Add a Button to a NinjaTrader Chart to Flatten a Long or Short Position and Add a Kill Switch Button (Point-and-Click NinjaTrader® Strategy)
Original Trading Strategy
Peer Reviews, Modifications & Responses
Thanks for Sharing!
Trading Strategy Summary
This strategy demonstrates how to add a button to the NinjaTrader® chart upon which a strategy is applied that will allow you to manually flatten a long or short position managed by the strategy.
This strategy also demonstrates how to add a “kill switch” button to the NinjaTrader® chart upon which a strategy is applied that will allow you to manually close the strategy, cancel its working orders, and disable the strategy.
This strategy builds upon the built-in Quagensia N Edition Strategy named “Add a Toggle Button to a NinjaTrader® Chart to Enable or Disable New Automated Entries” so also includes a “toggle button” that is added to the NinjaTrader® chart upon which the strategy is applied that will allow you to manually enable or disable new automated entries for the strategy, and includes “Enter Long” and “Exit Long” buttons that are added to the NinjaTrader® chart upon which the strategy is applied that will allow you to manually short-circuit its automated logic.
This strategy doesn’t actually enter or exit short positions automatically nor does it have “Enter Short” or “Exit Short” buttons but you could easily add automated short entries and exits in this strategy’s “When Bar Updates” section by creating logic similar to the automated long entry and exit logic in that section, and add “Enter Short” and “Exit Short” buttons to the strategy by copying the way that this strategy’s “Enter Long” and “Exit Long” buttons are set up in both this strategy’s “Internal Variables” section and in the respective “Button Control” sections of the “Enter Long” and “Exit Long” buttons. If you do this, both this strategy’s “Flatten Position” button and its “Kill Switch” button will handle exiting short positions without any adjustments to the trading logic in the “Flatten Position” or “Kill Switch” buttons’ “When Button Control is Clicked” sections.
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.


