Regime switching detector
Market regime label from volatility and trend; on the SPY sample it read 1 on every bar, so it told nothing.
Each bar gets a regime number from three tests: whether ATR (the atr input, default basic.ATR) is above atr_threshold, whether trend_slope is above +0.002 or below -0.002, and whether the latest four-bar rise is over 1.5 times the five-bar rise before it (the parabolic test). Checked in this order: a parabolic move with high volatility and slope above +0.002 gives 2; high volatility and slope above +0.002 gives 1; high volatility with slope between -0.002 and +0.002 gives 3; low volatility with slope near zero gives 0; every other bar gives 1.
How to read it
- The line sits in its own pane below the price and takes whole numbers from 0 to 3.
- A flat line at 1 means no other rule fired, not a confirmed uptrend: 1 is also the fallback for every bar the other rules miss.
- 2 marks a parabolic move in high volatility; 3 a choppy high-volatility bar with a flat slope; 0 a quiet bar with a flat slope.
- On the SPY sample (September 2026, one-minute bars) the line sat at 1 on every bar it drew, so the default chart carries no information.
What it outputs
- Regime
- Whole-number regime label from 0 to 3, from volatility, slope and recent acceleration. Blank for the first few bars.
Settings
- window
- Length of the stored close history. It only matters below 10, because the parabolic test needs 10 closes: a window under 10 turns label 2 off. Any value from 10 up gives the same chart, since the test reads only the last 10 closes.
Pitfalls
- On the SPY sample it read 1 on every bar, so labels 0, 2 and 3 never appeared. atr_threshold and trend_slope have no default; wire both before reading any label.
- Label 1 is also the fallback. Low-volatility bars with any real slope, and high-volatility bars in a strong downtrend, both get 1, so a strong fall in high volatility reads the same as a rally.
- The 0.002 and 0.0005 slope cut-offs and the 1.5 acceleration factor are fixed in the code, not parameters. On the SPY sample window changed nothing, since label 2 never appeared.