Direction of Calculating an indicator

 

Hi,

I want to program an indicator.

Normally I am using this loop in my indicators:

   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
//----
   int    i,pos=Bars-ExtCountedBars-1;

//---- signal line is simple movimg average
   for(i=0; i<pos; i++)
   { ....
   }

But when I am using this loop, the indicator is calculated from today to the past and than the actual values every tick.


Now for my new indicator it is very important, that I can also calculate the past values from the beginning of the first bar of the chart.

I hope you can understand me, I need the values from the past first and then the newer...


I think, I can't change my for-loop from

for(i=pos; i>0;i--) because of the future values??

 

standard indicator loop is:

for(int i=Bars-counted_bars-1;i>=0;i--){

}

I don't know what you mean with 'because of the future values'

 

New bars form on the right hand side of the chart . . . shouldn't every Indicator always work from left to right ? this is what an Indicator has to do when working in real time . . .

I don't have much experience with Indicators but I was working on an Indicator for a friend . . . I wasted 6 hours trying to figure out why my code wasn't working and then realised it was because the original code was working the existing bars from right to left and new bars from left to right.

I think your code looks OK . . but do you need to do this . . .

 if (ExtCountedBars>0) ExtCountedBars--;

//  and . . . this

   int    i,pos=Bars-ExtCountedBars  -1;
 
Actually, decrementing is unnecessary according to Contradictory information on IndicatorCounted() - MQL4 forum
Reason: