The strategy back tester not returning prices that are below the current open price

 
Hi! I have set my strategy back tester to back test a EA against a daily time frame over a year's worth of data. I have checked and Exness is able to provide tick based data for this time frame.  One of my conditionals before submitting a long or short trade is to check whether the bid or ask price is above or below the open. It would return a trade if I added an "=" to the conditional but when I use a pure "<>" it returns no trade. It is a bit unbelievable that over the course of a year, there is never one trade where there isn't a price above or below the open. My settings are set to "real ticks", and I am using a "Daily" time frame. The print functions do return a value for the bid and ask prices (calculated per tick), as well as the value for the open price (labelled, "DailyOpen"), and the value for the previous close (labelled, "DailyClose"). Does anyone know where I might be misunderstanding the strategy back tester?
Files:
 
Colin Kimble:
Hi! I have set my strategy back tester to back test a EA against a daily time frame over a year's worth of data. I have checked and Exness is able to provide tick based data for this time frame.  One of my conditionals before submitting a long or short trade is to check whether the bid or ask price is above or below the open. It would return a trade if I added an "=" to the conditional but when I use a pure "<>" it returns no trade. It is a bit unbelievable that over the course of a year, there is never one trade where there isn't a price above or below the open. My settings are set to "real ticks", and I am using a "Daily" time frame. The print functions do return a value for the bid and ask prices (calculated per tick), as well as the value for the open price (labelled, "DailyOpen"), and the value for the previous close (labelled, "DailyClose"). Does anyone know where I might be misunderstanding the strategy back tester?

I'm not sure what your intention is with the CopyTime if statement, but it is only true on the first tick of a bar - and as you are using D1 timeframe, that code is run once a day. You check entry condition on every tick, but buy/sell can only occur on the first tick, according to that 'if' statement. 


if(CopyTime(_Symbol,PERIOD_CURRENT,0,1,lastTime)==1 && prevTime!=lastTime[0])
     {
      prevTime=lastTime[0];

      if(OneDayCalculationMA > 0.9 && OneDayCalculationOS > 0 && BuyPrice < DailyOpen)// && BuyPrice < PivotPointValue && BuyPrice < PivotPointS1Calculation)
        {
         double EnterLong = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
         EnterLong = NormalizeDouble(EnterLong,_Digits);
         trade.Buy(Lots,NULL,EnterLong,StopLoss,NULL,"Enter Long");
        }

      // Check conditions to enter a short position
      if(OneDayCalculationMA < -0.9 && OneDayCalculationOS < 0 && SellPrice > DailyOpen)// && SellPrice > PivotPointValue && SellPrice > PivotPointR1Calculation)
        {
         double EnterShort = SymbolInfoDouble(_Symbol,SYMBOL_BID);
         EnterShort = NormalizeDouble(EnterShort,_Digits);
         trade.Sell(Lots,NULL,EnterShort,StopLoss,NULL,"Enter Short");
        }
     }
 
ceejay1962 #:

I'm not sure what your intention is with the CopyTime if statement, but it is only true on the first tick of a bar - and as you are using D1 timeframe, that code is run once a day. You check entry condition on every tick, but buy/sell can only occur on the first tick, according to that 'if' statement. 


Thank you for your help! I resolved the issue by doing all my calculations before that line of code and having the return as a double statement that either returns a 1 or -1 depending on the outcome, it is a double that would act "Boolean" in nature by only returning a 1 or -1, so that in the final conditional it will be either true or false once, while before this line of code do the calculations at the same time per tick. Thank you so much for all your support! Kind regards

 
ceejay1962 #:

I'm not sure what your intention is with the CopyTime if statement, but it is only true on the first tick of a bar - and as you are using D1 timeframe, that code is run once a day. You check entry condition on every tick, but buy/sell can only occur on the first tick, according to that 'if' statement. 


I have added in my EA that it would only submit orders from Monday to Friday, it won't reflect the day of the week. It has compiled without errors, do you know where I might have missed the mark? Thank you so much for all your previous help!

input int DayOfTheWeek = 0;
input int EndDayOfTheWeek = 6;
   MqlDateTime startTimeOne;
   TimeCurrent(startTimeOne);
   MqlDateTime startTimeTwo;
   TimeCurrent(startTimeTwo);

   startTimeOne.day_of_week = DayOfTheWeek;
   Print("Day of the week: ", startTimeOne.day_of_week);
   startTimeTwo.day_of_week = EndDayOfTheWeek;
   Print("Day of the week: ", startTimeTwo.day_of_week);

   datetime timeOpenFirstDay = StructToTime(startTimeOne);
   datetime timeOpenLastDay = StructToTime(startTimeTwo);
   if(TimeCurrent() > timeOpenFirstDay && TimeCurrent() < timeOpenLastDay)
     {
      static datetime prevTime=0;
      datetime lastTime[1];
      if(CopyTime(_Symbol,PERIOD_CURRENT,0,1,lastTime)==1 && prevTime!=lastTime[0])
        {
         prevTime=lastTime[0];
         // (15/22 or higher)
         if(OneDayCalculationMA == 1 && OneDayCalculationOS > 0.15 && BuyLevel1 == 1 && BuyLevel2 == 1 && BuyLevel3 == 1 && BuyLevel4 == 1 && BuyLevel5 == 1 && BuyLevel6 == 1 && BuyLevel7 == 1)
           {
            double EnterLong = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
            EnterLong = NormalizeDouble(EnterLong,_Digits);
            trade.Buy(Lots,NULL,EnterLong,StopLoss,NULL,"Enter Long");
           }

         // Check conditions to enter a short position (-15/22 or higher)
         if(OneDayCalculationMA == -1 && OneDayCalculationOS < -0.15 && SellLevel1 == -1 && SellLevel2 == -1 && SellLevel3 == -1 && SellLevel4 == -1 && SellLevel5 == -1 && SellLevel6 == -1 && BuyLevel7 == -1)
           {
            double EnterShort = SymbolInfoDouble(_Symbol,SYMBOL_BID);
            EnterShort = NormalizeDouble(EnterShort,_Digits);
            trade.Sell(Lots,NULL,EnterShort,StopLoss,NULL,"Enter Short");
           }
        }
     }
  }
 
Colin Kimble #:

I have added in my EA that it would only submit orders from Monday to Friday, it won't reflect the day of the week. It has compiled without errors, do you know where I might have missed the mark? Thank you so much for all your previous help!

No stress, I figured it out!