OPEN-SOURCE SCRIPT

Volatility Regime Classifier [AFD]

176
cuplikan

**What it does**
It answers one question: *is this symbol moving more, or less, than it usually does?*

It measures how far this symbol's own bars have been travelling, ranks that against its recent history, and states the answer as a percentile from 0 to 100 plus a named tier — **QUIET**, **NORMAL**, **ELEVATED** or **EXTREME**. Alongside it you get how the recent stretch compares with the longer one, whether the reading is rising or falling, and a plain-English line saying what that amounts to.

Everything comes from the chart you have open. No VIX, no options data, no implied volatility, no other symbol, and no `request.*()` call of any kind — so it behaves the same on a currency pair, a small-cap, a future or a crypto chart, none of which have an index volatility proxy to borrow.

**How it works**
Realized volatility is measured over three rolling windows — short, mid and long — and one **Sensitivity** setting picks them: Fast 5/15/30, Normal 10/30/60, Slow 20/60/120. Fast is the default.

Four estimators, and this choice matters more than any other setting:

cuplikan
- **Parkinson** (default) — reads the bar's high-low range.

cuplikan
- **Garman-Klass** — reads the range and the open-to-close move.

cuplikan
- **Close-to-close** — reads the dispersion of returns.

cuplikan
- **ATR** — a plain N-bar average of true range. **Not Wilder's smoothing**, so it will
not match TradingView's built-in ATR at the same length. Deliberate, not a bug.

Parkinson is the default because of a specific failure of the close-to-close default it replaced. Close-to-close measures how *scattered* returns are; a chart reader measures how *far* price went. A clean one-way slide has every return pointing the same way, so its dispersion is genuinely low — and a choppy bounce covering the same ground scores higher than the slide did. Range-based estimators read what the eye reads.

The short-window reading is ranked against the last **400 bars** to give the percentile, and the tier follows from that rank with a **band around each boundary**, so a reading parked on a threshold does not flip back and forth on sampling noise. The panel tells you when the band is holding a tier back.

There is a second route into EXTREME, and it exists because a percentile is self-normalising: roughly a tenth of all bars sit in the top tier however quiet the year has actually been. So a bar is also called EXTREME when the short window reaches a set multiple of the long one, whatever its rank. The multiple differs per estimator, because the four do not put that ratio on the same scale.

On intraday charts the **session-gap return is excluded**. It spans a close and the next open, so it is not a return over one bar of trading, and leaving it in made every session open read as a volatility event that never happened. It is dropped, not zeroed.

**How to use it**
Add it and read the dashboard. It starts compact at four rows; switch **Compact dashboard** off for the full nine, which name every window, bound and setting actually in force rather than the defaults. Hover the marker at the end of the line for a glossary of every number, also built from your current settings.

- **The percentile line** in the lower pane, tier zones shaded behind it.

- **Price-chart markers** — the bar column painted when a tier you have chosen is reached, or a box spanning the whole episode. EXTREME is marked by default; QUIET, NORMAL, ELEVATED and RISING are all available, and a marked tier always beats RISING so an overlapping bar's colour is never an accident of ordering.

- **The market context box** on the price chart, at the corner you pick or off. A headline names the character of the tape — `RANGE EXPANDING`, `RANGE COMPRESSING`, `WIDE AND HOLDING` and eight others — over a line naming what to re-check, a line stating what the short-to-long ratio amounts to in words, and a standing line reading **`Size only - this says nothing about direction.`**

That last line has no off switch, and the vocabulary above it never uses the words "up or "down". `EXPANDING` is equally what a hard rally and a hard sell-off look like.

**Three alerts**, all evaluated on confirmed bars only: the regime tier changed, the short-vs-baseline state changed, and the EXTREME tier was entered.

**Repainting**
The script reads nothing but the current chart's own bars. There are no `request.*()` calls, no higher-timeframe data and no `barmerge.lookahead_on` anywhere in it, so there is no future data for it to borrow. Once a bar closes, its reading is settled and does not change afterwards.

The bar still forming is the ordinary exception, and it is worth being explicit about: its high, low and close are still moving, so the reading on it moves too, and the tier on the live bar can change before the bar is done. The three alert conditions are gated to confirmed bars for that reason. Drawn elements — the panel, the context box, the episode box — are drawn at the last bar and update with it.

**Why it is original**
It is built for the **Pine Screener**, which is unusual in this category. The first ten plots are the contract — percentile, tier code, ratio, short-vs-baseline code, acceleration tier, regime-changed flag, the two raw RV levels, the percentile's sample count, and a flag saying whether the outputs are fully defined — so you can rank or filter a whole watchlist by volatility regime instead of reading one chart at a time. Zero `request.*()` calls, and the warmup is sized to fit the Screener's 500-bar window.

The other difference is that **the regime is a number, not a colour.** The visual layer is drawn *from* the percentile and never replaces it; every tinted panel row still states its value in words, and the whole visual layer switches off without a single reported number changing.

**Limitations**
- **It says nothing about direction, and it is not a signal.** No entries, no exits, no targets, no probability, win-rate or expectancy language anywhere in the script. It describes what has already happened on the chart in front of you.

- **It needs history.** At the default Fast preset the percentile is undefined until bar 404 and shows blank until then. The size-based EXTREME route is defined from bar 30, so **a bar can legitimately show an EXTREME tier beside a blank percentile row** — the panel says which is which, and the `Outputs fully defined` plot flags it.

- **A percentile is relative to this symbol's own recent history.** QUIET on one instrument and QUIET on another are not the same absolute amount of movement. The panel carries the absolute RV level next to the rank for exactly this reason.

- **ATR here is a simple average, not Wilder's**, as above.

**Licence:** Mozilla Public License 2.0.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.