Short Limit Entry Order with “Is Live Until Cancelled” with Entry Order Cancellation After “X” Bars (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 number of bars to which the input parameter named “Number of Bars Before Entry Limit Order Should Be Cancelled” is set (and certain other user-specified conditions are True) or 2) if the “Exit on Session Close” check box is checked in the “Strategy Details” section below.
This strategy has an input parameter named “Cancel Entry Order If Partially Filled” that allows the user to decide if partially filled limit orders should be cancelled or if these limit orders should continue to be working in the market.
The strategy also has input parameters that allow the user to decide how much lower the last price needs to be than the limit order price before the limit order is allowed to be cancelled, or if the limit order should be cancelled regardless of how close the last price is to its limit price. Read the description of the input parameter named “Cancel Entry Order Regardless of the Closeness of Last Price to the Limit Price” for more information about why a trader might not want the limit order to be cancelled when the last price is very close to its limit price.
This strategy demonstrates the following advanced techniques of building NinjaScript® strategies that use “advanced managed order handling” without code using Quagensia N Edition:
- Using a “Is Live Until Cancelled” entry limit order.
- Creating an internal variable of Type “NinjaScript® Order Object”.
- Explicitly setting an internal variable of Type “NinjaScript® Order Object” to the “Cbi.Order order” parameter of the advanced NinjaScript® event-driven method named “OnOrderUpdate” from within the “When OnOrderUpdate Occurs” section of a Quagensia N Edition Strategy.
- Converting a historical order to a real-time order in the “When OnOrderUpdate Occurs” section of a Quagensia N Edition Strategy.
- Explicitly cancelling the entry order after a specified number of bars using an internal variable of Type “NinjaScript® Order Object”.
- Explicitly setting an internal variable of Type “NinjaScript® Order Object” to null once the NinjaScript® Order object is represents is Rejected, Cancelled, or Filled in the advanced NinjaScript® event-driven method named “OnOrderUpdate” from within the “When OnOrderUpdate Occurs” section of a Quagensia N Edition Strategy.
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.


