Counterfactual Trading Logic (Uses Parallel Lists) (Point-and-Click NinjaTrader® Strategy)
Original Trading Strategy
Links to the section of the video titled “Using & Customizing the Built-In Strategies in Quagensia N Edition” in which this built-in strategy is covered.
Peer Reviews, Modifications & Responses
Thanks for Sharing!
Trading Strategy Summary
This Quagensia Strategy uses the power of lists to create an easily customizable “counterfactual trading logic” system. It acts as a template strategy that allows you to plug in your own entry and exit logic to create a trading strategy that only places actual trades when your preferred number of most recent entry and exit signals “would have” produced trades either above or below your preferred profit level.
This strategy uses lists to keep track of what “would have happened” if an actual trade had been entered every time your entry logic triggered and if those actual trades were exited every time your exit logic triggered to create a real-time, up-to-date historical list of possible trades and their hypothetical trading performance.
In this strategy, the trades not taken despite the entry signal trigger occurring are referred to as “counterfactual trades”. The trades where actual entry and exit orders are placed are referred to as “actual trades”. The term “counterfactual trading logic” refers to trading logic that takes into account the performance that “would have been achieved” by the most recent “counterfactual trades” had they been “actual trades”.
“Counterfactual trading logic” is just one example of the many kinds of powerful things that can be done without code using lists in Quagensia N Edition. Quagensia N Edition makes it easy to create and use lists, single-dimensional arrays, and multi-dimensional arrays of data of the Quagensia data types that represent a single value, such as numbers, dates, times, colors, items selected from a list of choices, text, or Booleans (true or false). You may not start out using lists and arrays on day one, but soon enough you will probably find that the use of lists and arrays is the only way to accomplish an intermediate or advanced level task, and you will realize that lack of support for lists and arrays would severely limit your ability to create advanced trading strategies such as those that use “counterfactual trading logic”.
NOTE: This strategy is meant to be used with trading logic that enters and exits the entire position quantity at once. In other words, this strategy is not meant to be used with trading logic that is intended to scale in and out of positions, i.e. trading logic that enters a trade more than once to build up a position before exiting the trade or that exits a trade more than once to scale out of a position before reentering.
Copyright © 2023 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.


