Volatility Regime Classifier [JOAT]Volatility Regime Classifier
Introduction
The Volatility Regime Classifier is an overlay indicator that continuously classifies the current market environment into one of four distinct volatility regimes — TRENDING , RANGING , VOLATILE , or MIXED — and adapts its visual output accordingly. Rather than simply measuring how much volatility is present, this indicator identifies what type of volatility environment is active, a distinction that is directly relevant to strategy selection.
The classification is built on three independent measures — ATR Z-score, ATR percentile, and EMA directional ratio — each capturing a different dimension of market behavior. Their combination produces a regime map that is both statistically grounded and practically actionable.
---
Core Concepts
1. ATR Z-Score — Detecting Statistically Extreme Volatility
The Z-score measures how far the current ATR deviates from its own historical mean, in units of standard deviation:
atrZ = (atr14 - ta.sma(atr14, lookback)) / ta.stdev(atr14, lookback)
A Z-score above the Volatile Z Threshold (default 2.0) means current volatility is more than two standard deviations above the recent average — a statistically uncommon spike. This is the trigger for the VOLATILE regime, indicating conditions where position sizing, stop distances, and strategy assumptions built around normal ranges may no longer apply.
The Z-score is a mean-reverting measure. An extreme reading does not tell you which direction price will move. It tells you the current volatility environment is atypical relative to recent history.
2. ATR Percentile — Identifying Volatility Compression
The percentile ranks current ATR linearly within its own recent range:
atrPercentile = (atr14 - ta.lowest(atr14, lookback)) / (ta.highest(atr14, lookback) - ta.lowest(atr14, lookback)) * 100
A percentile below the Ranging Percentile threshold (default 35%) means ATR is near its lowest levels of the lookback window — a compression signal. This is the trigger for the RANGING regime, which historically precedes expansion but does not predict its direction or timing. It is a descriptor of the current state, not a forecast.
Using percentile rather than a fixed ATR threshold makes the measure adaptive: it adjusts to the instrument's own volatility character and the current lookback window.
3. EMA Directional Ratio — Testing Movement Quality
Directional quality is measured by the separation between a fast and slow EMA, expressed in ATR units:
directional = math.abs(ema_fast - ema_slow) / atr14 > dirStrength
When the EMA separation exceeds the Directional Strength threshold (default 1.5 ATR units), the market is showing sustained, coherent movement in one direction relative to its current volatility level. This is the trigger for the TRENDING regime.
Expressing EMA separation in ATR units normalizes for volatility: a large EMA gap during a high-volatility period may be less directionally significant than the same gap during a low-volatility period.
4. Regime Classification Logic
The three measures are evaluated in priority order:
VOLATILE — if ATR Z-score exceeds the volatile threshold. Extreme volatility takes precedence over all other conditions.
RANGING — else if ATR percentile is below the ranging threshold. Volatility compression is checked next.
TRENDING — else if the EMA directional ratio is satisfied. Directional movement is confirmed if not in a spike or compression.
MIXED — else. The market does not clearly fit any of the above categories: volatility is average, not directional, and not compressed.
Regime transitions are confirmed on barstate.isconfirmed bars only, preventing labels and state changes from appearing on unfinished candles.
5. Adaptive Bands
Each regime applies a different ATR multiplier to a central EMA band:
VOLATILE: multiplier 3.0 — wide bands reflecting extreme range
TRENDING: multiplier 2.0 — moderate bands supporting trend context
MIXED: multiplier 1.5 — standard bands for undifferentiated conditions
RANGING: multiplier 1.0 — tight bands appropriate for compressed, mean-reverting conditions
upper = ema_center + baseMult * atr14
lower = ema_center - baseMult * atr14
The band envelope therefore scales automatically to the current regime, providing contextually appropriate support and resistance structure without manual adjustment.
6. Smooth Color Transitions
Regime colors are smoothed by applying a 10-period EMA to each RGB channel independently. This prevents abrupt color jumps at regime boundaries and provides a visual blending effect as the market transitions between states. The smoothing period is fixed at 10 bars and is not user-configurable, as it is a presentational feature rather than an analytical one.
7. Regime Transition Labels
A label is plotted at each confirmed regime change, marking the bar where the classification shifted. This creates a visual audit trail of regime history on the chart, allowing traders to review how conditions evolved across the session or swing.
8. Information Table
A compact table in the top-right corner displays the current state of all key measurements:
Current regime classification
ATR value (absolute)
ATR Z-score
ATR percentile
EMA trend direction (bullish/bearish based on fast vs slow EMA)
Band width (upper minus lower)
Directional threshold met (yes/no)
Active band multiplier
---
Features
Four-state regime classification: TRENDING, RANGING, VOLATILE, MIXED
ATR Z-score for statistical volatility spike detection
ATR percentile for volatility compression identification
EMA directional ratio normalized to ATR units
Priority-ordered regime logic with clear precedence rules
Adaptive ATR-based bands that scale multiplier per regime
Smooth RGB-channel EMA color blending at regime transitions
Regime transition labels at every confirmed state change
Per-bar color coding reflecting the active regime
Background tint per regime (high transparency, non-intrusive)
Real-time information table with all underlying metrics
---
Input Parameters
ATR Length (default 14): Period for all ATR calculations. Shorter values make the Z-score and percentile more reactive; longer values smooth them out.
Regime Lookback (default 100): The historical window used for Z-score (mean and standard deviation) and percentile (highest/lowest) calculations. Shorter lookbacks make the regime more sensitive to recent conditions; longer lookbacks require more extreme readings to trigger transitions.
Volatile Z Threshold (default 2.0): ATR Z-score level required to trigger the VOLATILE regime. 2.0 corresponds to a two-standard-deviation event relative to the lookback window.
Ranging Percentile (default 35%): ATR percentile below which the RANGING regime is triggered. Lower values require a tighter compression before classifying as ranging.
Directional Strength (default 1.5): EMA separation threshold in ATR units required for the TRENDING regime. Higher values require a stronger, more sustained directional move.
Fast EMA (default 20): Period for the fast EMA used in directional ratio and the band center.
Slow EMA (default 50): Period for the slow EMA used in directional ratio.
Band EMA (default 50): Period for the central EMA from which adaptive bands project. Can be set independently from the directional EMAs.
---
How to Use
Regime-to-strategy mapping: The four regimes map to four broad strategy postures:
TRENDING: Conditions are directional. Trend-following approaches — momentum entries, trailing stops, breakout continuation — have historically performed better in this state.
RANGING: Volatility is compressed. Mean-reversion approaches — fading extremes, range-bound entries — are more aligned with this environment. Be aware that compression often precedes expansion.
VOLATILE: Volatility is statistically extreme. Reduce position size. Wider-than-usual stops are required to avoid being shaken out by noise. Many strategies based on normal ATR assumptions will malfunction in this state.
MIXED: No strong signal. Conditions do not clearly favor trending, ranging, or risk-off postures. Waiting for a clearer regime or reducing exposure are reasonable responses.
Reading the bands: The adaptive bands are not support/resistance in a traditional sense. They represent a contextually appropriate price envelope for the current regime. In ranging conditions, expect price to interact with the tight bands; in volatile conditions, the wider bands reflect the expanded true range.
Using the table: The information table provides the underlying metric values at a glance. If a regime seems unexpected, check the raw Z-score, percentile, and directional values directly — this helps distinguish borderline cases from clear ones.
Transition labels: Regime transition labels mark where conditions shifted on historical bars. Reviewing these labels on historical data can help calibrate whether the default thresholds suit a particular instrument and timeframe.
---
Limitations
All three underlying measures are based on ATR and EMA — both of which are lagging indicators. Regime classification reflects recently confirmed conditions, not instantaneous market state.
The lookback window is critical to the behavior of both the Z-score and percentile. A short lookback makes the indicator reactive but prone to frequent transitions; a long lookback produces more stable regimes but may lag real condition changes.
The four-state classification is a simplification of a continuous, multidimensional market reality. Real market conditions exist on a spectrum; the regime labels are useful approximations, not rigid categories.
On instruments with low liquidity, thin volume, or irregular trading sessions (certain futures contracts, crypto on illiquid exchanges, small-cap equities), ATR behavior may be distorted by gaps or thin-market artifacts, producing unreliable Z-score and percentile readings.
Regime classification performs best when applied within a single session or consistent trading context. Applying it across major session boundaries (e.g., Asia open to New York close on forex) without adjustment may produce spurious transitions driven by liquidity changes rather than structural market behavior.
This indicator does not predict regime changes. It classifies the current regime after it has formed. The RANGING regime, for example, does not predict that expansion will occur — it describes that compression is currently present.
No indicator, including this one, predicts future price direction or magnitude. Regime classification informs which type of strategy is currently better aligned with conditions — it does not guarantee that any strategy will be profitable.
---
Originality Statement
Many volatility indicators answer the question "how volatile is the market?" — ATR, Bollinger Band width, historical volatility, and similar tools all provide variants of this measurement. This indicator answers a different question: "what type of volatility environment is the market currently in?"
The distinction matters because different volatility types require different responses. A spike in volatility during a strong trend calls for different handling than a spike caused by a news event in a ranging market. Compression before a directional breakout is a different environment than compression within an established range. The MIXED regime acknowledges that not all market conditions are clearly classifiable — a honesty that most binary volatility tools omit.
Three independent measures are combined by design, not convenience:
The Z-score is statistical — it grounds the VOLATILE trigger in the instrument's own distributional history rather than an arbitrary fixed threshold.
The percentile is rank-based and linear — it identifies compression relative to the full range of recent ATR values without being sensitive to individual outliers.
The EMA directional ratio tests movement quality in ATR-normalized units — a common EMA crossover system would classify direction identically regardless of whether price is moving coherently or chopping. Normalizing to ATR removes that ambiguity.
The adaptive band multiplier is a direct mechanical expression of the regime classification — not a cosmetic addition. It means the envelope drawn on the chart is always scaled to the current environment, rather than applying a single fixed multiplier that is simultaneously too tight for volatile conditions and too wide for ranging ones.
---
Disclaimer
This indicator is provided for informational and educational purposes only. It does not constitute financial advice, investment advice, or a recommendation to buy or sell any asset. Regime classification describes current market conditions based on historical data — it does not predict future conditions, price direction, or strategy outcomes. All trading involves risk. You are solely responsible for your own trading decisions.
-Made with passion by officialjackofalltrades
Pine Script® indicator






















