
Short answer. Exit on session close is a NinjaTrader strategy setting that closes the strategy's open position shortly before the end of each session in the chart's Trading Hours template. By default it fires 30 seconds before the close, and only in real time. Leave it on for intraday strategies. Turn it off only for a strategy built to hold overnight, and make sure the Trading Hours template matches the session you mean.
What exit on session close does
Every NinjaScript strategy has an Exit on session close property, called IsExitOnSessionCloseStrategy in code. When it's on, NinjaTrader closes the strategy's open position shortly before the end of each trading session, and cancels the strategy's working orders. It's a safety net for intraday strategies: whatever the strategy's own exits do, the position won't be carried past the session end.
Three details matter:
- It closes the strategy's position, not your whole account. A manual trade on the same account isn't touched.
- It works on every session in the Trading Hours template the strategy uses, not just once a week or once a day by the clock.
- It's on by default for most strategies, though a developer can set a different default in code.
Which "session close"? The Trading Hours template
NinjaTrader doesn't decide the session close from the exchange calendar directly. It uses the Trading Hours template on the strategy's data series. NinjaTrader's help guide says the exit is triggered at the end of each session as defined by that template. Change the template and you change when the strategy is flattened.
| Template | Session end for US index and gold futures | Effect on exit on session close |
|---|---|---|
| CME US Index Futures ETH, or the metals ETH template | The daily Globex close, 5 PM ET (4 PM CT) | Flat once a day, just before the daily maintenance break |
| CME US Index Futures RTH | The regular hours close in the afternoon | Flat at the end of regular hours, with nothing held into the evening |
| A custom template | Whatever window you define | Flat at the end of your window |
| "Use instrument settings" | The template set for that instrument in the Instruments window | Check which one that is before relying on it |
Our Trading Hours template guide covers how to view, pick and build templates. The key habit: open the data series settings, read the template name, and know exactly when that template's sessions end.
Exit on session close seconds
The companion setting, Exit on session close seconds (ExitOnSessionCloseSeconds), sets how many seconds before the session end the exit fires. NinjaTrader's default is 30 seconds.
- Real time only. The help guide notes that this setting only applies in real time. In a backtest, the exit is processed on the last bar of the session instead.
- Give it room. Liquidity gets thinner near the daily close. A larger value, such as a few minutes, gives the exit order more time to fill before the session ends.
- Bars must keep updating. The exit fires on incoming data. On a quiet market with no ticks, it can fire late.
- Some bar types differ. Bar types like Renko that don't build bars on a time basis can end a session without a bar at the close. The help guide's Break at EOD option, which starts a new bar at the end of each session, is relevant here; leave it on if you rely on session-based logic.
Backtests vs real time
In the Strategy Analyzer, exit on session close is applied on the last bar of each session. That means a backtest with it on shows every trade closed by the session end, at the last bar's price. In real time, the exit is a market order sent a set number of seconds before the close, filled at whatever price is available then. The two won't match exactly, and the gap is wider on thin markets and bigger contract counts. Treat the backtest exit price as an estimate, not a fill you'll get.
Coded exits vs exit on session close
Most well-built intraday strategies have their own time exit, and use exit on session close only as a backstop.
| Coded time exit | Exit on session close | |
|---|---|---|
| When it fires | At a time the strategy sets, such as the end of its own trading window | A set number of seconds before the template's session end |
| Depends on the template | No, if it uses clock time | Yes |
| Order type | Whatever the developer chose | A market order |
| Purpose | The planned end of the day's trading | A safety net if anything is still open |
Our strategy time filter guide covers how time windows and coded exits work. FuturesBotLab bots such as Gap Runner (MES · ES) and Gold Reload (MGC · GC) trade the New York session and are designed to be flat by the end of it.
Overnight, the daily break, weekends and the Sunday open
- The daily break. CME Globex closes each weekday from 5 PM to 6 PM ET for gold and US index futures. With an ETH template, exit on session close flattens the strategy just before that break.
- Weekends. The Friday close is the last session of the week. With the setting on, the strategy is flat into the weekend.
- The Sunday open. Globex reopens Sunday at 6 PM ET. A strategy that was flat on Friday starts the new week flat, and the first bars on Sunday evening can gap from Friday's close.
- Overnight holds. If a strategy is built to hold past the session end, exit on session close will undo that by closing it every day. That's the main reason to turn it off.
Holidays and shortened sessions
CME shortens or closes sessions around US holidays. NinjaTrader's Trading Hours templates include holiday and partial-day sessions, so exit on session close should follow an early close. But it's only as good as the template: keep NinjaTrader updated, and check CME's own holiday calendar before a holiday week. Our futures market hours tool lists the CME holiday windows we've checked and links to CME's calendar.
When to turn it off
Leave exit on session close on unless you have a clear reason. Reasonable reasons to turn it off:
- The strategy is designed to hold positions across sessions, and the developer says to turn it off.
- The strategy handles its own end-of-day exit and the developer specifically recommends turning the backstop off, for example to avoid a market order right at the close.
- You're testing a multi-day idea in the Strategy Analyzer and want to see trades held overnight.
If you turn it off, understand what you take on: the position can be held through the daily break, overnight and the weekend, where price can gap past a stop. Margin requirements for positions held past the session end are usually higher than intraday margin. Your account provider publishes the overnight margin it requires.
Troubleshooting
- It closed earlier than I expected. The strategy is probably on an RTH or custom template. Check the data series' Trading Hours template.
- It didn't close at all. Check the setting is on in the strategy's properties, that the strategy was enabled and connected at the close, and that the PC was running. It can't fire on a machine that's asleep; see do you need a VPS.
- It closed late or at a poor price. Increase Exit on session close seconds, and remember the exit is a market order in thin liquidity.
- The backtest looks better than real time at the close. The backtest uses the last bar's price; real time uses a market order seconds before the close.
- It closed on a holiday at an odd time. The template followed CME's holiday session. That's usually what you want.
For what happens when you enable the strategy again the next session, see strategy start behavior.
How to check the setting, step by step
- Open the strategy's properties. On the chart, open the Strategies window, or find the strategy on the Strategies tab of the Control Center and open its settings. Disable the strategy first, because most settings can't change while it runs.
- Find the Order handling section. Exit on session close and Exit on session close seconds sit together there.
- Read the data series. In the same window, check the Trading Hours template the strategy's data series uses. That template sets the session end.
- Work out the exit time. Take the template's session end and subtract the seconds setting. That's when the strategy will be flattened in real time.
- Compare with the strategy's own exit. If the strategy has a coded time exit, it should normally come first, so the session close exit is only a backstop.
- Test it. Run the strategy on a simulated account through one session close and confirm on the Orders tab that the exit fired when you expected.
Two worked examples
An index strategy on an ETH template. A strategy on MES uses the CME US Index Futures ETH template, with the default 30 seconds. Its session ends at the daily Globex close, 5 PM ET, so any open position is closed with a market order about 30 seconds before that. A strategy meant to finish by the regular hours close needs its own time exit, because the backstop is hours later.
The same strategy on an RTH template. Switch the template to CME US Index Futures RTH and the session ends at the regular hours close in the afternoon. Exit on session close now flattens the strategy then, and its indicators only see regular hours bars. That changes more than the exit: overnight bars disappear from the chart, so values like a daily high or a moving average change too. Change templates deliberately and test again after you do.
A note on risk at the close
The minutes around the daily close can be quieter, with wider spreads, and a market order in those minutes can fill away from the last price. That's why a coded exit a little earlier, plus exit on session close as a backstop, is a common pattern for intraday strategies. Use the tick value calculator to see what a few ticks of slippage cost on your contract and size.
Finally, write the exit time down next to each strategy you run: the template, the session end, the seconds setting and the strategy's own exit. When something closes at an unexpected moment, that note answers the question in seconds. Review it whenever you change a template, update NinjaTrader, or move the strategy to another machine, because each of those can change which session end the strategy sees and therefore when it will be flattened.
Related guides
- Strategy start behavior explained: wait until flat, immediately submit, synchronize account →
- NinjaTrader trading hours templates: set up Asia, London and New York sessions →
- How to add a session time filter to a NinjaTrader strategy →
- Strategy not showing in NinjaTrader: every cause and fix →
- Can you run automated strategies in NinjaTrader? What you need first →
- Do you need a VPS to run a futures bot? Local PC vs VPS →
- Automated futures trading in NinjaTrader: how it works →
- Futures trading sessions: Asia, London and New York times →
- NinjaTrader daily loss limit and strategy safety settings →
- How to import a strategy into NinjaTrader →
Bots mentioned in this guide
Futures trading involves substantial risk of loss and is not suitable for every investor. Past or hypothetical results don't guarantee future results. This guide is educational, not investment advice. Risk disclosure.