OPEN-SOURCE SCRIPT
Cập nhật

Adaptive Regression Channel Fit-Gated & Calibrated

463
Adaptive Regression Channel — Multi-Engine, Fit-Gated & Calibrated

What it is

A regression channel that lets you choose the estimator, measures its own goodness-of-fit, and refuses to be trusted when that fit is poor. Four centerline engines, seven volatility engines for the bands, a kurtosis fat-tail multiplier, an honest √-horizon uncertainty cone, a ride-vs-revert detector, and a past-only calibration tracker that asks whether tagging the band actually precedes reversion on this symbol — measured against an unconditional base rate, in R.

Why these components belong in ONE script (not a stack of indicators)

They are the parts of one estimator, each covering a failure mode of the others:

Centerline engine. OLS is the baseline but lags at the right edge and is fragile to spikes. LOESS fixes the endpoint lag (local-linear, tricube-weighted). Theil-Sen fixes spike fragility (median of pairwise slopes). Kalman removes the window entirely (recursive level + trend). You choose the trade-off.
Adaptive window (Kaufman efficiency ratio). A fixed window is wrong in both trends and chop; the length stretches when price is efficient and contracts when it is noisy, so the channel tracks the live swing.
Volatility engine. The bands are only meaningful if their width reflects the real residual distribution: EWMA (recency), Yang-Zhang (drift-robust OHLC range), GARCH(1,1) (clustering), MAD (spike-resistance), asymmetric semidev (skew), quantile (empirical containment) — plus a kurtosis fat-tail multiplier so the stated containment actually holds.
Fit-quality gate. A channel drawn on a bad fit is noise dressed as structure. The centerline only draws solid and only emits events when it explains at least r2Gate of variance; below that it greys to dashed.
Ride-vs-revert. A band touch is ambiguous. Consecutive closes beyond the band ("walking the band") mark continuation, not reversion — so the channel does not fade a trend that is running.
Calibration. The edges are a hypothesis. Each trusted band tag is resolved forward against an unconditional same-horizon base rate, in R, so you see whether the band adds anything over noise — not a naked win-rate.

The centerline says where the mean is, the volatility engine says how wide the normal range is, the fit gate says whether to believe any of it, ride-vs-revert says fade or follow, and calibration keeps it honest. Remove any layer and the channel loses a check it cannot recover.

How it works (mechanics)

The selected engine fits the centerline in (optionally log) price space, on a window that can be fixed, ER-adaptive, or pivot-anchored to the current segment. Residual dispersion drives the bands through the chosen volatility engine, widened by the fat-tail multiplier. The fit metric is the explained-variance fraction of the residuals; below the gate the channel is shown as untrusted and emits nothing. On a trusted channel, each band tag is queued on bar close and resolved horizon bars later — a win if price moved moveATR·ATR in the reversion direction — and tallied per class (UTAG / LTAG) against the unconditional base rate.

Non-repaint: fits on confirmed closes, pivots confirmed, calibration on bar close. The drawn channel updates live (a rolling regression always does — that is description, not a signal); the calibrated events are confirmed-bar only.

How to use

Read the dashboard: FIT% and TRUSTED / LOW-FIT come first. If the fit is low, treat the channel as description only.
On a trusted channel, a band tag is a reversion hypothesis — the calibration rows tell you whether that class has actually paid on this symbol (Hit% vs Base%, Edge with a 95% star, MFE/MAE in R).
WALK means the band is being ridden (trend) — do not fade it.
The cone is an uncertainty fan (√-horizon growth), not a target.
Everything here is descriptive, probabilistic context — never an instruction.

Use on any market

The Data Source inputs (Close / High / Low) drive the fit, the band tags and the calibration, so the channel runs on any series (standard candles, Heikin-Ashi, etc.) and any market. All thresholds are ATR-relative. Defaults are set for NIFTY index-futures intraday; change the source or lengths for other assets.

Originality

The contribution is the closed loop: a selectable estimator whose fit is measured and gated, bands whose width is chosen from seven rigorous volatility models and fat-tail-corrected, a ride-vs-revert guard, and a per-class forward calibration against an unconditional base rate. Most channels draw a line and a ±σ band and stop; this one tells you whether to believe the line and whether the band has historically meant anything here.

Credits

Least squares & local regression (LOESS) — Gauss / Legendre; W. S. Cleveland
Theil-Sen estimator — H. Theil & P. K. Sen
Recursive level+trend (Kalman) filter — R. E. Kálmán
Efficiency Ratio (adaptive window) — Perry Kaufman
EWMA / RiskMetrics variance — J.P. Morgan
Yang-Zhang OHLC volatility — Dennis Yang & Qiang Zhang
GARCH(1,1) — Engle & Bollerslev

The fit-quality gate, the band-walk ride-vs-revert logic and the forward-calibration framework are the author's original implementation.

Limitations (honest)

The calibration is in-sample, close-to-close at a fixed horizon, with no costs, slippage or stops — a study aid, not a backtest, and not a probability of future results. A rolling regression updates every bar; the drawn channel is descriptive, and only the confirmed-bar tag events are calibrated. Theil-Sen is O(n²) in pairs (capped for speed). Past behaviour does not assure future behaviour.

Disclaimer

Educational / informational study for chart analysis only. NOT financial advice, NOT a strategy, NOT a recommendation. It places no orders and guarantees no outcome. Markets carry risk; do your own research and manage your own risk. Paper-trade before risking real money.
Phát hành các Ghi chú
v2.0 — Frontier bands: quantile-regression centreline + asymmetric bands, Conformal-PID coverage, rough-vol width, regime backbone

QUANTILE (MEDIAN) centreline engine (Koenker-Bassett, via IRLS): an L1 / median regression — the most outlier-robust centre. The same routine draws asymmetric QUANTILE-REGRESSION bands (a new volatility engine) whose upper/lower are conditional-quantile lines fitted straight to the data, so the channel is genuinely asymmetric where the move is skewed.
CONFORMAL-PID band coverage: instead of a fixed ×σ, the band multiplier is set from the recent standardised residuals so the channel actually contains its target % of closes on THIS symbol. Adaptive Conformal Inference (the integral term) plus a proportional term on the recent coverage error (Angelopoulos-Candès-Tibshirani 2023) keeps coverage on target through volatility breaks. Live coverage and the effective multiplier show on the dashboard (cov …→target, k×…).
ROUGH-VOL band width: a fractional power-law kernel (weight ∝ lag^(H−0.5), Gatheral-Jaisson-Rosenbaum) for the residual σ — rougher vol puts more weight on the most recent bars.
REGIME★ backbone (optional): link the source to the Market Regime Classifier's EXP_Regime; a strong trend regime (|state| = 2) then blocks the band tag that would fade it — no upper-band fade in a strong up-regime, no lower-band fade in a strong down-regime. Guarded so a source left at price can't misread as a regime.
Added the MPL-2.0 licence header. New exports: EXP_Coverage, EXP_BandMult. All prior engines (OLS/LOESS/Theil-Sen/Kalman, 7 vol engines), the fit-quality gate, ride-vs-revert, the past-only calibration tracker, the cone, theme and non-repaint behaviour are unchanged; defaults reproduce v1 shape with calibration added.

Descriptive regression channel; conformal coverage and forward stats are in-sample/on-symbol, not investment advice.

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.