# 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,
{"ft_lang_label":"__label__en","ft_lang_prob":0.7342164,"math_prob":0.975408,"size":1370,"snap":"2023-14-2023-23","text_gpt3_token_len":400,"char_repetition_ratio":0.11566618,"word_repetition_ratio":0.04597701,"special_character_ratio":0.34525546,"punctuation_ratio":0.14590748,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99726576,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-25T18:59:54Z\",\"WARC-Record-ID\":\"<urn:uuid:b8318698-0273-4700-8591-aaaddf136b9f>\",\"Content-Length\":\"48303\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8f147abc-8299-4322-8c9b-97d1192bf803>\",\"WARC-Concurrent-To\":\"<urn:uuid:163bf32f-af64-485f-8df8-63701f14d0d0>\",\"WARC-IP-Address\":\"13.107.253.40\",\"WARC-Target-URI\":\"https://social.microsoft.com/Forums/en-US/963b271e-103e-4510-a5cf-66317a55466a/how-to-index?forum=Offtopic\",\"WARC-Payload-Digest\":\"sha1:3PATZKPHRSF4S4HBWXLTNSEROXNKY6ML\",\"WARC-Block-Digest\":\"sha1:O65QVLCHA5Q7X7OSKKRTPWFL5F7BOLNI\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296945368.6_warc_CC-MAIN-20230325161021-20230325191021-00012.warc.gz\"}"}