I am trying to emulate the ExitOnClose flag programatically. So, when backtesting I have ExitOnClose set to false and instead I'm using this code:
Code:
protected bool NYSEClose() {
return ToTime(Time[0]) >= ToTime(12, 58, 00);
}
protected void CloseEOD() {
// Closing the Day - only if we trade intraday
bool closeOpen = intraday ? NYSEClose() : true;
if (closeOpen)
{
if(Position.MarketPosition == MarketPosition.Long)
ExitLong("Exit Long", "");
if(Position.MarketPosition == MarketPosition.Short)
ExitShort("Exit Short", "");
}
}
My setup:
- I'm running this on a 30min chart against the ES ##-##
- I have 'intraday' set to true as the default.
- CalculateOnBarClose is set to false in my Initialize() method
- At the end of my OnBarUpdate() method I call CloseEOD();
For some reason I'm not being closed out at 12:58 (I'm in CA, so this is actually 2 minutes before the close of the session). Instead it's closing out the next morning at the first candle: http://screencast.com/t/gFUnogKb
The reason why I cannot use the ExitOnClose flag is that I am sending myself emails and I seem to be unable to generate an event/alert when the ExitOnClose flag is being triggered.
Any help would be greatly appreciated. Please ask if anything is unclear.

Seems pretty obvious to me...
Comment