Advanced volatility regime detector
Whether recent price moves are unusually small, normal or large against their own recent average (0, 1 or 2).
The detector blends two measures of recent bar size: 60% of the average true range (ATR, the typical high-to-low span including gaps from the prior close) and 40% of the standard deviation of one-bar dollar price changes. Each measure is divided by its own average over the last 2 x window bars, so the reading compares now with recent history rather than a fixed level. The blend is coded 0 below 0.8, 2 above 1.4, and 1 in between.
How to read it
- The line sits in its own pane below the price and steps only between 0, 1 and 2.
- 2 means recent moves ran above 1.4 times their recent average (high); 0 means below 0.8 (low); 1 is normal.
- On SPY at defaults, 0 and 2 each cover at least 5% of bars, so the steps are common rather than rare.
- The line shows the size of moves, not their direction: a step to 2 does not mean price is going up or down.
What it outputs
- Volatility regime (0 to 2)
- Coded volatility state for each bar: 0 low, 1 normal, 2 high, measured against recent average move size. It carries no direction.
Settings
- window
- Length of the standard deviation lookback; the baseline it is compared with spans twice as many bars. Higher smooths the reading and keeps a regime longer after volatility fades; lower reacts within minutes and flips on noise.
- atr_window
- Smoothing length of the average true range, which carries 60% of the blend. Higher gives a steadier ATR and slower reaction; lower tracks the last few bars' ranges closely and steps more often.
Pitfalls
- The baseline is the recent average, so a long spell of high volatility lifts the average and the reading drifts back to 1 while the market stays choppy.
- The code has no symbol-specific logic. It reads the chart's own high, low and close, and the facts were measured on SPY.
- The code calls the std input returns, but it is a standard deviation of dollar price changes, so a $1 move counts the same at any price level.