OPEN-SOURCE SCRIPT

Consolidation Ranges & Breakout Map [MQLSoftware]

1 533
Consolidation Ranges & Breakout Map reads the market's sideways regime as a measurable object. It detects compression with an authored Range Compression Index, fixes the consolidation box only after enough confirmed evidence, tracks how the box resolves — breakout, measured-move projection reached, false break, or expiry — and reports the measured base rates of those outcomes counted on the chart's own history.

This is a visual analytical tool for chart study. It does not execute trades and does not provide financial advice.

Key Features
  • Consolidation boxes fixed on confirmed evidence only: a candidate must hold the compression threshold for a minimum number of confirmed bars before it becomes a live range — borders never move backwards once fixed
  • Amber forming frame while compression is still building, so you see the candidate before it commits
  • Breakouts by confirmed CLOSE beyond the border plus an ATR buffer — wicks and gaps alone never trigger a breakout
  • Measured-move projections (1× and 1.618× the range height by default) drawn from the broken border — a geometric reference derived from the range's own size
  • Outcome tracking on confirmed bars: ✓ printed when the 1× projection is reached, ✕ false break when price closes back inside within the fakeout window, quiet expiry when the resolution window runs out
  • Range invalidation discipline: a box that "breathes" beyond its edge-update budget or outgrows the maximum width is annulled and excluded from the statistics, so pseudo-ranges never contaminate the base rates
  • Measured base rates in the panel: share of upside breakouts, share that reached the 1× projection, share of false breaks, median bars to 1×, median range length — each with its sample size
  • Higher-timeframe context band (rolling HTF high/low), optional volume-expansion quality gate, four panel modes, five confirmed-bar alerts plus one dynamic JSON alert


Core Concept — what is original here

TradingView has many box-drawing and Darvas-style tools; most fix a rectangle from a simple highest/lowest lookback and leave the interpretation to the reader. This script makes the detector itself measurable and then closes the loop by counting what actually happened. Three specific algorithmic elements:

1. The Range Compression Index (RCI). A 0–100 composite authored for this script: RCI = 100 · (0.40 · ineff + 0.35 · vc + 0.25 · cont), where ineff = 1 − min(ER, 1) is movement inefficiency (the inverse Kaufman efficiency ratio — net displacement over the evaluation window divided by the bar-to-bar path traveled), vc is volatility compression (short ATR against a 4× longer ATR window, rescaled to 0..1), and cont is containment — the share of closes inside the central 90% of the candidate box. Each component measures a different facet of "sideways": no net progress, contracting volatility, clustering closes. A candidate also has to pass a geometry gate — its width may not exceed a configurable multiple of ATR. The sensitivity presets set the RCI threshold (Low 70, Normal 62, High 55).

2. The consolidation → breakout state machine. SEEKING → FORMING → LIVE → BREAK UP / BREAK DOWN → RESOLVED / FALSE BREAK / EXPIRED, with every transition on confirmed bars only. The box is fixed only after the minimum number of confirmed compression bars. A fixed border may be widened by a wick within the edge tolerance a limited number of times — each update on a confirmed bar and counted; beyond the budget the box is invalidated and never enters the statistics. A breakout requires a confirmed close beyond the border plus the ATR buffer; a bar that pierces both borders resolves by its close; a close back inside within the fakeout window is classified as a false break (checked before the projection within the same bar, deliberately conservative). The resolution window defaults to three times the range's own duration, capped at 200 bars.

3. Measured base rates. The panel reports observed frequencies counted on this chart's loaded history: how often ranges broke upward, how often the breakout reached the 1× measured-move projection, how often the break turned out false, the median bars to 1× and the median range length — each with its sample size. Below a minimum sample the panel prints the sample gate instead of a percentage, so small-sample noise is never dressed up as a statistic. Observed frequencies, not assumptions, and no claims attached to them.

Anatomy of the Display
  • Live range box — steel border with a faint fill, header with the range's duration and height in ATR; midline optional
  • Amber dashed frame — a FORMING candidate: compression is building but the box is not yet committed
  • ▲ / ▼ breakout markers on the confirmed breakout bar (Descriptive or Compact style)
  • Dashed projection lines from the broken border with 1× and 1.618× labels at the right edge
  • ✓ 1× printed where the projection is reached, ✕ false break where price closed back inside
  • Translucent higher-timeframe band with the rolling HTF high/low and a timeframe tag
  • Panel (Off / Minimal / Normal / Large): state in plain words (SEEKING / COMPRESSING n/m / RANGE LIVE / BROKE UP / BROKE DOWN / FALSE BREAK), the live Range Compression Index with a five-block meter, range height and duration, position inside the range, and in Large mode the measured base-rate section


Notes on Repainting
  • All state transitions, breakout/outcome markers, statistics counters and alerts fire on confirmed bars only and never move once printed
  • Box borders are fixed on the confirming bar and never move backwards; the only permitted change is a forward widening within the edge tolerance, on a confirmed bar, a limited number of times
  • The live box's right edge, the FORMING candidate frame and the panel's live rows update intrabar — visual context, not signals
  • The higher-timeframe band uses one request.security call with lookahead off and reads the previous confirmed HTF value — no future data anywhere
  • Display inputs only gate drawing; they never change the state machine, the counters or the alerts


Typical Analysis Workflow
  • Watch the panel's Compression row: a rising RCI with an amber forming frame means a candidate is building
  • When RANGE LIVE prints, read the box header — a 40-bar range 1.2 ATR tall is a different regime than an 8-bar pause
  • Treat the breakout marker as a measured event, not an invitation: the base rates tell you how often breakouts on this chart reached the projection versus failed back into the box
  • Use the false-break share as regime context — some markets punish breakout chasing far more often than others, and the panel will say so with a sample size
  • Check the higher-timeframe band: a local range at the edge of the senior range is a different situation than one in the middle of it


Configuration
  • Range Detection — compression sensitivity preset (RCI threshold), evaluation window, minimum confirmed bars to fix a box, maximum width in ATR, containment threshold, edge tolerance and the edge-update budget
  • Breakout — ATR buffer for the confirmed close, fakeout window, both projection multiples, resolution window (auto = 3× range duration), optional volume-expansion gate with its multiple
  • Higher-Timeframe Context — band on/off, HTF (empty = auto: 4× chart timeframe capped at 1W), HTF range length
  • Statistics — base-rate section on/off, minimum sample to display a percentage
  • Visual — panel size and position, marker style (Descriptive / Compact), projections, midline, how many past ranges to keep, and the four identity colors (all inputs; dark-theme defaults)


Markets and Timeframes
Any symbol and timeframe. All thresholds are expressed in ATR and percentiles of the chart's own behavior, so the detector self-calibrates per instrument. On symbols without volume data the volume gate is ignored automatically and the panel says so. On slow timeframes (1D/1W) the sample gate will hide the percentages until enough ranges have resolved — that is the honesty rule, not a defect.

Alerts
Range confirmed · Range breakout up · Range breakout down · False break · 1× projection reached — all evaluated on confirmed bars from the same event flags that draw the markers, plus one dynamic alert() with a JSON payload (event, symbol, timeframe, box borders, break level, height in ATR).

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.