Regime classifier
Tags each minute with a regime code: trend direction crossed with high or low volatility.
The classifier names the current market regime with one code from 1 to 6. It fits a straight line through the last trend_window closes: a good fit (R-squared above 0.6) is a trend, rising if the line climbs faster than 0.05% a bar and falling otherwise, and a poor fit is a range. Volatility is the average true range over the last atr_window bars, as a share of the average close, compared with vol_threshold.
How to read it
- The line sits in its own pane below the price and only takes whole values from 1 to 6.
- Odd codes are high volatility and even codes low. 1 and 2 are up, 3 and 4 down, 5 and 6 range.
- In the one-month SPY sample every reading fell between 4 and 6, and 6 made up at least half of them.
- Read a run of the same code as one regime. A single-bar flip is noise, not a new regime.
What it outputs
- Regime code
- Regime code from 1 to 6: trend (up, down or range) crossed with high or low volatility. Blank until the window fills.
Settings
- atr_window
- Bars in the average true range that measures volatility. Longer smooths out one-bar spikes and steadies the volatility half of the code. Shorter reacts within minutes. Below 2 it never outputs, because ATR needs at least one true range.
- trend_window
- Bars in the straight-line fit and the average price. Longer waits for a longer, smoother run before a trend shows. Shorter reacts within minutes but reads noise as trend. The first trend_window minus one bars stay blank, so 49 at the default 50.
- vol_threshold
- Volatility cut-off as a share of price: above it is high volatility (odd codes), below it low (even codes). Raising it makes high volatility rarer. Lowering it flags more bars. Negative values flag every bar as high volatility.
Pitfalls
- A gentle smooth rise is labelled a downtrend. Any fit that climbs less than 0.05% a bar, about 0.4 dollars a minute on SPY near 765, falls through to the downtrend codes 3 or 4.
- No uptrend appeared in the one-month SPY sample at defaults, so the up codes 1 and 2 are rare. A steep, steady climb is needed to earn them.
- Volume only has to be present. It never changes the code, and a bar with no volume is blank.