Strategy Testing using specific GMT time periods only

 

I have looked around, and I have determined how to use the time of day / day of week to determine strategies in my EA. My question is, does this actually work in the strategy tester? (I am not sure how the strategy tester pulls the time) - Props to Raptor for this source code btw.

Additionally my preference in live trading would be to pull from a ntp so I could use GMT, so that regardless of server time, my EA operates when I want it to. I understand this would be forward testing only, without writing test code to provide dummy info.

bool AllowTradesByTime(int Start_Time, int Finish_Time)
   {
   int Current_Time = TimeHour(TimeCurrent());
   if (Start_Time == 0) Start_Time = 24; if (Finish_Time == 0) Finish_Time = 24; if (Current_Time == 0) Current_Time = 24;
      
   if ( Start_Time < Finish_Time )
      if ( (Current_Time < Start_Time) || (Current_Time >= Finish_Time) ) return(false);
      
   if ( Start_Time > Finish_Time )
      if ( (Current_Time < Start_Time) && (Current_Time >= Finish_Time) ) return(false);
   return(true);
   }

For different days, such as sat / sun I have code like this in several places

        if (DayOfWeek() == 0 || DayOfWeek() == 6)
                {
                        """xxx code to wait for monday"""
                        return(0);
                }

Will this perform properly in Strategy testing? - I understand that some data is grabbed from the server at start of program, and other is grabbed from server, and without restating documentation I believe I am not using any "start of program" data, but I am unsure of proper operation in strategy testing.

Thank you for looking :)

 
ReaDOnlY:

I have looked around, and I have determined how to use the time of day / day of week to determine strategies in my EA. My question is, does this actually work in the strategy tester? (I am not sure how the strategy tester pulls the time) - Props to Raptor for this source code btw.

Additionally my preference in live trading would be to pull from a ntp so I could use GMT, so that regardless of server time, my EA operates when I want it to. I understand this would be forward testing only, without writing test code to provide dummy info.

For different days, such as sat / sun I have code like this in several places

Will this perform properly in Strategy testing? - I understand that some data is grabbed from the server at start of program, and other is grabbed from server, and without restating documentation I believe I am not using any "start of program" data, but I am unsure of proper operation in strategy testing.

Thank you for looking :)

My code works in the Strategy Tester, I have tested it. I am not sure about DayOfWeek() so I wouldn't use it, instead I would use TimeDayOfWeek(TimeCurrent()).
 

Thank you very much. So TimeDayOfWeek(TimeCurrent()) will return the current day of the week on the server. How do I manage to always work on GMT time, regardless of server used? (for example I give to my buddy who uses FXDD instead of FXCM and the servers are in different time zones, so the trading windows would be different) Right now I have the departure from server time as a manual input, but hoping for something better.

Thanks

 
ReaDOnlY: TimeDayOfWeek(TimeCurrent()) will return the current day of the week on the server. How do I manage to always work on GMT time, regardless of server used?
  1.       // https://www.mql5.com/en/forum/127483 reports DayOfWeek() always returns 5 in tester.
          // https://www.mql5.com/en/forum/144021 2013.03.18 (Build 509) reports no problems.
          // https://www.mql5.com/en/forum/146843/page2#840945 fixed in 2013
    
    So DayOfWeek now works fine, but you'll still need TimeDayOfWeek(gmtTime)
  2. Convert server time to gmt then do your tests. See my code
Reason: