I thought I was very familiar with the ExitOnClose usage but I'm not getting the results I desire. Please note that this is for an unmanaged approach.
In backtesting, Exit on Close (in the Strategy Analyzer) is set to true. The strategy will successfully exit on close in backtesting, though not quite as expected. I use "ExitOnCloseSeconds = 3600" because I want the strategy to close at 4PM instead of 5PM (this is based on the session template for the instrument in question, and all of these are CME Globex products. I have not changed the defaults for CME FX Futures ETH). In backtesting, the strategy exits at the end of the session's defined time (5PM EST), not 4PM EST as instructed. I've learned recently that ExitOnClose doesn't work for backtesting, which is fine.
When running the strategy live, however, the strategy will not close at 4PM EST as instructed.
Am I missing something in this case? I have "ExitOnClose = True" within Initialize(). Here is a copy of the initialization code:
protected override void Initialize() { try { // Bar on close? CalculateOnBarClose = true; // Account Size localPnL = GetAccountValue(AccountItem.RealizedProfitLoss); // Suppress messages for now. TraceOrders = true; SyncAccountPosition = false; Unmanaged = true; IncludeCommission = true; IgnoreOverFill = false; // Error handling: RealtimeErrorHandling = handleErrors ? RealtimeErrorHandling.StopStrategyCancelOrdersClosePositions : RealtimeErrorHandling.TakeNoAction; // Exit any position 60 minutes before the close; ExitOnClose = true; ExitOnCloseSeconds = 3600; SyncAccountPosition = false; // Maximum bar lookback MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; // Add any indicators to the chart here Add(SMA(movingAveragePeriod)); } catch (Exception ex) { if (debugOutput) { DebugMessage(BarsInProgress, CurrentBar, Instrument, "Exception caught Initialize(): " + ex); } } }
I should note that I'm using a 10 min delayed feed from DTN for "live" testing - would this cause issues?
Comment