OPEN-SOURCE SCRIPT
Telah dikemas kini

Adaptive Bollinger Bands Calibrated and Regime-Aware

503
# Adaptive Bollinger Bands — Robust, Calibrated & Regime-Aware (BB ARC)

## What this is

Most Bollinger Band tools plot a simple moving average plus or minus two standard deviations and assume price is normally distributed. Real price is not: it has fat tails, it is skewed, and a single spike distorts the width. BB ARC is a full reworking of the Bollinger idea that measures the **actual distribution** of the symbol on your chart, builds statistically honest bands from it, proves how well those bands describe the market in real time, and then decides whether a band touch should be **faded** (range) or **ridden** (trend). Everything is universal: the price source and all optional reference feeds are user-selectable, so it runs on any symbol, any market and any timeframe.

It plots the bands and signals on the price chart and an analytics oscillator (%B or band-z) in a lower pane, with a single dashboard that turns all of it into one read.

## Why these components are combined (mashup rationale)

A raw band only says "price is far from its average." On its own that is ambiguous: in a quiet range a touch of the band mean-reverts, but in a strong trend price "walks the band" and keeps going. Giving the same signal in both situations is the classic Bollinger weakness. BB ARC combines several layers specifically because each one removes a weakness the others cannot, and they feed each other in sequence:

1. **Honest band engine** — replaces the naive standard-deviation width with a choice of robust (median / MAD), asymmetric (separate upside/downside deviation, capturing skew), empirical-quantile (width set so the band actually contains your chosen percentage of bars), or EWMA-volatility estimators, plus a kurtosis-adaptive multiplier that widens the band when tails are fat. This makes the *distance* of a touch statistically meaningful instead of an arbitrary 2-sigma.
2. **Calibration layer** — because the bands now claim to contain a certain fraction of price, the script measures the **realized containment %** on the current symbol, plus skew and kurtosis, so the band proves its own validity instead of asking you to trust a textbook assumption.
3. **Regime filter** (efficiency ratio + ADX + volatility clustering) — decides whether the market is ranging, trending or volatile, and therefore whether the correct response to a band touch is to fade it or ride it. This is what resolves the Bollinger paradox above.
4. **Mean-reversion math** — an Ornstein-Uhlenbeck half-life estimate quantifies how many bars a touch typically takes to revert (and reports "trending" when there is no clean reversion), and band-walk persistence counts how long price has been pinned to a band. Together they tell you whether a reversion is realistically tradable.
5. **Multi-timeframe confluence** — checks %B agreement across four timeframes and draws higher-timeframe band rails on your chart, so a signal is not taken against the larger structure.
6. **Conviction engine** — blends the stretch, regime fit, MTF agreement, half-life quality, calibrated edge, volume thrust and order-flow into a single 0-100 score with hard vetoes, so you get one decision rather than several conflicting indicators.

None of these layers is decorative; remove any one and the others lose context. That interdependence is the reason they are published together rather than as separate scripts.

## What it does, step by step

- Builds a basis (SMA / EMA / rolling VWAP / robust median) and three band tiers using the deviation engine you select.
- Computes **%B** and **bandwidth**, a signed **band-z** (how many multiples beyond the basis, using the correct up or down deviation), realized **containment %**, **skew/kurtosis**, **half-life**, **band-walk** streaks, an empirical **reversion probability** (how often, historically on this symbol, a band touch returned toward the basis within N bars), and a **squeeze** state with an expansion-direction read.
- Classifies the **regime** and auto-selects **Fade** (range reversion) or **Ride** (trend continuation) logic.
- Detects regular **%B divergence** and can draw it as lines connecting the pivots on price.
- Produces a **verdict** (LONG / SHORT / VETO / FLAT) with a conviction score and tier, and fires alerts on bar close.

## How to use it

1. Add it to any chart. The bands appear on price, the %B/band-z analytics in the lower pane, and the dashboard in the corner.
2. Read the **REGIME** and **MODE** rows. In a Range regime the engine looks to **fade** outer-band touches back toward the basis; in a Trend regime it looks to **ride** band-walks in the trend direction.
3. Use the calibration rows as a confidence check: a high containment %, a short half-life and a favourable reversion probability support a fade; "trending" half-life and persistent band-walk support a ride.
4. Treat the **CONVICTION** score and **VETO** as the gate — a high score with no veto is the cleanest setup; a veto explains why a tempting touch is being skipped.
5. Optional: enter a volatility-index symbol and/or a correlated instrument in the feed settings to add a volatility-spike veto and cross-asset confluence. Both are blank (off) by default, so nothing market-specific is assumed.

## What makes it original

- A **multi-engine, statistically honest** band (robust, asymmetric semideviation, empirical quantile, EWMA, fat-tail-adaptive) rather than a single SMA±kσ.
- **Live self-calibration**: the band reports the percentage of bars it actually contained, on the current symbol, so its claim is verifiable.
- An **Ornstein-Uhlenbeck half-life** read that turns "far from the mean" into "expected to revert in about X bars, or not at all."
- An **empirical reversion-probability** statistic built from the chart's own history.
- A **regime-driven fade/ride auto-switch** and a single **conviction score with vetoes**, so the same band touch is interpreted correctly in different market states.

## Settings overview

Grouped as: Core (price source, basis, adaptive length), Band Engine (deviation engine, multipliers, quantile %, EWMA lambda, fat-tail), Regime, Mean-Reversion, Calibration, Squeeze, Signals, MTF, Conviction (weights and minimum), Risk (used for sizing and alert context), Optional Reference Feeds (volatility index, cross-asset — both off by default), and Display (bands, fills, divergence-as-lines toggle, adaptive dashboard, legend, identity label).

## Universal data source

The whole engine runs on a user-selected **price source** (close, hl2, hlc3, ohlc4, or even another indicator's output), and the optional reference feeds are typed in by the user, so the script is not tied to any one instrument or exchange. It also degrades gracefully on instruments without volume.

## A note on the chart used for publishing

The published chart shows only this script. The bottom-centre label prints the script name, the symbol and the timeframe so it is always clear what is plotted. No unrelated drawings or third-party indicators are added.

## Disclaimer

This script is a technical study for educational and informational purposes only. It is not financial, investment or trading advice, and it is not a strategy or a solicitation to buy or sell any instrument. The signals, levels, conviction scores and statistics it displays are derived from past price and volume on your chart and do not guarantee any future result. Markets involve risk; you are solely responsible for your own decisions and risk management. Test thoroughly before relying on any tool.

Nota Keluaran
What's new in this update

Conviction is now proven, not asserted. Every Fade, Ride and Squeeze signal opens a forward sample resolved by a triple-barrier (profit / stop / horizon), uniqueness-weighted and recency-decayed, scored against a regime-matched base rate, with the significance star corrected for multiple testing. Each mode's realised edge now feeds the conviction score (replacing the old raw reversion-probability term), and per-mode Hit% ± Wilson / base / edge is shown in the table. The reversion-probability stat is split by regime, so fading odds are measured only where fading applies.

Honest bands made honest by construction. A new containment controller nudges the band multiplier online so the realised containment % converges on your target; the dashboard reports realised-vs-target, the live multiplier and a calibrated / too-tight / too-wide verdict.
Variance-ratio regime test. A statistical mean-reversion test (ratio < 1 = mean-reverting → Fade; > 1 = trending → Ride) refines the fade-vs-ride decision and gates the half-life, instead of relying on the ADX threshold alone.

Conviction reliability. The score is reliability-checked (Brier + calibration gap), so you can see whether conviction 75 actually beats 50.

Full export bus. The script previously emitted nothing; it now exports 19 generic Data-Window series — EXP_PctB, EXP_BandZ, EXP_Basis, EXP_UpperMain, EXP_LowerMain, EXP_Bandwidth, EXP_BWPercentile, EXP_Regime, EXP_HalfLife, EXP_Containment, EXP_VarRatio, EXP_FadeEdge, EXP_RideEdge, EXP_Conviction, EXP_Dir, EXP_Bias, EXP_Squeeze, EXP_Divergence, EXP_Brier — for cross-script use.

Packaging. Renamed to Adaptive Volatility Bands (universal terms; author names moved into a concept-credits block); settings reorganized into 15 numbered groups; all feature toggles default-on (adaptive length, controller, variance ratio, full table); configurable price and volume sources plus a volume-borrow input for no-volume instruments; NIFTY / NSE:INDIAVIX defaults; basis tinted by Fade/Ride mode; dashboard adaptive to chart background with a KEY block + calibration table.

Educational/informational only — not financial advice. Calibration is in-sample, forward-measured at fixed barriers; the position-size figure is a suggestion, not an order. Validate out-of-sample before relying on the edge numbers.

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.