Short Limit Entry Order with Simulated, Non-Advanced Version of “Is Live Until Cancelled” with Entry Order Cancellation After “X” Bars and Custom Exit at End of Session (Point-and-Click NinjaTrader® Strategy)
Original Trading Strategy
Peer Reviews, Modifications & Responses
Thanks for Sharing!
Trading Strategy Summary
Introduction
This strategy is intended to be the same as the strategy named “Short Limit Entry Order with Simulated, Non-Advanced Version of ‘Is Live Until Cancelled’ with Entry Order Cancellation After ‘X’ Bars” with the exception that it also has custom “Exit at End of Session” trading logic.
The custom “Exit at End of Session” trading logic in this strategy allows a strategy to flatten any open short position and signal to the NinjaTrader® platform to cancel any working entry limit order *after* the current bar closes even at times that are very far from the end of the session, including hours before the session ends, and not consider re-entering until the start of the next session (*unless* an entry limit order was working and hasn’t yet been cancelled automatically by the NinjaTrader® platform *after* the end of the bar that triggers the custom “exit at end of session” logic, in which case the entry limit order *could still be filled* through the end of the triggering bar). See the section named “*** PROS AND CONS OF THIS STRATEGY’S CUSTOM “EXIT AT END OF SESSION” TRADING LOGIC ***” somewhat further down in this “Description & Notes” field to learn more about when you might want to use this strategy’s custom “Exit at End of Session” trading logic and when you shouldn’t use it.
This custom “Exit at End of Session” trading logic can be seen at the top of the “When Bar Updates” section, and includes a lot of logic. The logic starts at the very top of the “When Bar Updates” section, starting after the “Comment in Code” component that reads “STEP #1: Handle the Trading Is Allowed Based on Filter ‘Seconds From Session Close To Cease Trading’ Logic” and goes all the way down to directly above the “Comment in Code” component that reads “STEP #2: Determine if there is an entry signal, or if there have been too many bars since the last entry signal.”
WANT TO LEARN? Please read the “Description” fields of the input parameters that start with the one named “Initiate a Cease in Trading After ‘Seconds From Session Close To Cease Trading'” and continue down to the second to last input parameter in the “Input Parameters” section, and read the “Comment in Code” components in the relatively large amount of trading logic at the top of the “When Bar Updates” section described in the last paragraph to learn more about how this strategy’s custom “Exit at End of Session” trading logic is implemented.
How to Copy and Paste This Quagensia N Edition Strategy’s Custom “Exit at End of Session” Trading Logic into Your Own Quagensia N Edition Strategy
IN A HURRY AND WANT TO USE THE CUSTOM “EXIT AT END OF SESSION” LOGIC IN YOUR OWN STRATEGY IN THE LEAST AMOUNT OF TIME? You only need to copy and paste trading logic from two locations in this Quagensia N Edition Strategy into your own Quagensia N Edition Strategy to do this.
First, do a multi-action copy of the custom “Exit at End of Session” trading logic at the top of the “When Bar Updates” section of this strategy, then paste these actions at the top of the “When Bar Updates” section of your own strategy. The logic starts at the very top of the “When Bar Updates” section, starting after the “Comment in Code” component that reads “STEP #1: Handle the Trading Is Allowed Based on Filter ‘Seconds From Session Close To Cease Trading’ Logic” and goes all the way down to directly above the “Comment in Code” component that reads “STEP #2: Determine if there is an entry signal, or if there have been too many bars since the last entry signal.” Note that this includes a lot of logic so you will need to scroll down for a while to find the end of this logic. Note that when you do this, all the Input Parameters and Internal Variables used by this trading logic will also be automatically copied into your strategy.
Then, scroll down to the *bottom* of the “When OnOrderUpdate Occurs” subsection of the “When Advanced NinjaScript® Events Occur” section and copy everything in that section by clicking the “Add Trading Logic” link that appears at the end of the section when you place your mouse pointer over anything in that section and selecting “Copy All Items” from the context menu that appears. Then, paste all items just copied from the “When OnOrderUpdate Occurs” section into your Quagensia N Edition Strategy. If the “When OnOrderUpdate Occurs” section in your Quagensia N Edition Strategy is empty, just click on the “Add Trading Logic” link at the bottom of the section and select “Paste” from the context menu that appears. If the “When OnOrderUpdate Occurs” section in your Quagensia N Edition Strategy is *not* empty you will need to actually understand the trading logic enough to be able to decide if the trading logic on the clipboard should be pasted above the pre-existing trading logic in the “When Bar Updates” section or below it. You can paste the trading logic from the clipboard above the pre-existing logic by clicking on the first action at the top of that section and selecting “Paste Before Me” from the context menu that appears. You can paste the trading logic from the clipboard below the pre-existing logic by clicking the “Add Trading Logic” link that appears at the end of the section when you place your mouse pointer over anything in that section and selecting “Paste”.
Pros and Cons of This Strategy’s Custom “Exit at End of Session” Trading Logic
This strategy’s custom “Exit at End of Session” trading logic has some weaknesses and some strengths when compared to the trading logic that can be implemented simply by checking the “Exit on Session Close” check box and entering a number into the “Exit on Session Close Seconds” text box in the “Strategy Details” section of this Quagensia N Edition Strategy. Some of these weaknesses and strengths are mentioned below.
KNOWN WEAKNESS #1 OF THE CUSTOM “EXIT AT END OF SESSION” TRADING LOGIC: Regardless of whether the strategy is being run on realtime bars, regardless of whether the strategy’s “Calculate” field is set to “On each tick” or “On price change”, and regardless of whether the triggering tick or price change occurred at the start or in the middle of a bar, the entry limit order will only be cancelled *after* the triggering bar closes. In the special case of the triggering bar being the *last* bar of the session this would mean that the entry limit order will *not* likely be cancelled during the session. This is even a weakness if the triggering bar is *not the last bar of the session* since there is still a chance the entry limit order will be filled after the triggering tick or price change but before the NinjaTrader® platform actually cancels it *after* the triggering bar closes.
KNOWN WEAKNESS #2 OF THE CUSTOM “EXIT AT END OF SESSION” TRADING LOGIC: The market order that flattens the short position that may exist when the custom “exit at end of session” trading logic is triggered would end up not being able to flatten the position before the end of the session if it is triggered “On bar close” of the last bar of the session, and instead would be unlikely to be able to flatten the position until the start of the next session, leading to holding a potentially highly leveraged position “overnight” or at least until the start of the next session. For historical price bars (including all price bars in Strategy Analyzer), even if the strategy’s “Calculate” field was set to “On each tick” or “On price change” in the NinjaTrader® user interface, historical bars only call the “When Bar Updates” section of this strategy “On bar close”, so if a triggering bar is the last bar of a session and the bar is a historical bar, the market order to flatten the position would show a historical execution on the open of the first bar of the next session. This causes inaccurate historical executions, which would cause the backtests of the strategy in Strategy Analyzer to be very inaccurate if on realtime bars in realtime trading for a strategy whose “Calculate” field is set to “On each tick” or “On price change” in the NinjaTrader® user interface the strategy could flatten its position by the end of the session if there was enough time after the triggering tick or price change to submit a market order to flatten the position (and enough time for it to be filled).
BENEFIT #1 OF THE CUSTOM “EXIT AT END OF SESSION” TRADING LOGIC: There are *no re-entries* after the “Exit on Session Close Seconds” time (*unless* an entry limit order was working and hasn’t yet been cancelled automatically by the NinjaTrader® platform *after* the end of the bar that triggers the custom “exit at end of session” logic, in which case the entry limit order *could still be filled* through the end of the triggering bar). The custom logic doesn’t just inform the NinjaTrader® platform to cancel the entry limit order at the end of the triggering bar and flatten all open positions; it also *disallows new orders* from being submitted from the strategy for the remainder of the session. This is *different* than the behavior that can be achieved using the two aforementioned fields in the “Strategy Details” section, because if your strategy depends solely on checking the “Exit on Session Close” check box and entering a number into the “Exit on Session Close Seconds” text box in the “Strategy Details” section, there is always the chance that a new entry limit order could be submitted for the remainder of the session that occurs *after* the date and time that is equal to the session end time minus the number of seconds specified in the “Exit on Session Close Seconds” field through the session end time. While setting the value of the “Exit on Session Close Seconds” text box to a small number, like 30 seconds, may greatly reduce the odds of submitting a new entry limit order and even entering a new position, the market would still have 30 seconds to potentially move in a way that your strategy would identify as a being a new entry signal. And if an entry order submitted in the last 30 seconds of the session is filled and you are using a lot of leverage, you could end up with a highly leveraged position that is held “overnight”, or at least during the time between a session end time and the next session start time. Note that this benefit of the custom “exit at session close” logic is only a real benefit if the triggering bar closes in enough time for the NinjaTrader platform to submit a cancel request (and in enough time for the order to actually be cancelled) for the entry limit order *after* the triggering bar closes but before the session end time.
BENEFIT #2 OF THE CUSTOM “EXIT AT END OF SESSION” TRADING LOGIC: The number of seconds entered into the “Seconds Before Session Close On or After Which the Next ‘When Bar Updates’ Should Initiate a Cease in Trading” input parameter of this strategy will also work in back-tests (with the limitation that the bar time used to check against the date and time equal to the session end time minus a number of seconds equal to the value of the input parameter named “Seconds Before Session Close On or After Which the Next ‘When Bar Updates’ Should Initiate a Cease in Trading’ input parameter will be equal to the *bar end time* of historical bars even if this strategy’s “Calculate” field is set to “On each tick” or “On price change” in the NinjaTrader® user interface), whereas the positive number of seconds entered into the “Exit on Session Close Seconds” text box will likely have no impact when the strategy is being run on historical bars. For this reason, the behavior of the custom “exit at end of session” trading logic in back-tests may be closer to this behavior when run on real-time bars.
Learn More
This strategy is intended to be the same as the strategy named “Short Limit Entry Order with Simulated, Non-Advanced Version of ‘Is Live Until Cancelled’ with Entry Order Cancellation After ‘X’ Bars” with the exception that it also has custom “Exit at End of Session” trading logic. To learn more about the rest of the trading logic in this strategy that isn’t related to the custom “Exit at End of Session” trading logic, please read the “Description & Notes” field of that strategy.
To learn more about both non-advanced and advanced managed order handling in NinjaScript® strategies, please read the help page from ninjatrader.com at https://ninjatrader.com/support/helpGuides/nt8/managed_approach.htm.
To learn more about advanced managed order handling in NinjaScript® strategies, please read the help page from ninjatrader.com at https://ninjatrader.com/support/helpGuides/nt8/advanced_order_handling.htm.
Copyright © 2025 Quagensia, Inc. All rights reserved.
How to Get the Quagensia Strategies
This point-and-click trading strategy is built into Quagensia N Edition (for NinjaTrader®).
Customize Quagensia Strategies with Your Own Ideas
Tweaking Quagensia Trading Strategies using point-and-click with the Quagensia Desktop Application is easy for non-programmers. If you get stuck you can usually find the answer you need in our online help documentation or you can ask a question in our friendly Discord community.
If you don’t want to tweak a Quagensia Trading Strategy with point-and-click to add your own proprietary trading logic, you can still download a Quagensia Trading Strategy file, open it up in the Quagensia Desktop Application, and generate its code, then backtest and optimize the trading strategy on different instruments, different bar periods (weekly bars, daily bars, hourly bars, 15-minute bars, etc.), or different bar types (time-based bars, volume-based bars, tick-based bars, etc.), and use different start and end dates.
Some tweaks you can make to the Quagensia Trading Strategies you download include:
Modify the entry & exit logic.
- Add more conditions, remove conditions, or change them by choosing from among a very large number of components, including many exotic indicators.
- Add or modify stop losses, trailing stops, and profit targets. Make them tighter, less tight, or based on an entirely different calculation.
- Add or modify time stops. For example, exit after a certain number of bars either unconditionally or only if the post-entry price action did or did not exhibit certain characteristics.
Enhance the output of the strategy to go beyond simply placing orders.
- Draw lines, shapes, and text on the chart. For instance, you can mark times or prices where each entry or exit condition of a multi-condition entry or exit was true, even if all the necessary entry or exit conditions were not true at the same time so an entry or exit did not occur.
- Write information to NinjaTrader®’s NinjaScript® Output window or TradeStation®’s EasyLanguage® Print Log window.
- Write information to a file. You can even output a report that can be opened in Microsoft Excel or consumed by another application that reads comma-delimited, semicolon-delimited, or otherwise character-delimited tabular data files.


