EA gets slowly when backtesting

 

Hello,

Any ideas why my EA gets slowly over time when backtesting
CPU runs on 25% ram 280MB.


I am Running the EA each minute.

The variable are initialize before getting into the loop, there are approx 100 variables. 

int     Check_Candles[3];


I have a loop that is executed three times, based on the time frame. 

inside the loop i have another 50 loops which calculates variable

      for(int m =0; m<=2; m++)
        {
         if(m==0)
           {
            tf = LTF;
           }
         if(m==1)
           {
            tf = MTF;
           }
         if(m==2)
           {
            tf = HTF;
           }
        // calculation 1
        // calculation 2
        .....
        // calculation 50
        }

Variables getting defined in the loop

         highest_high_Price_sell[m]             = 0; 
         highest_high_Bar_sell[m]               = 0;
         Low_of_Highest_Bar_sell[m]             = 0;
         highest_high_Price_time_sell[m]        = 0;


inside the loop there are aprox. 50 loops which calculates variables. 
Not all loops do run always but only condition-wise, when 1st condition is fulfill, 2nd loop - 5th loop,

 All variables in the loop are Arrays as the have to fill three times. 

         for(int i=1; i<=Check_Candles_sell[m]; i++)                   // Finds the highest high
           {
            if(iHigh(Symbol(),tf,i) >= highest_high_Price_sell[m])
              {
               highest_high_Price_sell[m] =iHigh(Symbol(),tf,i);
               highest_high_Bar_sell[m]=i;
               Low_of_Highest_Bar_sell[m]=iLow(Symbol(),tf,i);
               highest_high_Price_time_sell[m] = iTime(Symbol(),tf,highest_high_Bar_sell[m]);
              }
           }

Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
 
  1. Mario0407: Any ideas why my EA gets slowly over time when backtesting? I have a loop that is executed three times, based on the time frame. 
    if(iHigh(Symbol(),tf,i)

    Your loop is three timeframes times whatever i loops on.

  2. Why are you looking at multiple candles? If the earlier candles had your condition, you would have opened then. You only need to look at the last.

  3. Do you have a new bar test for each timeframe?
              detecting a new bar without removing ability to detect tick in multiple timeframe - Easy Trading Strategy - MQL4 programming forum #8 (2021.08)

  4. Do you have indicator(s) that calculates all bars each tick?

  5. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

 

1. correct i look on three timefrimes on the same candel pattern. 

2. I look at multiple candles because i want to find a certain scenario. Looking for high then lows,...

3. EA runs every minute

   if(LastActionTime != Time[0])
     {

        // Code
        // ...
        // ...

      LastActionTime = Time[0];
     }

 do you mean something link that? to not run every minute the loop?
 

         if(candelcounter[m] >= 1)
           {
            candelcounter[m] ++;
            lowest_Low_Price[m] =iLow(Symbol(),tf,candelcounter[m]);
            High_of_Lowest_Bar[m]=iHigh(Symbol(),tf,candelcounter[m]);
            Lowest_Low_Bar[m] = candelcounter[m];
            lowest_Low_Pricere_time[m] = iTime(Symbol(),tf,Lowest_Low_Bar[m]);
           }
         if(candelcounter[m] >=20)
           {
            Lowest_Low_Bar[m] =0;
            candelcounter[m] =0;
           }
         if(iLow(Symbol(),tf,1) <= lowest_Low_Price[m])
           {
            Lowest_Low_Bar[m] =0;
            candelcounter[m] =0;
           }
         if(candelcounter[m] ==0)
           {
            for(int i=0; i<=Check_Candles[m]; i++)                   // Finds the lowes low
              {
               if(iLow(Symbol(),tf,i) <= lowest_Low_Price[m])
                 {
                  lowest_Low_Price[m] =iLow(Symbol(),tf,i);
                  Lowest_Low_Bar[m]=i;
                  High_of_Lowest_Bar[m]=iHigh(Symbol(),tf,i);
                  lowest_Low_Pricere_time[m] = iTime(Symbol(),tf,Lowest_Low_Bar[m]);
                  candelcounter[m] = i;
                 }
              }
           }

4. no, every minute