Is there any way to prevent slowness when using array in EA?

 

I applied the following calculation to the EA and the speed of the EA got very slow.

Is there any way to make it more efficient?


input int Inp_HighPeriod = 20;
input int Inp_LowPeriod = 10;
input int Inp_MAPeriod = 30;
input ENUM_MA_METHOD Inp_MAMode = MODE_SMA;

input int digit = 3;
double buf_MA[];
double buf_Kairi[];
input int limit = 100;


void OnTick()

{

  ArrayResize(buf_Kairi,100,100);

  for(int i = 0;i<limit;i++)
   {
      double High=iHigh(_Symbol,0,iHighest(_Symbol,0,MODE_HIGH,Inp_HighPeriod,i));
      double Low=iLow(_Symbol,0,iLowest(_Symbol,0,MODE_LOW,Inp_LowPeriod,i));
      buf_Kairi[i]=NormalizeDouble((High-Low)/Low,digit);
   }


~~~~~~~~~~~~~~~~~~~

}
 
metamitsu:

I applied the following calculation to the EA and the speed of the EA got very slow.

Is there any way to make it more efficient?


Don't allocate memory on every tick.
 
metamitsu: Is there any way to make it more efficient?
Don't do per tick that which you can do once per bar or at initialization.
  1. Resize your array once in OnInit.
  2. After the first computation, nothing changes unless the bid goes above High or below Low or a new bar starts. Just check those three and return.
  3. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2017.07.19

Reason: