Reasons and help of a very slow backtest

 

Hallo,

I have programmed an EA with an iCustom-Function with 10 different Parameters.

This iCustom-Indicator is calling an MTF-Indicator, which is calling an Indicator from my standard-metatrader-account.


The backtest of my EA is very, very slow!


Can anybody tell me what I can do against that?

What are the reasons? The many Parameters or the MTF-Indicator or the recall of the functions?

 

When I look in the journal, I can see, that my Indicator and the Indicator I call im my Indicator are loaded successfully and in the same minute they are removed!

The only messages in the journal are

...loaded successfully

...removed

The EA doesn't open an order or something like that!

 

One approach (and there are several you can use) is to cache the values - IF (and that's a big IF) the iCustom values do not change during the course of a bar. The following shows a routine I use (BTW to help automate closing orders as weekend approaches) that caches values. One technique to allow caching, is to use Open price (that should not change during a bar) rather than Close to calc values (although that introduces a one-bar delay)

double GetCustomWW(int pMode)
{
   double res;
   static datetime cacheTimes[]={0,0,0,0,0,0,0,0};
   static double cacheValues[]={EMPTY_VALUE,EMPTY_VALUE,EMPTY_VALUE,EMPTY_VALUE,EMPTY_VALUE,EMPTY_VALUE,EMPTY_VALUE,EMPTY_VALUE};
   if(pMode<0 || pMode>7)
   {
      Alert("WW pMode outside 0-7 @ ", pMode);
      return (EMPTY_VALUE);
   }
   if(cacheTimes[pMode] != Time[0])
   {
      cacheTimes[pMode] = Time[0];
      cacheValues[pMode] = iCustom(NULL, Period(), _WeekendName, 
ServerHoursOfFridayToCutOff,
MinimumHoursWarning,
MinimumBarsWarning,
IconSpacingAsBarHeightRatio,
IconWarning,
IconCutoff,
      pMode, 0); 
   }
   res = cacheValues[pMode];
   return (res);
}
 

sunshineh:

The backtest of my EA is very, very slow!

Can anybody tell me what I can do against that?
  1. One or more indicator is/are recomputing everything for all bars instead of just using the standard
    int start(){
       int counted_bars=IndicatorCounted();
       if(counted_bars<0) return(-1);
       if(counted_bars>0) counted_bars--;
       int limit=Bars-1-counted_bars;
       for(int i=limit; i>=0; i--){...
  2. Otherwise you can reduce the number of bars on chart.

  3. And/Or, don't do unnecessary work in your EA
    //+------------------------------------------------------------------+
    //| Skip useless ticks                                               |
    //+------------------------------------------------------------------+
    double  CA.below,   CA.above=0;         // Export to start
    void    CallAgain(double when){
        if (when>=Bid && CA.above > when) CA.above = when;
        if (when<=Bid && CA.below < when) CA.below = when;
        return;
    }
    //+------------------------------------------------------------------+
    //| expert start function                                            |
    //+------------------------------------------------------------------+
    int     start(){
        static datetime Time0;  bool newBar  = Time0 != Time[0],
                                     useless = CA.below <= Bid && Bid <= CA.above;
        if (useless && !newBar) return(0);  #define INF 9999999
        CA.below = 0;   CA.above = INF;     Time0 = Time[0];
        if (!useless){
            OnTick();                           // Will reset CA's
            ModifyStops();
            OpenNew();                          
        }   // Not useless
    
Reason: