Strategy tester too slow when testing my EA

 

I have an Expert Advisor that uses the ZigZag indicator.

I tried using a while loop to get the last two points, and this gave me the result I wanted, but the EA was too slow. But when I test other Expert Advisors, the strategy tester doesn't slow down.

Please help me check this.

Thanks.

 

 My Code;


//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {



int n, i;

i=0;

while(n<2)

{

   if(Last_fixed_point>0) Current_point=Last_fixed_point;

   Last_fixed_point=iCustom(NULL, 0, "ZigZag", InpDepth, InpDeviation, InpBackstep, 0, i);

   if(Last_fixed_point>0) n+=1;

   i++;

}
 
  1. EAs : Don't do per tick what you can do per bar, or on open.
    If you are waiting for a level, don't reevaluate, wait until price reaches it (or a new bar starts, and you recalculate.)
    If you are waiting for an order to close, only look when OrdersTotal (or MT5 equivalent) has changed.
              How to get backtesting faster ? - MT4 - MQL4 programming forum (2017)

  2. Indicators: Code it properly so it only recomputes bar zero (after the initial run.)
              How to do your lookbacks correctly. (2016)
    Or, reduce Tools → Options (control+O) → Charts → Max bars in chart to something reasonable (like 1K.)

 
mql4 question in mql4 section please.
 
Try using only opening price for testing, that may increase the speed of testing a lot!
Reason: