OPEN-SOURCE SCRIPT
Обновлено

Range Expansion Divergence Oscillator

571
Range Expansion Divergence Oscillator

## Overview

The Range Expansion Divergence Oscillator turns **directional range expansion** - how large each bar range is versus its recent average, signed by the prevailing price direction - into a standardized, bounded oscillator, and then looks for **divergence between price and range**. The idea it tests: when price makes a new extreme on shrinking ranges, the move is "thin" and lacks effort behind it.

It is a single-pane oscillator. It needs no external data and no volume. Every data input is user-configurable, so it runs on any symbol, asset class or timeframe, in any market and on any timeframe. Defaults target NSE NIFTY index futures on intraday charts.

## What it plots

- A z-scored **range oscillator** (expanding range with the trend = up, contracting range = near zero), with a glow line and sigma-based overbought/oversold levels.
- **Extreme-zone bands** (default +/-3 sigma) with a gradient fill that deepens toward the edge.
- **Divergence lines and labels** on the oscillator - regular (reversal) and hidden (continuation), in two colors.
- **In-band reversal dots** where the oscillator turns inside an extreme zone.
- Optional **price-pane marks** at the confirmation bar (all generated by this one indicator).
- A **background-adaptive status dashboard** (oscillator value in sigma, zone, last divergence, last reversal, current range z-score).

## Why these components are combined (mashup rationale)

This script combines a **derived measure**, a **normalization stage**, a **divergence engine** and a **reversal read**, because each answers a question the others cannot and none is useful here alone:

1. **Directional range expansion (effort/participation).** Price geometry alone cannot show participation. A new high made on shrinking bar ranges is "thin"; a high on expanding ranges has effort behind it. The oscillator z-scores the bar range (high - low) versus its recent average and signs it by the net direction of price, giving the closest read to participation buildable from the bars of the instrument itself - with no volume required.

2. **Standardization (rolling z-score).** range differs in scale across instruments. The z-score expresses it in standard-deviation units, so "overbought/oversold" and the extreme bands mean the same thing on NIFTY, on a commodity future, or on a crypto instrument. Without this step the divergence thresholds would not transfer between symbols.

3. **Divergence engine.** The original payload is reading **price-versus-range disagreement at confirmed pivots**. The engine pairs each new price pivot with the oscillator value, then requires: a genuine new price extreme; the measure failing to confirm it; a minimum oscillator gap scaled to the oscillator own stdev; the two pivots within a maximum bar distance; and optionally an overbought/oversold reading at the pivot. These gates make the combination produce signal rather than noise.

4. **Reversal read.** Independently, the engine flags oscillator turns that occur inside the extreme bands - a complementary exhaustion cue.

Together the components form one pipeline: **build the signal -> make it comparable (z-score) -> surface where price and that signal disagree (divergence) and where it exhausts (reversal).** Each is incomplete alone.

## How it works (method)

bar range (high - low) is standardized to a rolling z-score, then signed by the net direction of price over the range window so that up = bullish; the result is the oscillator.

Regular and hidden divergence are detected from confirmed pivothigh/pivotlow pivots and filtered by the gates above; reversals are oscillator pivots that print inside the extreme bands. Pivots confirm a few bars after they occur, so a printed signal does not repaint. The confirmation lag equals the pivot length.

## How to use it

1. Add the indicator on any chart; no volume or external data is required.
2. Read divergence as **context, not a trigger**: a bearish divergence (price higher high, range lower high) says the new high lacks expanding range/effort; a bullish divergence says the opposite at lows. Confirm with your own structure, levels and risk process.
3. Tune the **pivot length**, **max gap** and **min oscillator gap** to your timeframe; raise them for fewer, cleaner signals.

## Originality

This is an original implementation - not a range line and not a generic divergence script, but the specific combination of range, sigma-standardization that makes the read portable across markets, a multi-gate divergence engine (magnitude + distance + extreme-zone), hidden-divergence and in-band reversal detection, and a background-adaptive dashboard. The code is written from scratch; helper functions use only their arguments and built-ins.

## Credits

Range-expansion / **effort-versus-result** analysis is a long-standing public technical-analysis approach (in the **Wyckoff** tradition). **Price/oscillator divergence** is likewise a standard, publicly documented technique. This script is not affiliated with, nor endorsed by, any third party.

## Notes / limitations

- Range is a participation proxy, not a direction call; the sign comes from a short price window, so very choppy segments can flip it.
- Divergence is descriptive context, never a guarantee of reversal.
- Confirmation lags each pivot by the pivot length.

## Disclaimer

Research and educational tool only. NOT financial advice and no guarantee of profitability or accuracy. Indicators describe past behaviour; they do not predict the future. Trading carries risk of loss. Test out-of-sample and make your own decisions. The author accepts no liability for any use of this script.

Информация о релизе
Range Expansion Divergence Oscillator — update notes

Forward calibration added. Each divergence and reversal class (Reg Bull/Bear, Hidden Bull/Bear, Rev +/−) is resolved by a triple-barrier outcome, uniqueness-weighted and recency-decayed, reported as an edge over a zone-matched base rate with a Wilson interval and a multiple-testing-corrected significance star — so you can see which range-expansion (participation) divergences actually pay.

Identity strip showing name · symbol · timeframe on the chart (theme-adaptive).
Exports bus: EXP_Osc, EXP_OscZ, EXP_Zone, EXP_Bias, EXP_RegDiv, EXP_HidDiv, EXP_Reversal, EXP_BullEdge, EXP_BearEdge, plus EXP_RangeZ.

Pro dashboard adds the per-class calibration table; settings reorganized into 7 groups; all toggles default-on; NIFTY/intraday defaults retained; no volume or external data required; effort/result credit (Wyckoff tradition) kept in the header, out of the UI.

Educational only — not financial advice. Range is a participation proxy, not a direction call; calibration is in-sample, forward-measured. Validate out-of-sample.
Информация о релизе
v1.1 — Three additive layers: robust normalization, a lag-minimal smoother, a 3-window extreme consensus, and a walk-forward out-of-sample reliability read. The directional range-expansion engine, the divergence engine and the triple-barrier zone-matched calibration are unchanged — set Normalization = "Classic (mean/stdev)" and Smoother = "EMA" for the original read.

1. Robust MAD normalization + UltimateSmoother (default on). The signed range-expansion series can be standardized with a median/MAD z-score (median absolute deviation ×1.4826) instead of mean/stdev, so an outlier bar doesn't blow out the sigma bands, and smoothed with Ehlers' lag-minimal UltimateSmoother. Reversible via "Normalization" / "Smoother".

2. 3-window extreme consensus (opt-in, default off). z as the MEDIAN of the z at half, one and double the normalization window — extreme only when short, medium and long agree.

3. Walk-forward out-of-sample reliability. The first N resolved signals TRAIN; every one after is scored OUT-OF-SAMPLE and exported as EXP_OOSEdge / EXP_OOSHit — the trustworthy read.

What is unchanged. The directional range-expansion measure (range z signed by net direction), the regular + hidden divergence engine, the in-band reversal read and the entire triple-barrier zone-matched calibration (uniqueness-weighting, recency decay, Wilson interval, Šidák correction) are byte-for-byte the published version. The new layers only read existing series.

Still research/education only — NOT financial advice; no volume required (built from the bar's own range). Non-repaint: late-confirming pivots, calibration resolves on confirmed bars. Concept credits unchanged (Wyckoff-tradition effort-vs-result; López de Prado triple-barrier/uniqueness; Wilson; Šidák; Ehlers UltimateSmoother).
Информация о релизе
v1.2 — R1 honest-stats standardization. Robust-z and the Wilson confidence half-width now come from the published calibration libraries (ml_robuststats/2, ml_calib/2), byte-identical to the prior local helpers — oscillator, divergence detection, marks and calibration numbers unchanged. Shared calibration engine across the divergence family.

Отказ от ответственности

Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.