Quote:
Originally Posted by nakata79087
I do not understand the difference of two programs, but would teach it?
int limit = Bars-IndicatorCounted();
int i ;
for( i=limit-1; i>=0; i--)
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i = 0; i <= limit; i++)
|
The most important difference is the direction of the "for" loop:
The first one scan the bars following the natural time, ie from the oldest to the newest bar.
The second one scan the bars in the opposite direction: it can work if the calcul of a bar doesn't involve the result of the previous bar;
In general it's better to use the same direction as the time: it always works and there are no possibilties of mistaken.