How to index? RRS feed

  • 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))
    // 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][0] = cma;
    // Values return the plots to create the object
    // int count = 0;
    	for (int i = 0; i <= Period-1; i++)
    					AddPlot(Brushes.Aqua, "MyPlot"+ count);
    	    } //	
    Print("Bar " + count + " of Period CMA value: " + cma);
    	Print("count" +count);
    // this part list the result of the cma//
    	for(int n = 0; n < Values.Count(); n++)
               double value = Values[n][0];


    Wednesday, January 8, 2020 2:31 PM

All replies

  • Ninjatrader related, its a charting software.
    Wednesday, January 8, 2020 3:27 PM
  • Hi,
    This forum is discussing and asking questions about the Windows Forms.
    If your question is related to the winform, please provide more details about it.
    If it is related to Ninjatrader that you said, please contact Ninjatrader developer.
    Best Regards,
    Daniel Zhang

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 9, 2020 6:00 AM