Simple counter question

 

Hello,

Just had a quick MQL4 question.

How would one approach bar counting in MQL4, I know of the "bars" variable and iBar() .

I would like to able to print how many bars above 10 SMA there were last year, I get the result of the backtest would be that value . ( Would you actually run that in the backtester ? )

cheers,

 

Hello,

Use "iBars()" and similar timeseries access functions to instantly get actual data.

Use "RefreshRates()" to get actual data in "Bars" variable and in similar predefined variables for sure.

By the way, I never use "IndicatorCounted()" function, and I do not remember exactly why. To avoid unnecessary recalculations I use another approach.

Regards,

 

hmm, I`m not sure I`m following you, so far I`m using this, but it keeps on print at every tick and is not very great for backtesting :

int counter=1;

for(int i=1; i<=300; i++)

{

if (Close[i-1] > SMA)

{

if (Close[i-1]>Open[i-1])

{

count = count +1;

}

if (Close[i-1]<Open[i-1])

{


count = count - 1;

}


Print("Count =",count);

}

 
julz:

hmm, I`m not sure I`m following you, so far I`m using this, but it keeps on print at every tick and is not very great for backtesting :

?
I do not disclosed here my approach to avoid unnecessary recalculations, yet.
?
This approach is to give the control to the block of checks in the beginning of "start()" function.
!
I did it now !
!

Reason: