iCustom prev_calculated is always 0 when calling different symbols in one symbol with EA

 

Hi,

I am creating an EA which scans all the symbols in the market watch. In that, every symbol runs a set of custom indicator which I developed.

From this, I am getting "indicator is too slow, 5640 ms. rewrite the indicator, please" this issue in most of the indicators.

I am using " int Nbars = rates_total - prev_calculated - 1;" this in all indicators. So when a symbol loads at the first time, it returns total bars and after that, it will load only new bars( the value will be 0 or -1).

But I am facing the issue, every time it loads a symbol, OnInit() is called and prev_calculated is always 0. It is not returning the previous call.

I read the MQL document which is 

 If since the last call of OnCalculate() price data has changed (a deeper history downloaded or history blanks filled), the value of the input parameter prev_calculated will be set to zero by the terminal.


But I don't know why it is returning the calculated rates_total.

Kindly give your valuable solution 

Thanks in advance !

 

Always use 

#property strict

in your codes.


 int Nbars = rates_total - prev_calculated - 1;

if you are trying to access Buffer[Nbars] when Nbars==-1 you should be getting an array out of range error (if you use strict).

Have your code assign different values to Nbars depending on whether prev_calculated== 0 or not.

 

Thanks for the reply.. 

I used this in all indicators

#property strict

Actually, how I am using is,

EA will scan like EURUSD,GBPCAD,USDJPY etc.. from the market watch.

For the first iteration, All indicators will get the details about EURUSD and print the log as EURUSD +1 or -1 

For the next iteration, GBPCAD will be called and repeat end of symbols in the market watch.

After this, the next repitation of EURUSD will call again, this time, already EURUSD was calculated all the candles then the prev_calculated will be set as rates_total, after here only new bars should be calculated. But the problem is again it is calling the total bars which makes my terminal slow.

This is the problem I am facing.