Regime detector
Sorts each bar into one of four volatility and trend regimes; on SPY with defaults only 0 and 1 appear.
Each bar gets one regime ID from two gates: volatility, the ATR divided by the close, and trend strength, the ADX, which measures how strong a move is but not its direction. High volatility means that ATR-to-close ratio is above vol_threshold, and a strong trend means ADX is above trend_threshold. The ID is 0 for low-vol ranging, 1 for low-vol trending, 2 for high-vol ranging and 3 for high-vol trending. Only close, ATR and ADX are read; the high and low inputs are wired in but never used.
How to read it
- The line sits in its own pane below the price and takes whole values from 0 to 3.
- On SPY one-minute bars with defaults it was at 0 for at least half the bars and at 1 for at least 5%; 2 and 3 never appeared in the September 2026 sample.
- A step from 0 to 1 means ADX rose above trend_threshold while ATR over close stayed under vol_threshold.
What it outputs
- Regime ID
- Regime for each bar: 0 low-vol ranging, 1 low-vol trending, 2 high-vol ranging, 3 high-vol trending. Blank while ATR or ADX is warming up.
Settings
- vol_threshold
- ATR over close above this counts as high volatility; raising it makes that rarer. The default 0.015 is far above SPY's peak of about 0.001, so 2 and 3 never show. Near 0.00018, half the bars are high vol. At 0 or below, nearly all are.
- trend_threshold
- ADX above this counts as a strong trend, moving 0 to 1 and 2 to 3. Raising it keeps only the strongest trends. ADX peaked at 71 in the sample and sat above 47 about 5% of the time, so values above 71 never fire. Lowering it counts weak trends.
Pitfalls
- With defaults the high-vol gate never opens on SPY one-minute bars, so the line is really a 0 or 1 trend flag until vol_threshold drops.
- The values are categories, not a scale: a step from 0 to 3 is a jump between unrelated states, not a stronger reading.
- The ATR and ADX inputs use their default 14-bar windows, and the high and low inputs are wired in but never read.