Regime filter
Labels each bar bull, bear or sideways from three moving averages, and leaves it unmarked when the trend is unclear.
RegimeFilter labels each one-minute bar as a bull regime (1), a bear regime (-1), sideways (0), or no call. It uses three simple moving averages of the close, 50, 200 and 800 bars by default. A bull call needs the averages stacked upward with price above the fast one, the medium average more than 0.1% above the slow one, and the fast average more than 0.05% above the medium one. Bear is the mirror image, and sideways needs the medium and slow averages within 0.08% of each other and recent closes spread by more than 2.5% of price.
How to read it
- Markers sit on the candles the filter classifies; a bar with no marker has no clear regime call.
- A 1 marker means the averages are stacked upward with price above the fast one; a -1 means stacked downward with price below it.
- A 0 marker means sideways, the spread-of-closes test. Read the pitfalls before relying on it.
- Markers come in runs while a regime holds, because the averages move slowly.
What it outputs
- Regime (1 bull, -1 bear, 0 sideways)
- Regime call on each bar: 1 for bull, -1 for bear, 0 for sideways. No marker where the regime is uncertain.
When it fires
Bull (1): averages stacked upward, price above the fast average, and the medium-slow and fast-medium gaps above 0.1% and 0.05%. Bear (-1) is the mirror image. Either marks a trend that has already formed, so it lags turns. Sideways (0) cannot fire at defaults on this sample.
Settings
- fast
- Length in bars of the fast average, and of the window for the sideways spread test. Raising it slows the fast line so calls change less often and need a longer move; lowering it makes calls flip more often.
- med
- Length in bars of the middle average, which sets both trend gaps. Raising it slows the middle line so calls change less often; lowering it lets them change faster.
- slow
- Length in bars of the slow baseline and the longest history needed: no call appears until it has filled. Raising it requires a longer-established trend and delays the first call; lowering it makes calls react faster.
Pitfalls
- Sideways (0) cannot fire on this SPY sample at defaults. It needs the 50-bar spread of closes above 2.5% of price, but the whole month's closes spanned only about 3.3%, which caps that spread near 1.7%.
- The code comment says bull needs low-medium volatility, but the bull and bear checks never read volatility. The 'slope' values are percentage gaps between averages, not the slope of any line.
- Nothing enforces fast < med < slow, so out-of-order settings give meaningless calls. No call appears until the slowest average has filled, 800 bars by default.