Quote:
Originally Posted by fxbs
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>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
if(i < 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=0; i<limit; i++)
if(i < 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)