Short Limit Entry Order with Simulated, Non-Advanced Version of “Is Live Until Cancelled” with Entry Order Cancellation After “X” Bars (Non-Advanced Managed Order Handling) (Point-and-Click NinjaTrader® Strategy)
Original Trading Strategy
Peer Reviews, Modifications & Responses
Thanks for Sharing!
Trading Strategy Summary
This mean reversion strategy places a limit order to enter a short position a specified number of ticks above the close price when the close price closes above the upper band of a Bollinger Bands® indicator while the close price is going up and exits using a trailing stop or profit target.
The entry limit order will “time out” and be cancelled 1) *after* the bar close of the bar that occurs after the number of bars to which the input parameter named “Number of Bars Before Entry Limit Order Should Be Cancelled” is set or 2) if the “Exit on Session Close” check box is checked in the “Strategy Details” section below. Note that the simple trading logic in this strategy does not submit a request to cancel the entry limit order as soon as the first “When Bar Updates” event occurs on the first bar that occurs after the specified number of bars even if the strategy’s Calculate is set to “On each tick” or “On price change”; the request to cancel the entry limit order will instead be automatically submitted by the NinjaTrader® platform *after* the close of the bar on which the first tick or price change occurred where the no-code function named “Enter Short Position Using A Limit Order” stopped being called.
This strategy demonstrates how to *simulate* using an *advanced* limit entry order that uses the “Is Live Until Cancelled” feature that is part of the “advanced managed order handling” technology that is part of NinjaScript®, but it does so with the least amount of usage of the features of “advanced managed order handling” possible while still being relatively robust and while still working for a large number of use cases.
This makes it possible for traders who are not experienced NinjaScript® programmers to create strategies with Quagensia N Edition without code that submit limit, stop, stop limit, and MIT orders that are “kept alive” after each bar close on which the orders should remain working, similar (but not exactly the same) to how one of these orders would behave if they were submitted using one of the advanced no-code functions that allows Quagensia N Edition users to submit a limit, stop, stop limit, or MIT order with its “Is Live Until Cancelled” flag set to True. One possibly *major weakness* of doing it the “non-advanced” way as demonstrated in this strategy is that it is not possible to cancel the entry limit order in the middle of a bar, whereas the “advanced” way allows the entry limit order to be cancelled in the middle of the bar instead of needing to wait until *after* the close of the bar before the entry limit order can be cancelled.
This strategy demonstrates a practical use of the “When OnOrderUpdate Occurs” subsection of the “When Advanced NinjaScript® Events Occur” section. In this strategy, the main purpose of the logic in that section is simply to set the Boolean (True or False) Internal Variable named “Entry Limit Order Should Be Working In The Market” to False once the entry limit order named “SE” has reached a terminal state such as “Filled”, “Rejected”, “Cancelled”, or “Unknown”.
At the bottom of the “When OnOrderUpdate Occurs” section mentioned in the paragraph above there is also an example of using the “Use TriggerCustomEvent to Sync Logic on Data Series” Action block, which makes it possible to use no-code functions and features that require accurate market data and indicator data in the advanced sections in Quagensia N Edition Strategies where accurate market data and indicator data are not guaranteed to be available by default. The “When OnOrderUpdate Occurs” section is one of these sections, and the no-code function named “Print To Output Window (With Primary Data Series Time Stamp)” that is used at the bottom of this strategy’s “When OnOrderUpdate Occurs” section is one of the no-code functions that require accurate market data since this no-code function also prints out the time stamp of the primary data series.
This Quagensia N Edition Strategy’s “Calculate” drop-down list is set to “On Bar Close” by default (scroll down a little to see and change the value of this drop-down list), so all calculations and all movements of the trailing stop will occur only once per bar by default. If you want the trailing stop to move more frequently than once per bar in contexts that support it, you can change the “Calculate” drop-down list in the NinjaTrader® user interface to something other than “On bar close”, and you can change the default value to which the “Calculate” drop-down list in the NinjaTrader® user interface is set when this Quagensia N Edition Strategy’s code is generated and sent to the NinjaTrader Strategy Code Folder for the first time with a specified “Strategy Name Inside of NinjaTrader®” field (scroll up a little to see and change this field) by changing the value of the “Calculate” drop-down list at the top of the “Strategy Details” section this Quagensia N Edition Strategy.
This strategy will skip new entry signals until at least the number of bars to which the input parameter named “Required Number of Bars Between Successive Entry Signals” is set, so if an entry signal occurs, is filled on the same bar, and then the trailing stop or profit target exits the position on the same bar, entry signals will be skipped until there have been enough bars subsequent to the previous entry signal.
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.


