Custom-Built ATR-Weighted Moving Average and ATR Bands in an Intraday Long-Short Reversal Strategy (Point-and-Click NinjaTrader® Strategy)
Original Trading Strategy
Peer Reviews, Modifications & Responses
Thanks for Sharing!
Trading Strategy Summary
The main purpose of this long-short reversal strategy is to demonstrate how to create and plot your own custom-built indicators inside of a Quagensia N Edition Strategy so that you are not limited to the indicators that are built into NinjaTrader® and the indicators that you download from third parties.
The indicator created and plotted in this strategy has three plots, including a “Middle Line”, an “Upper ATR Band” and a “Lower ATR Band”, and in this way is very similar to the Bollinger Bands® indicator built into NinjaTrader®.
The Middle Line is a custom-built “ATR-Weighted Moving Average” which is calculated by dividing the following two numbers:
- Numerator: The ATR-weighted sum of the close prices, which is the sum of the products (i.e. multiplications) of the “Close Price * ATR” for each bar of the last number of bars specified by the “ATR-Weighted MA Period” input parameter.
- Denominator: The sum of the ATR-weighting values themselves (without multiplying them by the close prices) for that number of most recent bars.
The two numbers above are calculated by looping over the last number of bars specified by the “ATR-Weighted MA Period” input parameter by using a Quagensia N Edition Loop and calculating the running totals of these two numbers.
The Upper and Lower ATR Bands of this strategy’s custom-built indicator are simply the prices that are the specified number of ATRs above and below the ATR-Weighted Moving Average.
While the trading logic of this long-short reversal strategy is a little complex due to its handling of specific edge cases, the most important rules of this long-short reversal strategy’s trading logic are as follows:
- If the Upper ATR Band was breached then:
- If the last short entry occurred less recently than the last downside breach of the ATR-Weighted Moving Average while the strategy was not short, then enter a short position or reverse from long to short.
- If the strategy is long but the last short entry occurred more recently than the last downside breach of the ATR-Weighted Moving Average while the strategy was not short, exit the long position but do not reverse to short.
- Otherwise do nothing.
- If the Lower ATR Band was breached then:
- If the last long entry occurred less recently than the last upside breach of the ATR-Weighted Moving Average while the strategy was not long, then enter a long position or reverse from short to long.
- If the strategy is short but the last long entry occurred more recently than the last upside breach of the ATR-Weighted Moving Average while the strategy was not long, exit the short position but do not reverse to long.
- Otherwise do nothing.
The “Calculate” field in this Quagensia N Edition Strategy’s “Strategy Details” section is set to “On Price Change” by default. Much of the logic of this strategy deals with the issues and challenges of real-time trading for a strategy whose “Calculate” field is set to “On Price Change” or “On Each Tick”, not just “On Bar Close”. This strategy’s logic is meant to be a demonstration of how the logic of a single strategy can handle all three values of the “Calculate” field, removing the need for a trader to create one strategy that only works if its “Calculate” field is set to “On Bar Close” and a second strategy that only works if its “Calculate” field is set to either “On Price Change” or “On Each Tick”.
Copyright © 2024 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.


