Change start time / from time | Strategy Tester

 

So currently when I start up a Strategy Tester, I can only select the day I want it to test on. As example, if I select today, it will start at 00:00. 

Is there a way to change the start time, since I want to test from 9am until 9pm

 
Zwarte ijsman: So currently when I start up a Strategy Tester, I can only select the day I want it to test on. As example, if I select today, it will start at 00:00. Is there a way to change the start time, since I want to test from 9am until 9pm

No, not in the Strategy Tester settings!

You will have to do that in your EA code. Create a start and stop date-time parameters and only trade during that interval.

 
Fernando Carreiro #:

No, not in the Strategy Tester settings!

You will have to do that in your EA code. Create a start and stop date-time parameters and only trade during that interval.

Hey Fernando,

Thanks for your reply. I get that I will have to create a start and stop date-time parameter, which will make sure it will only trade between those times.

But in this I have done that. But when I start a strategy test, it will still run on the 00:00 - 09:00 to test my strategy, eventough I know it wont buy/sell during that time because I have a start and stop date-time parameter. So I want the strategy tester to start at 09:00, so I dont have to wait for that long on time it wont place orders.

 
Zwarte ijsman #: Thanks for your reply. I get that I will have to create a start and stop date-time parameter, which will make sure it will only trade between those times. But in this I have done that. But when I start a strategy test, it will still run on the 00:00 - 09:00 to test my strategy, eventough I know it wont buy/sell during that time because I have a start and stop date-time parameter. So I want the strategy tester to start at 09:00, so I dont have to wait for that long on time it wont place orders.

I will repeat myself — no, it can't be done in the Strategy Tester settings!

If you are waiting, then your code is not working properly and still processing irrespective of your start/stop time conditions.

If done properly, it should not be processing any data until 09:00 so as to only have a negligible delay.

 
Fernando Carreiro #:

No, not in the Strategy Tester settings!

You will have to do that in your EA code. Create a start and stop date-time parameters and only trade during that interval.

I did this to focus on a specific trade where I let Strategy tester iterate some parameters to understand what makes the best outcome for that strategy.
With the default minimum range of a day then the optimization becomes averaged over all trade cases of that day interval and not as distinct for learning what is optimal for this particular trading case.

Narrowing down to second precision can be done basically like this: 

A method tradingAllowed() called by the EA to see if it may currently issue a trade:

bool tradingAllowed() {
  datetime now=TimeCurrent();
  return (!TestMode() || (TestMode() && (InpTradeStart<=now && InpTradeEnd > now)));
}

The start / end  params use datetime syntax such as 

datetime InpTradeStart=  D'20.08.2024 16:00:00';  // Start of trading time (datetime string) 
datetime InpTradeEnd=    D'20.08.2024 17:30:00';  // End of trading time   (datetime string)

A method TestMode() that tells if EA is running in Strategy Tester.
I set a a flag in OnTesterInit(), reset in OnTesterDeinit().. 

//+------------------------------------------------------------------+
//| TestMode function                                              |
//+------------------------------------------------------------------+  
bool TestMode() {
  return testing;
}

//+------------------------------------------------------------------+
//| TesterInit function                                              |
//+------------------------------------------------------------------+
void OnTesterInit()
  {
    testing=true; // Mark Strategy Tester mode
//---
   
  }
 
//+------------------------------------------------------------------+
//| TesterDeinit function                                            |
//+------------------------------------------------------------------+
void OnTesterDeinit()
  {
//---
    testing=false;
  }
In Strategy Tester the time is set to the day where the trade of interest occurred.