Market state machine
Joins the volatility, trend and momentum regimes into one state code for each bar.
It takes three regime indicators as inputs: volatility (0 low, 1 normal, 2 high), trend (-1 down, 0 ranging, 1 up) and momentum (-1 oversold, 0 neutral, 1 overbought). Each bar it passes the three codes through unchanged and adds a state ID that packs them into one number: volatility times 100, plus (trend + 1) times 10, plus (momentum + 1). It calculates no regime of its own and has no parameters.
How to read it
- Volatility, trend and momentum are small whole codes, so read the steps between them, not the size of the line.
- The state ID reads as three digits: hundreds for volatility, tens for trend + 1 and units for momentum + 1. 210 means high volatility, ranging trend and oversold momentum.
- The ID runs from 0 (low volatility, downtrend, oversold) to 222 (high volatility, uptrend, overbought), with one value per combination.
What it outputs
- Volatility regime
- Volatility code passed through unchanged from the volatility regime input: 0 low, 1 normal, 2 high.
- Trend regime
- Trend code passed through unchanged from the trend regime input: -1 downtrend, 0 ranging, 1 uptrend.
- Momentum regime
- Momentum code passed through unchanged from the momentum regime input: -1 oversold, 0 neutral, 1 overbought.
- State ID
- One number for the whole state: volatility x100 + (trend + 1) x10 + (momentum + 1). Runs 0 to 222, one value per combination.
Pitfalls
- It only repackages its inputs. Its meaning is entirely the three regime indicators wired into it; with raw price as input the codes just copy the price and say nothing.
- Any input still warming up blanks all four outputs for that bar, and the momentum regime's default 1,500-bar RSI window means about 25 hours of one-minute bars before the state first appears.
- Compare state IDs for equality, not size: 201 is not stronger than 200, it is a different combination of the three regimes.