I have an automated system trading futures and there is a simple piece of code to close open positions before the weekend inside OnMarketData() function.
--------------------
if ((Time[0].DayOfWeek == DayOfWeek.Friday) && (ToTime(Time[0]) >= 135800))
{
if (Position.MarketPosition == MarketPosition.Long)
ExitLong();
if (Position.MarketPosition == MarketPosition.Short)
ExitShort();
}
------------------
This code work just fine in real-time and closes open positions right before 2pm PST on friday.
During the weekend I usually reboot the system and restart NT. And after the restart of the same strategy on Sunday morning, this Friday position closing just does not happen.
The strategy thinks that whatever position was open is still open.
Tha data series has 'Tick Replay' flag set., and the strategy has 'Calculate on each tick' property set.
It looks like historical data timestamps are processed differently in the system and the above mention code does not work correctly with historical data timestamp.
Please let me know if I need to set any other flag/property or there is a workaround for the strategy to correctly close open positions on historical data.
Thank you,
Comment