Back testing taking hours ?

 

I use the Strategy Tester when trying to optimise parameters for my code although back testing only 3 years of data on open prices only can take 30 hours, does it really take this long (it never used to), I have read elsewhere that having a optimised code can speed up back testing, what sort of things in the code can slow down back testing ?

Here's part of my code, are there any obvious things that slow it down ?

i use i custom functions aswell, if this may slow it down ?

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CheckForLONGTrade()
  {
//Alert("Checking for long trade");

   if(GetGreenWaddah2() > GetExplosion2() && GetGreenWaddah2() > GetDead() && GetExplosion2() > GetDead() && (GetTrendForce() > TrendTrigger) && (GetTrendForceshift() < TrendTrigger) && (GetUTFASTdown() < GetUTFASTup())) 
              
     {
      Alert("Long");
      OrderEntry(1);
     }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CheckForSHORTTrade()
  {
//Alert("Checking for short trade");

   if(GetRedWaddah2() > GetExplosion2() && GetRedWaddah2() > GetDead() && GetExplosion2() > GetDead() && (GetTrendForce() < -TrendTrigger) && (GetTrendForceshift() > -TrendTrigger) && (GetUTFASTup() < GetUTFASTdown()))
     {
      Alert("Short");
      OrderEntry(0);
     }
  }

void OrderEntry(int direction) 

  {
   if(direction==1)
      if(OrderSend(Symbol(),OP_BUY,GetLongContracts(),Ask,SLIPPAGE,GetStopLossLongPrice(),0,NULL,MagicNumber,3,Green) < 0)
        {
         Print("Order Send failed, error # ", GetLastError());
        }

   if(direction==0)
      if(OrderSend(Symbol(),OP_SELL,(GetShortContracts()),Bid,SLIPPAGE,GetStopLossShortPrice(),0,NULL,MagicNumber,3,Green) < 0)
        {
         Print("Order Send failed, error # ", GetLastError());
        }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsNewCandle()
  {
   static datetime saved_candle_time;
   if(Time[0]==saved_candle_time)
      return false;
   else
      saved_candle_time=Time[0];
   return true;
  }

void OnTick()

{
          
     {
      if(IsNewCandle())
        {
         Alert("New Bar");
         //Alert("Checking for trades");
         
         if(CountLONGPositions() > 0 && GetUTFASTup() < GetUTFASTdown() )
          {
          CloseOrders(Symbol(),MagicNumber,OP_BUY);;
          Alert("Order Closed");
           }

         if(CountSHORTPositions() > 0 && GetUTFASTdown() < GetUTFASTup() )
          {
          CloseOrders(Symbol(),MagicNumber,OP_SELL);
          Alert("Order Closed");
          }

         if((CountPositions() > 0))
           {
            ApplyTrailingStop(Symbol(), MagicNumber, ATRTrailingStop() * TrailingStopMultiplier );
           }

         if((CountPositions() < 1))
           {
            CheckForLONGTrade();
           }

         if((CountPositions() < 1))
           {
            CheckForSHORTTrade();
           }

//+------------------------------------------------------------------+
 
George Johnson:

I use the Strategy Tester when trying to optimise parameters for my code although back testing only 3 years of data on open prices only can take 30 hours, does it really take this long (it never used to), I have read elsewhere that having a optimised code can speed up back testing, what sort of things in the code can slow down back testing ?

Here's part of my code, are there any obvious things that slow it down ?

i use i custom functions aswell, if this may slow it down ?

Don't keep calling the same function in the same block of code. Call it once and save the value in a variable.

Also here you call the same function 3 times. Why?????


         if((CountPositions() > 0))
           {
            ApplyTrailingStop(Symbol(), MagicNumber, ATRTrailingStop() * TrailingStopMultiplier );
           }

         if((CountPositions() < 1))
           {
            CheckForLONGTrade();
           }

         if((CountPositions() < 1))
           {
            CheckForSHORTTrade();
           }

This does the same but only calls the function once!

         if((CountPositions() > 0))
           {
            ApplyTrailingStop(Symbol(), MagicNumber, ATRTrailingStop() * TrailingStopMultiplier );
           }
        else
           {
            CheckForLONGTrade();
            CheckForSHORTTrade();
           }
 
  1. Keith Watford #: Don't keep calling the same function in the same block of code. Call it once and save the value in a variable.

    Exactly

  2.    if(GetGreenWaddah2() > GetExplosion2() && GetGreenWaddah2() > GetDead() && GetExplosion2() 

    Here you called GetGreenWaddah2 twice and GetExplosion2 twice.

  3. Your code
    bool IsNewCandle()
      {
       static datetime saved_candle_time;
       if(Time[0]==saved_candle_time)
          return false;
       else
          saved_candle_time=Time[0];
       return true;
      }
    Optimized
    bool IsNewCandle()
      {
       static datetime saved_candle_time;
       datetime prev = saved_candle_time;
       saved_candle_time = Time[0];
       return saved_candle_time != Time[0];
      }

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              Running EA once at the start of each bar - MQL4 programming forum (2011)

 

How to open Multi Currency Trade at Same Time From One Symbol Expert Advisor attached.

One Symbole Buy And Second Symbol Sell Open Two Trades At the same Time. It is Possible?

 
Pankaj Kapadia #: How to open Multi Currency Trade at Same Time From One Symbol Expert Advisor attached. One Symbole Buy And Second Symbol Sell Open Two Trades At the same Time. It is Possible?

On MetaTrader 4, the Strategy Tester can only handle trading on a single symbol, not multiple symbols at the same time. You can still reference OHLC data from a different symbol or time-frame but not trade it.

However, you can do multi-symbol trading on a live chart in MetaTrader 4. Just can't do it on the Strategy Tester.

For true multi-symbol trading in the Strategy Tester, only on MetaTrader 5.
Reason: