It's most likely Exit on session close, which is on by default. In real time, 30 seconds before the session ends, the strategy cancels its orders and closes its positions. If it seems to close at an odd time, check the Trading Hours template: that's where the time comes from.
On this page
What it does exactly
IsExitOnSessionCloseStrategy is true by default. It cancels all strategy-generated orders and closes open strategy positions at the session close. On multi-timeframe or multi-instrument strategies it acts at the close of any of their sessions, across all instruments.
Where the time comes from
ExitOnSessionCloseSeconds defaults to 30 and counts back from the EOD time in the strategy's Trading Hours template. That's why a template that differs from your real schedule makes the exit come earlier than you expect. You can change both settings in the strategy window or in OnStateChange(), during State.SetDefaults or State.Configure.
Why the backtest exits at a different time
The seconds setting only works in real time. On historical data, the position exits at the close of the session's last bar. That gap changes the exit price and is one more reason a backtest doesn't match live trading.
Three confusing cases
- Renko without Break at EOD. If it's False, the last bar can run past the close, and so can the historical exit.
- Finer fill resolution. Even with High Order Fill Resolution, the exit stays tied to the primary series bar.
- Daily bars. The guide warns against combining it with daily bars and High Order Fill Resolution, and says the feature is designed for intraday strategies only.
If you want to keep the position
Turning the setting off means the strategy won't exit through this feature, so the position can carry into the next day. Before you do, decide what happens if the PC or connection fails overnight. Also review what a disconnect does.
How to check it
- Look at the exit time in your executions list.
- Open the strategy settings and check Exit on session close and its seconds.
- Open its Trading Hours template and check the EOD time.
- Confirm that time matches the hours you want to trade.
On a prop firm account, this time matters. Many firms set a time to be out of positions, and it won't necessarily match your template. Confirm your firm's schedule and leave a margin: if your exit relies on NinjaTrader's session end, make sure it comes before theirs.
Want someone to review it? We check the schedules and exits of your NinjaScript strategy.
Review from $90 Analyze NinjaTrader with AISources
- IsExitOnSessionCloseStrategy (NinjaScript Language Reference)
- ExitOnSessionCloseSeconds (NinjaScript Language Reference)
Keep reading
Free: The Other Half Workbook. Nine templates for trading with a cool head: your one-page plan, the pre-session checklist, the twelve-patterns test, your size and the bill for your mistakes.
Get the free workbookGet ready for 2027: the Trader Planner. Each day's US releases in New York time, your pre-market routine and a log for every session.
Paperback on Amazon, $16.99 Get the PDF, $9Educational content based on the official NinjaTrader documentation. Not investment advice. Test any change on a simulation account before using it live.