Wrong date during Backtesting
Wrong date during Backtesting
20 Oct 2014, 10:58
Hello!
I have the following issue:
I set up a filter on time to prevent the robot from trading during specific hours:
[Parameter("UTC Trade Start", DefaultValue = 22.0)]
public double TimeStart { get; set; }
[Parameter("UTC Trade Stop", DefaultValue = 8.0)]
public double TimeStop { get; set; }
startTime = Server.Time.Date.AddHours(TimeStart);
endTime = Server.Time.Date.AddHours(TimeStop);
bool tradeTime = Server.Time >= startTime && Server.Time <= endTime;
if (!tradeTime)
{
Print("Start time, server time, finish time: {0},{1},{2}", startTime, Server.Time, endTime);
return;
}
During backtests, I noticed that both variables of start time and stop time are changing correctly while server time is using the date which is set up as a date to finish backtest.
16/10/2014 21:44:48.086 | Start time, server time, finish time: 08.09.2014 22:00:00,16.10.2014 17:44:48,08.09.2014 8:00:00
16/10/2014 21:44:48.495 | Start time, server time, finish time: 08.09.2014 22:00:00,16.10.2014 17:44:48,08.09.2014 8:00:00
16/10/2014 21:44:48.576 | Start time, server time, finish time: 08.09.2014 22:00:00,16.10.2014 17:44:48,08.09.2014 8:00:00
...
...
17/10/2014 03:54:54.442 | Start time, server time, finish time: 08.09.2014 22:00:00,16.10.2014 23:54:54,08.09.2014 8:00:00
17/10/2014 03:54:55.458 | Start time, server time, finish time: 08.09.2014 22:00:00,16.10.2014 23:54:55,08.09.2014 8:00:00
17/10/2014 03:54:56.440 | Start time, server time, finish time: 08.09.2014 22:00:00,16.10.2014 23:54:56,08.09.2014 8:00:00
17/10/2014 03:54:56.440 | Backtesting finished
What should I use instead of Server.Time during backtesting to enable it to work properly?
AlexanderRC
22 Oct 2014, 17:22
You should extract the time portion from Server.Time and compare that with start and end TimeSpan's. Look for DateTime.TimeOfDay. Note that if start time is grater than end time (night), the comparison must be adjusted. Also, beware of the TimeZone property of Robot attribute.
@AlexanderRC