Dual Range Reversion and Trend Tracker By WiselyWealth
Comprehensive Guide to the Dual Range Reversion and Trend Tracker
1. Introduction: Purpose and Concept
The Dual Range Reversion and Trend Tracker is a sophisticated, highly versatile technical indicator built in Pine Script. Financial markets generally alternate between two distinct behavioral phases: range-bound consolidation and directional trends. Traditional indicators often fail because they are designed to excel in only one of these environments, leading to false signals, or "whipsaws," when market conditions inevitably shift.
This script is engineered to solve that exact problem. Its primary purpose is to seamlessly adapt to shifting market structures by combining a mean-reversion strategy for sideways markets with a robust trend-following system for directional breakouts. By utilizing a smart, internal synchronization logic that prevents these two contrasting methodologies from clashing, the indicator provides traders with a cohesive, all-in-one suite designed to maximize their trading edge in both choppy and trending environments.
2. Core Working Mechanics: Signal Detection Engine
This indicator operates through two distinct mathematical engines, filtering its entries through an advanced pullback system.
The Range Detector and Reversion Engine (R-Signals):
The foundation of the sideways market analysis relies on a dynamically calculated Average True Range (ATR) band plotted around a Simple Moving Average (SMA). The script continuously scans for price action that remains confined within these ATR bands for a minimum consecutive number of bars. When the price successfully stays within this threshold, the script maps out a visible "Range Box" representing an active consolidation zone.
Instead of trading the breakout, this specific engine hunts for liquidity sweeps or false breakouts. An R-Buy is triggered when the price drops below the established lower boundary but manages to close back inside the box, effectively catching a "spring" or bear trap. Conversely, an R-Sell is generated when the price pierces the upper boundary but fails to hold, closing back inside to signal a bull trap.
The Alpha Trend Tracker (T-Signals):
When the market breaks out of consolidation and establishes a true directional move, the Alpha Trend component takes over. This system gauges momentum using either the Money Flow Index (MFI) or the Relative Strength Index (RSI), smoothed by an ATR-based trailing threshold. A T-Buy or T-Sell signal is triggered when the underlying Alpha Trend line crosses its own historical value, indicating a fundamental shift in broader market momentum.
Advanced Retest and Pullback Filter:
Unlike amateur trend systems that buy blindly into overextended breakouts, this script features an intelligent "Retest Mode." When a preliminary trend signal fires, the script calculates a specific pullback target—measured in either price ticks or a percentage drop. The system then enters a "pending" state. The final T-Buy or T-Sell signal will only be printed on the chart if the price retraces to touch this calculated target, ensuring a superior entry price. If the market aggressively runs away without pulling back, a built-in timer (max_wait_bars) ensures the trade is still executed before the move is missed entirely.
Smart Signal Synchronization (The Lock Mechanism):
Mean reversion and trend following are inherently conflicting strategies. To prevent chaotic, overlapping signals, the script employs an automatic locking mechanism. The moment a directional trend signal (T-Signal) fires, the script instantly disables all range-bound reversion signals (R-Signals). The reversion engine remains locked until the trend exhausts itself and the algorithm detects the formation of a brand-new, valid consolidation box.
3. Application: How to Use and Best Practices
To extract the maximum value from the Dual Range Reversion and Trend Tracker, traders must align the script’s parameters with the specific asset class being traded.
Optimal Settings:
For highly volatile assets like cryptocurrencies, consider increasing the "Range Width" (ATR Multiplier) to 1.5 or 2.0 to prevent minor wicks from constantly invalidating the range boxes. If you are trading fast-moving indices (like NASDAQ), keep the "Retest Value" relatively tight (e.g., a small tick count) and the "Max Candles to wait" to 3-5 bars. This ensures you catch the micro-pullbacks without getting left behind. Additionally, if you are trading Forex pairs on broker feeds that do not provide reliable volume data, you must check the "Change calculation (no volume data)" box. This shifts the Alpha Trend engine from using MFI to RSI, maintaining the indicator's mathematical integrity.
Suitable Markets and Timeframes:
This indicator thrives in markets that display clear structural shifts between accumulation phases and aggressive markup phases. It is highly effective on major Forex pairs, large-cap Cryptocurrencies, and global Equity Indices.
While it functions on lower timeframes, the sheer amount of intraday market noise can trigger premature signals. It is highly recommended to deploy this indicator on medium to high timeframes—such as the 15-minute, 1-hour, or 4-hour charts. These timeframes provide the algorithm with enough clean data to establish mathematically significant ranges, leading to highly reliable trend breakouts and reversion setups.
Credits and Acknowledgements
This indicator, the Dual Range Reversion and Trend Tracker, would not be possible without the brilliant foundational contributions of two highly respected developers in the TradingView community.
First, I would like to extend my deepest gratitude to KivancOzbilgic for the original AlphaTrend indicator. His innovative approach to combining ATR with volume-weighted momentum (MFI/RSI) forms the core of the trend-tracking engine in this script, allowing for highly accurate breakout detections and dynamic trailing support.
Second, a special thanks to LuxAlgo for their exceptional Range Detector script. Their elegant logic for mathematically defining and visually highlighting market consolidations serves as the exact backbone for the mean-reversion phase of this tool.
This combined script is a derivative work that bridges these two powerful concepts into a unified trading system. All credits for the foundational mathematical structures belong to KivancOzbilgic and LuxAlgo.
Indicador Pine Script®






















