Thread: How to code?
View Single Post
  #525 (permalink)  
Old 12-06-2007, 07:28 PM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 513
Michel is on a distinguished road
Quote:
Originally Posted by nakata79087 View Post
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.
Reply With Quote