OPEN-SOURCE SCRIPT

Trend Range Detector (Zeiierman)

7 446
Overview
Trend Range Detector (Zeiierman) is a market structure tool that identifies and tracks periods of price compression by forming adaptive range boxes based on volatility and price movement. When prices remain stable within a defined band, the script dynamically draws a range box; when prices break out of that structure, the box highlights the breakout in real-time.
istantanea

By combining a volatility-based envelope with a custom weighted centerline, this tool filters out noise and isolates truly stable zones — providing a clean framework for traders who focus on accumulation, distribution, breakout anticipation, and reversion opportunities.

Whether you're range trading, spotting trend consolidations, or looking for volatility contractions before major moves, the Trend Range Detector gives you a mathematically adaptive, visually intuitive structure that maps the heartbeat of the market.
istantanea


How It Works
Range Formation Engine
The core of this indicator revolves around two conditions:
  • Distance Filter: The maximum distance between all recent closes and a dynamic centerline must remain within a volatility envelope.
  • Volatility Envelope: Based on an ATR(2000) multiplied by a user-defined factor to account for broader market volatility trends.

If both conditions are satisfied over the most recent length bars, a range box is drawn to visually anchor the zone.

Dynamic Breakout Coloring
When price breaks out of the top or bottom of the active range box, the box color shifts in real-time:
  • Blue Boxes represent areas where price has remained within a defined volatility envelope over a sustained number of bars. These zones reflect stable, low-volatility periods, often associated with consolidation, equilibrium, or market indecision.
  • Green Boxes for bullish breakouts.
  • Red Boxes for bearish breakdowns.

This allows traders to visually spot transitions from consolidation to expansion phases without relying on lagging signals.

Why Use a Weighted Close Instead of SMA?

A standard Simple Moving Average (SMA) treats all past closes equally, which works well in theory, but not in dynamic, fast-shifting markets. In this script, we replace the traditional SMA with a speed-weighted average that reflects how aggressively the market has moved bar-to-bar.

Here's why it matters:
  • Bars with higher momentum (larger price differences between closes) are given more weight.
  • Slow, sideways candles (typical in noise or low volume) contribute less to the calculated centerline.

This method creates a more accurate snapshot of market behavior, especially during volatile phases. As a result, the indicator adapts to market conditions more effectively, helping traders identify real consolidation zones, not just average lines distorted by flat bars or noise.

How to Use

Range Detection
  • Boxes form only when price remains consistently close to the speed-weighted mean.
  • Helps identify sideways zones, consolidations, and low-volatility structures where price is “charging up.”

istantanea

Breakout Confirmation
  • Once price exits the top or bottom boundary, the box immediately highlights the direction of the break.
  • Use this signal in conjunction with your own momentum, volume, or trend filters for higher-confidence trades.

istantanea

Settings
  • Minimum Range Length: Number of candles required for a valid range to form.
  • Range Width Multiplier: Adjusts the envelope around the weighted average using ATR(2000).
  • Highlight Box Breaks: Enables real-time coloring of breakouts and breakdowns for immediate visual feedback.


-----------------
Disclaimer

The content provided in my scripts, indicators, ideas, algorithms, and systems is for educational and informational purposes only. It does not constitute financial advice, investment recommendations, or a solicitation to buy or sell any financial instruments. I will not accept liability for any loss or damage, including without limitation any loss of profit, which may arise directly or indirectly from the use of or reliance on such information.

All investments involve risk, and the past performance of a security, industry, sector, market, financial product, trading strategy, backtest, or individual's trading does not guarantee future results or returns. Investors are fully responsible for any investment decisions they make. Such decisions should be based solely on an evaluation of their financial circumstances, investment objectives, risk tolerance, and liquidity needs.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.