I noticed that the optimizer doesn't always respect the from and to dates that you set. For example if I set a strategy to optimize from Jan 3rd to Jan 5th, sometimes I see trades that took place on the 2nd and 6th.
My strategy has a profit factor of 4.0 - 5.0 and trades many times a day, I was worried this was fake and it scared me that it's trading outside of it's range. For example, Jan 6th is the out of sample period, so this is how I measure how well it works.
I started doing some detective work and created this bit of code, instantly I got hundreds of prints stating "OnBarUpdate called with bad bar", and the profit factor dropped instantly to 0.5 .
I'm not sure what's causing it and it doesn't happen on all of my machines. Here's the code I'm using to stop it:
private DateTime bt_start ;
private DateTime bt_end ;
protected override void Initialize()
{
bt_start = this.BackTestFrom;
bt_end = this.BackTestTo;
}
protected override void OnBarUpdate()
{
if(this.Account.Mode == Mode.Simulation) {
if(Time[0] < bt_start) {
//Print("OnBarUpdate called with bad bar " + Time[0]);
return;
}
if(Time[0] >= bt_end) {
//Print("OnBarUpdate called with bad bar " + Time[0]);
if (Position.MarketPosition == MarketPosition.Long) {
ExitLong();
}
return;
}
}
}

Comment