Range Breakout Verdict Engine [PhenLabs]

📊 Range Breakout Verdict Engine [PhenLabs]
Version: PineScript™ v6
📌 Description
Most range tools draw a box and mark the first close outside it as a breakout. When price slips back inside a few bars later, the label is either left behind as a false signal or quietly rewritten as a “deviation”. Either way you learn the answer only after the move is over.
The Range Breakout Verdict Engine treats every breakout as a question that needs evidence. When a confirmed close leaves an auto-detected range, the breakout goes under test. Each closed bar after it adds evidence for or against acceptance. The engine stops and gives one verdict, ACCEPTED (continuation) or DEVIATION (failed break), as soon as the evidence is strong enough for the error rates you chose. If the evidence never gets there, the test ends as SKIP.
The evidence comes from your own chart. The engine follows every past breakout to a clear outcome and learns how accepted breakouts and failed breakouts tend to behave in the bars right after the break. A verdict is a new event on a closed bar. It is never repainted or relabelled.
🚀 Points of Innovation
🔧 Core Components
🔥 Key Features
🎨 Visualization
📖 Usage Guidelines
Range Detection
Sequential Test
Learning Rules (enable Custom Learning Rules to edit)
Visuals
✅ Best Use Cases
⚠️ Limitations
💡 What Makes This Unique
⚙️ Under the Hood
🔬 How It Works
Version: PineScript™ v6
📌 Description
Most range tools draw a box and mark the first close outside it as a breakout. When price slips back inside a few bars later, the label is either left behind as a false signal or quietly rewritten as a “deviation”. Either way you learn the answer only after the move is over.
The Range Breakout Verdict Engine treats every breakout as a question that needs evidence. When a confirmed close leaves an auto-detected range, the breakout goes under test. Each closed bar after it adds evidence for or against acceptance. The engine stops and gives one verdict, ACCEPTED (continuation) or DEVIATION (failed break), as soon as the evidence is strong enough for the error rates you chose. If the evidence never gets there, the test ends as SKIP.
The evidence comes from your own chart. The engine follows every past breakout to a clear outcome and learns how accepted breakouts and failed breakouts tend to behave in the bars right after the break. A verdict is a new event on a closed bar. It is never repainted or relabelled.
🚀 Points of Innovation
- Wald sequential probability ratio test (SPRT) applied to range breakouts: the verdict arrives on a data-dependent bar instead of after a fixed number of confirmation candles
- You set the tolerated false-accept and false-reject rates (α and β) directly, instead of tuning an abstract sensitivity number
- Likelihoods are learned from this chart’s own resolved breakouts and counted only after each outcome is known, so there is no lookahead
- A TESTING state replaces the usual relabel-on-failure behaviour: the provisional phase is shown in the dashboard and the verdict is a single permanent event
- An early verdict record on the chart scores only verdicts issued before the outcome bar, so you can see how the tool actually performs on the symbol and timeframe you are trading
- Automatic range detection by compression ratio: no manual anchors and no clicking points on the chart
🔧 Core Components
- Compression range detector: arms a range when the high-low height of the last N closed bars is at most a set fraction of the 4N-bar context height
- Breakout test: the first confirmed close outside the armed range opens a test in that direction
- Evidence accumulator: each closed bar’s distance beyond the broken boundary, measured in range heights, is binned and converted into a log-likelihood ratio
- Outcome labeller: follows every breakout until a close reaches the acceptance yardstick (1.0× range height beyond) or returns past the failure depth (0.25× range height inside), then adds the breakout’s observations to the matching class
- Verdict gate: ACCEPTED at the upper Wald bound, DEVIATION at the lower bound, SKIP if neither is reached within the maximum test bars
🔥 Key Features
- Decision-ready signals: an accepted up-break or a rejected down-break is bullish; an accepted down-break or a rejected up-break is bearish
- Three error-rate presets (5%, 10%, 20%) via one dropdown
- LEARNING gate: no verdicts until the chart has enough resolved accepted and failed breakouts (5 each by default)
- Chart accept rate: the share of breakouts on this chart that went on to be accepted, shown as context for every verdict
- 14 inputs with progressive disclosure: the learning rules stay greyed out until you enable Custom Learning Rules
- Theme-adaptive dashboard that reads on dark and light charts, with a Table Size setting
- Bullish, bearish and breakout-under-test alerts, plus Pine Screener columns
🎨 Visualization
- Range box: a faint dashed box while the range is armed. It turns solid in the verdict colour when a verdict is issued and stays neutral after a SKIP or LEARNING test. Only the last 4 boxes are kept
- Acceptance yardstick: a short dotted line, 1.0× range height beyond the broken boundary, shown only while a breakout is being tracked. It marks the distance used to label acceptance
- Verdict label: a small ACCEPTED ▲ / DEVIATION ▼ label placed clear of the candle, never on top of it
- Dashboard: state, evidence meter between the two bounds, error rates, learned trials, chart accept rate, early verdict record, last verdict and data mode
📖 Usage Guidelines
Range Detection
- Range Length — Default: 20 — Range: 8-100 — Bars in the candidate range window. Shorter values find more, smaller ranges
- Max Compression — Default: 0.50 — Range: 0.20-0.90 — Maximum ratio of range height to the 4× longer context height. Lower values accept only tight consolidations
Sequential Test
- Error Rates — Default: Balanced (α = β = 10%) — Options: Conservative 5%, Balanced 10%, Aggressive 20% — Lower rates need more evidence, so verdicts arrive later and more tests end as SKIP
- Max Test Bars — Default: 8 — Range: 2-30 — Closed bars after the breakout bar that the test may use before it ends as SKIP
Learning Rules (enable Custom Learning Rules to edit)
- Acceptance Yardstick — Default: 1.0 — Range: 0.3-3.0 — Distance beyond the boundary, in range heights, that labels a past breakout ACCEPTED
- Failure Depth — Default: 0.25 — Range: 0.05-1.0 — Distance back inside the range that labels a past breakout FAILED
- Outcome Horizon — Default: 30 — Range: 5-200 — Breakouts that resolve neither way within this many bars are left out of learning
- Min Trials per Class — Default: 5 — Range: 2-50 — Resolved accepted and failed breakouts needed before verdicts start
Visuals
- Show Range Boxes — Default: on — Toggles range boxes and the yardstick line
- Bullish / Bearish colours — Default: teal / coral — Verdict colours
- Show Dashboard and Table Size — Default: on / Small — Dashboard visibility and scale
✅ Best Use Cases
- Range and consolidation traders deciding whether to join a breakout or fade it back into the range
- Wyckoff spring / upthrust and AMD-style manipulation reads, where the question is whether the break is real
- Opening-range and overnight-range breakouts on index futures, gold and crypto
- Pine Screener scans for symbols with a fresh verdict or a breakout currently under test
⚠️ Limitations
- Wald’s error bounds assume independent observations. Consecutive closes are correlated, so realised error rates can be higher than the α and β you select. The early verdict record shows what actually happened on your chart; trust it over the nominal rates
- Verdicts need learning history. A chart with few resolved breakouts stays in LEARNING, so use enough history or a lower timeframe
- Evidence is pooled across test bars and is based on closing prices only; wicks and volume are not used
- Only one breakout is tracked at a time. While a breakout is being followed to its outcome, no new range is armed
- Statistics are specific to the symbol, timeframe and settings. Changing any of them restarts learning
💡 What Makes This Unique
- Evidence-timed verdicts: the tool waits exactly as long as the evidence needs, no fixed confirmation candle count
- No relabelling: the provisional phase is explicit, so historical signals on the chart are the signals you would have seen live
- Measured, not named: the only percentages shown are counts of real outcomes on your chart
⚙️ Under the Hood
- Sequential probability ratio test: each closed test bar adds ln P(bin | accepted) − ln P(bin | failed) to a running total. The test stops at Wald’s bounds A = ln((1 − β) / α) and B = ln(β / (1 − α)), so the stopping rule follows directly from the error rates you pick
- Chart-learned likelihood histograms: two 6-bin integer arrays store how often accepted and failed breakouts produced each close distance (in range heights). They use Laplace smoothing and are updated only when a breakout’s outcome resolves, which keeps the current test free of future information
- Closed-bar state machine: scanning → range armed → testing → outcome tracking. Every transition sits behind barstate.isconfirmed, the range uses the previous N bars only, and no request.* call or lookahead is involved
- Object budget: explicit max_boxes_count, max_lines_count and max_labels_count, with the script deleting its own oldest boxes and labels rather than relying on garbage collection
- Data mode / plan note: OHLC only. Every TradingView plan gets the full feature set, and the dashboard’s Data mode row shows “OHLC · all plans”
- Screener & alerts: the first four plots, Verdict Signal (+1 / −1 / 0), Evidence LLR, State (0 / 1 / 2) and Chart Accept Rate %, are exposed to the Pine Screener and the Data Window. Filter on Verdict Signal = 1 or −1 for fresh verdicts, or State = 2 for breakouts under test. Alert conditions: RBVE Bullish Verdict, RBVE Bearish Verdict, RBVE Breakout Under Test
🔬 How It Works
- Range arming: on each closed bar the engine compares the previous N-bar height with the previous 4N-bar height. When the ratio is at or below Max Compression and the close is inside, the range is frozen and drawn
- Breakout: the first close above the range high or below the range low opens a test, and the breakout bar is the first observation
- Evidence: each test bar’s close distance beyond the boundary (negative when back inside) is binned and its log-likelihood ratio is added. The dashboard meter shows where the total sits between the two bounds
- Verdict: crossing the upper bound gives ACCEPTED, crossing the lower bound gives DEVIATION, and reaching Max Test Bars first gives SKIP. One verdict per breakout
- Learning: the breakout is followed until it reaches the yardstick (accepted), returns past the failure depth (failed), or times out (discarded). Resolved observations update the histograms used by every later test
💡 Note:
Start on a liquid symbol with plenty of history, such as BTCUSDT, ETHUSDT, ES or NQ futures, or XAUUSD on 15m to 4h, and let the dashboard leave LEARNING before acting on verdicts. Check the early verdict record against the chart accept rate: the verdict is only worth following if its record is clearly better than the base rate on your market. You can move the dashboard to the chart’s bottom panel from the script’s More menu for a clutter-free chart. This tool is an analytical aid for studying breakout behaviour, not financial advice.
TradingView Charting w/ Crypto Systems: phenlabs.com
Join our growing community: discord.gg/phen
All content provided by PhenLabs is for informational & educational purposes only. Past performance does not guarantee future results.
Join our growing community: discord.gg/phen
All content provided by PhenLabs is for informational & educational purposes only. Past performance does not guarantee future results.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
TradingView Charting w/ Crypto Systems: phenlabs.com
Join our growing community: discord.gg/phen
All content provided by PhenLabs is for informational & educational purposes only. Past performance does not guarantee future results.
Join our growing community: discord.gg/phen
All content provided by PhenLabs is for informational & educational purposes only. Past performance does not guarantee future results.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.