OPEN-SOURCE SCRIPT
Atualizado

Adaptive Regime Detector [4-State] [TSL]

223
════════════════════════════════════════════════════════════
SCRIPT TITLE (the "Title" field when publishing):
Adaptive Market Regime Detector [4-State]

SUGGESTED TAGS:
regime, trend, volatility, ATR, marketregime, futures,
efficiencyratio, choppiness, adaptive, context
════════════════════════════════════════════════════════════


DESCRIPTION (paste into the description box):
────────────────────────────────────────────────────────────

Most regime filters answer the wrong question. They tell you a single number — "ADX is 27" — and leave you to guess what that means for the symbol and timeframe in front of you. That threshold was calibrated on one market. Load it somewhere else and it quietly misfires, because volatility and trend distributions are not the same on NQ 1-minute as they are on BTC 4-hour.

This indicator takes a different approach. It does not use a single hard-coded threshold anywhere. Instead, every metric is ranked against its own recent distribution using percentile scoring, so the boundary between "trending" and "ranging" recalibrates to whatever chart you put it on. The same script adapts across symbols and timeframes without manual retuning.


── WHAT IT DOES ──

On each confirmed bar, the script measures two independent axes:

Trend axis — Kaufman Efficiency Ratio (directional travel divided by total path) combined with an ATR-normalized EMA slope. High when price is making clean directional progress, low when it is grinding sideways.

Volatility axis — the percentile rank of ATR combined with the percentile rank of Bollinger Band width. High when ranges are expanding, low when the market is compressed.

Crossing those two axes produces four regimes rather than the usual three:

• TRENDING + VOLATILE — direction and range together. The momentum environment.
• TRENDING + CALM — orderly directional grind, muted volatility.
• VOLATILE CHOP — wide two-sided candles going nowhere.
• QUIET RANGE — low volatility, no direction.

The distinction between a volatile trend and a volatile range is the reason this exists. Most detectors collapse both into one "high volatility" state, but they are opposite trading environments. Splitting them apart is the practically useful part.


── HOW TO READ IT ──

Background shading colors the chart by the active regime. A compact dashboard in the corner shows the live trend score, volatility score, direction, a confidence reading (how decisively the dominant axis clears its threshold), and a one-line note for the current state.


── ANTI-FLICKER ──

A regime only changes after a configurable number of consecutive bars agree (default 3). This trades a few bars of lag for a stable label, so the read does not strobe back and forth in transition zones. All logic runs on confirmed bars; the script does not repaint.


── SETTINGS ──

Percentile lookback — the window each metric is ranked against. Lower it toward 80–100 on the 1-minute, keep it near 120 on the 5-minute and above.
Trend / Volatility percentile thresholds — how far above its own distribution a score must sit to count as trending or volatile. Defaults 60 / 65.
Confirmation bars — agreeing bars required before the label flips. Higher is steadier and slower.
Display — background shading, dashboard, dashboard position, background transparency.
Alerts — fires once per bar close on a confirmed regime change, with the new regime and confidence in the message.

Defaults are tuned for index futures (NQ, ES, MNQ, MES) on intraday charts, but because the engine is adaptive it works on forex, crypto, and stocks without retuning.


── HOW TO USE IT ──

This is a context filter, not a signal generator. It tells you which kind of market you are in so you can apply the tactic that fits — momentum in a volatile trend, pullback entries in a calm trend, mean reversion or standing aside in chop, reduced size in a quiet range. Pair it with your own entry trigger and risk plan. The regime read tells you which tool to reach for, not where to click.


── LIMITATIONS ──

It classifies context; it does not predict direction or generate entries. Transitions are inherently fuzzy and the confirmation buffer means the label arrives a few bars after a regime genuinely shifts — that is deliberate. On a freshly loaded chart with little history, the percentile scores can be jumpy until enough bars accumulate to form a stable distribution.


Open source. The full Pine v6 source is on this page — read it, fork it, adapt it to your own strategy.

This script is an analytical tool published for educational purposes. It does not constitute financial advice and does not guarantee any trading outcome. Trading involves substantial risk of loss.
Notas de Lançamento
════════════════════════════════════════════════════════════
RELEASE NOTES — paste into TradingView's "Publish update" box
Script: Adaptive Regime Detector [4-State] [TSL]
Version: v1.1 — Dashboard readability
════════════════════════════════════════════════════════════


v1.1 — Dashboard readability

Added a new "Dashboard size" input under the Display group with four options: Small, Normal, Large, and Huge. The default is now Large, which keeps the regime state, score readings, and confidence figure legible at any chart zoom. Drop it to Normal if you preferred the previous compact look, or push it to Huge if you're running a 4K monitor.

The dashboard's tactical-hint line — the one-liner that reads "Prime: momentum, ride extensions", "DANGER: stand down", and so on — now renders in accent blue rather than plain white. The hint reads as a verdict for the current regime instead of blending into the rows above it.

No logic changes. Regime classification, the confirmation buffer, alert conditions, and the underlying percentile-scoring engine are identical to v1.0. This is a pure readability update — anyone who built habits around v1.0 outputs can update without re-validating anything.
Notas de Lançamento
════════════════════════════════════════════════════════════
RELEASE NOTES — paste into TradingView's "Publish update" box
Script: Adaptive Regime Detector [4-State] [TSL]
Version: v1.2 — Anchored VWAP
════════════════════════════════════════════════════════════


v1.2 — Anchored VWAP

Added an optional anchored VWAP that auto-anchors itself to a meaningful pivot — and the regime engine decides what counts as meaningful. The most useful anchored VWAP for catching continuation moves is one drawn from the start of the current trend leg, because pullbacks to that line are the textbook continuation entry. The script now places that anchor for you automatically every time a new trend begins.

Three anchor modes are available under the new "Anchored VWAP" input group:

· Trend start (default) — anchors when the regime transitions into TREND or TREND+VOL. Built for continuation traders.
· Regime change — anchors on every state shift. More resets, useful as a per-regime fair-value reference.
· Session open — anchors at the start of each day. Classic session-VWAP behaviour.

Three other options are available in the same group:

· Show ±1σ bands — optional standard deviation envelope around the VWAP (off by default). Useful for spotting overextensions from fair value.
· Dim VWAP outside trending regimes — fades the line in CHOP and QUIET (on by default). Visual cue that continuation logic doesn't apply there.
· Colour and line width — for tuning the line to your chart.

No changes to the regime classification engine. Percentile scoring, the confirmation buffer, the alert behaviour, and the dashboard are all identical to v1.1. The VWAP is purely additive — disable "Show anchored VWAP" under the new group and the indicator looks and behaves exactly as it did before.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.