Since ExitOnClose must be set in initialize, I don't think I can have any logic that uses ExitOnClose only if its Friday. Or can I?
So I came up with this.
if ((ToTime(Time[0]) >= 150000) && (Time[0].DayOfWeek == DayOfWeek.Friday))
{
if (Position.MarketPosition == MarketPosition.Long)
{
ExitLong(100000);
}
if (Position.MarketPosition == MarketPosition.Short)
{
ExitShort(100000);
}
}
I have some instances on backtest that show that it is not working as expected....
Example
CalculateOnBarClose = true;
Timestamps are at close of bar.
Position.MarketPosition == MarketPosition.Long
A bar closes with a closing timestamp of 15:45:57
I expected to be taken flat on the close of that bar.
But that isn't what happens. What am I doing wrong?

Comment