# How to index? • ### Question

• Hello,

I am trying to index a cumulative moving average so i can create more than one cma in my chart.

As you can see in the chart the blue line is the result of the code and the yellow is what it should look like. The blue lines all start at the 4th candle when actually it should create a cma that starts at every candle and cumulate the period from left to right. The system refuse to let me insert an image. sorry

```if (CurrentBar < (ChartBars.ToIndex-Period))
return;
// test if is there enough bars in the chart.

int count = 0;
double sum01 = 0;
double sum02 = 0;
double cma = 0;

Print("***** Bar " + CurrentBar + " CMA Values: *****");

for (int i = 0; i <= Period-1; i++)
{
// return periods to index from bar 4 to 1, the opposite is also possible (int i = Period-1; i >= 0; i--)

double privol =	Volume[i] * Input[i];
// input returns all prices in the series and [i] is the indexation

sum01 += privol;
sum02 += Volume[i];

cma = sum01 / sum02;

Values[count] = cma;
// Values return the plots to create the object
// int count = 0;
for (int i = 0; i <= Period-1; i++)
{
count++;
} //

Print("Bar " + count + " of Period CMA value: " + cma);

count++;

Print("i"+i);
Print("count" +count);

// this part list the result of the cma//

for(int n = 0; n < Values.Count(); n++)
{
double value = Values[n];

Print(value);
}

}
```

thanks

Wednesday, January 8, 2020 2:31 PM

### All replies

• Ninjatrader related, its a charting software.
Wednesday, January 8, 2020 3:27 PM
• Hi,