View Single Post
  #9 (permalink)  
Old 03-01-2008, 07:38 AM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 513
Michel is on a distinguished road
Quote:
Originally Posted by fxbs View Post
Hey, Michel!
how to use this line:
if(i > MaxBars) continue;
i tryed - no go...

but if put like this:
if(i < MaxBarsToCount)
- works (MACD):

PHP Code:
int start()
  {
   
int limit;
   
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;

//---- macd counted in the 1-st buffer
   
for(int i=0i<limiti++)
   if(
MaxBarsToCount)
   
      
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   
for(i=0i<limiti++)
      if(
MaxBarsToCount-SignalSMA

      
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
   
return(0); 
both should do the same, but the problem here is that you don't use the brackets for the for loop because there is only one command.
"if(i < MaxBarsToCount) MacdBuffer[i]=iMA(NULL,0,FastEMA... ;" is only one command ( there is only one ";" ) so the for loop doesn't need any brackets.
Now, the use "if(i >MaxBarsToCount) continue;" means one more command in the for loop, so you have to use brackets to group them together.
so :
for(int i=0; i<limit; i++)
if(i > MaxBarsToCount) continue;
does'nt work because there is only one command, the if test line, which does nothing.
but
for(int i=0; i<limit; i++)
{
if(i > MaxBarsToCount) continue;
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE blabla ;
blahblahblah...;
}
works.

I a general case, the for loop use brackets, thus "if(i > MaxBarsToCount) continue;" is ready to use (you do not need to add other brakets or modify the code)

Last edited by Michel; 03-01-2008 at 07:42 AM.
Reply With Quote