Volatility Regime Bands from Percentile-Ranked ATR
Volatility regimes shift. A trader who sizes positions or adjusts order placement strategies using volatility metrics benefits from knowing whether current price movement is quiet, extreme, or average relative to recent history. The Volatility Regime Bands indicator uses the Average True Range (ATR) [1] and percentile-rank methodology to place current volatility in context and display that context as a three-band envelope. Upper and lower bands mark the extremes of the lookback period's volatility, while a median band shows the centre. Background shading flags whether volatility is elevated, depressed, or neutral, allowing traders to identify regime transitions without subjective thresholds.
//@version=6
indicator("Volatility Regime Bands (Percentile ATR)", overlay=false)
// Inputs
atrLength = input.int(14, "ATR Length", minval=1)
lookback = input.int(50, "Lookback Period", minval=2)
upperThreshold = input.float(80, "Upper Threshold (%)", minval=1, maxval=99)
lowerThreshold = input.float(20, "Lower Threshold (%)", minval=1, maxval=99)
// Calculate true range and ATR
tr = math.max(high - low, math.max(math.abs(high - close[1]), math.abs(low - close[1])))
atr = ta.sma(tr, atrLength)
// Calculate percentile rank of current ATR (0-100 scale)
atrPercentRank = ta.percentrank(atr, lookback) * 100
// Define volatility regime bands
upperBand = ta.highest(atr, lookback) // Highest ATR in lookback period
medianBand = ta.sma(atr, lookback) // Average ATR
lowerBand = ta.lowest(atr, lookback) // Lowest ATR in lookback period
// Plot bands
plot(upperBand, "Upper Band", color.new(color.red, 0), linewidth=2)
plot(medianBand, "Median Band", color.new(color.orange, 50), linewidth=1)
plot(lowerBand, "Lower Band", color.new(color.green, 0), linewidth=2)
plot(atr, "Current ATR", color.new(color.blue, 40))
// Regime background shading
regimeColor = atrPercentRank > upperThreshold ? color.new(color.red, 85) : atrPercentRank < lowerThreshold ? color.new(color.green, 85) : color.new(color.gray, 90)
bgcolor(regimeColor)
How the code works
The indicator begins by computing true range, which measures the largest distance between the high, low, and prior close. ATR is then calculated as the simple moving average of true range over a user-set period, defaulting to 14 bars. [1]
The percentile rank of the current ATR is determined using Pine's ta.percentrank() function, which compares the current ATR value against all ATR values in the lookback window (default 50 bars) and returns a rank from 0 to 100. An ATR at the 80th percentile means volatility is higher than 80 per cent of the values over the past 50 bars.
Three bands form the volatility regime envelope. The upper band plots the highest ATR observed in the lookback period, marking the ceiling of recent volatility. The lower band plots the lowest ATR, marking the floor. The median band is the simple moving average of ATR, representing the centre of the regime. These bands are descriptive only; they have no predictive power and do not forecast future volatility.
The background shading compares the current ATR's percentile rank against user-defined thresholds. When the rank exceeds the upper threshold (default 80 per cent), the background turns red, flagging elevated volatility or an expansion regime. When it falls below the lower threshold (default 20 per cent), the background turns green, flagging depressed volatility or a contraction regime. A gray background indicates a neutral state.
Reading it on a chart
Traders typically monitor the bands and background colour for regime signals. When ATR (blue line) pushes above the upper band and the background flushes red, volatility has reached or exceeded recent highs. This can signal that price is entering a period of increased dispersion or range. Conversely, when ATR falls below the lower band and the background turns green, volatility has compressed below its recent norm, which may indicate consolidation or setup for a volatility expansion.
The median band serves as a quick visual anchor for the regime centre. If ATR is hovering near the median, volatility is ordinary relative to the lookback window. Trending ATR toward the upper band signals rising volatility; trending toward the lower band signals falling volatility.
The three-band design permits traders to set conditional alerts or rules. An alert can trigger when ATR crosses the median band upward, signalling entry into a rising volatility regime, or when it breaks below the lower band, hinting at compression that may precede expansion.
Limitations
The indicator relies on historical extremes to define bands. In a market trending into a new volatility regime, the bands will lag. A sharp volatility spike pushes ATR above the upper band in a single bar; the upper band itself will not rise until that spike enters the lookback window and displaces an older, lower value. This delay is inherent to any lookback-window method and cannot be eliminated without introducing lookahead.
Percentile rank is sensitive to the lookback period. A 50-bar window captures recent shifts but may miss structural regime changes. A longer window smooths transitions but becomes less responsive to current volatility swings. The choice involves a trade-off with no universally optimal value.
ATR does not distinguish direction. Two instruments with identical ATR might have opposite trends. Rising ATR during an uptrend and falling ATR during a downtrend tell different stories, but ATR alone cannot separate them. Traders pairing this indicator with directional momentum or trend filters avoid regime signal noise.
The background shading thresholds (default 80th and 20th percentiles) are editable but arbitrary. No empirical study proves these percentiles are optimal entry or exit signals for any instrument or timeframe. Threshold adjustments substantially alter the frequency and timing of regime flags.
Key definitions
Average True Range (ATR): A volatility measure calculated as the simple moving average of true range over a specified period; higher values indicate greater price dispersion and lower values indicate tighter price action. [1]
True Range: The greatest of three values: the current high minus the current low, the absolute value of the current high minus the prior close, or the absolute value of the current low minus the prior close.
Percentile Rank: A statistical measure indicating the percentage of values in a dataset that are equal to or below the current value; a rank of 80 per cent means the current value exceeds 80 per cent of historical observations.
Volatility Regime: A market state characterised by a particular range of price dispersion; regimes shift between compression (low volatility) and expansion (high volatility).
Lookback Period: The number of historical bars used to calculate statistical measures such as percentile rank, highest value, or lowest value.
References
- Wilder, J. Welles. New Concepts in Technical Trading Systems. Trend Research (1978).
- Investopedia. "Average True Range (ATR): How to Calculate and Use It." Investopedia. Https://www.investopedia.com/terms/a/atr.asp
- CME Group. "E-mini S&P 500 Futures Contract Specifications." CME Group. Https://www.cmegroup.com/markets/equities/sp-500/e-mini-sp-500.contractSpecs.html
- Taleb, Nassim N. Fooled by Randomness. Random House (2001).
- Murphy, John J. Technical Analysis of the Financial Markets. New York Institute of Finance (1999).
Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.
Last reviewed by the PropLedger research pipeline: 2026-09-13. Educational research on historical data, not financial advice.
Keep reading
Measured Move Projector
Free open-source Pine Script indicator: measured move projector from the last completed swing. Full code and a plain-English walkthrough.
Spread Tracker: Related Futures Contracts
Free open-source Pine Script indicator: spread tracker between two related futures contracts. Full code and a plain-English walkthrough.
Seasonality Heat Strip
Free open-source Pine Script indicator: seasonality heat strip: month-of-year average returns. Full code and a plain-English walkthrough.