OPEN-SOURCE SCRIPT
SAO RUBIQ Regime v1.1

# SAO · RUBIQ — Regime Visualizer
**by SNP420 · Jarvis Claudos · Finexus s.r.o.**
*Pine Script v6 · Build 2026-05-26*
---
## What is it
A research-grade market regime overlay that classifies every confirmed
bar into one of **five regimes** and paints the chart accordingly.
Born out of a simple insight:
> *"The right algorithm in the wrong phase of the market still fails —
> even when it is 100% correct under ideal conditions."*
This is the central thesis of the **SAO · RUBIQ** project: every
strategy lives or dies inside a specific regime × timeframe cell.
Without active regime perception, every trading system is necessarily
under-performing on the bars it was not designed for. This indicator
makes those cells visible.
## The five regimes
| Regime | Meaning |
| ------------- | -------------------------------------------------------- |
| **BULL_CALM** | Trending up with low realized volatility |
| **BEAR_CALM** | Trending down with low realized volatility |
| **RANGE** | Sideways with narrow Bollinger width |
| **CHOPPY** | Sideways with high noise / many directional flips |
| **STRESS** | Volatility spike — any 2 of {rv, ATR z-score, bar range} |
| *UNCERTAIN* | Fallback — nothing fits cleanly (no box drawn) |
Priority order: **STRESS > BULL > BEAR > RANGE > CHOPPY > UNCERTAIN.**
## How it works
The indicator computes the full RUBIQ v1.1 feature stack on every bar:
- ATR(14), ADX/DI(14), Bollinger(20, 2)
- 20-bar realized volatility, 30-bar directional flips
- HH / HL / LH / LL pivot-swing counts in a 30-bar window
- 500-bar rolling medians for BBwidth, RV, ATR, bar range
- ATR z-score, bar-range ratio, price drift in ATR units
It then applies a calibrated rule set (per-feature thresholds derived
from EUR/USD M30 2024-2025 baseline) and assigns one of the six labels.
A hysteresis smoother (`min_run = 5` bars, configurable) suppresses
flicker — a regime is only committed after enough confirming bars.
## Visualization (FX-Sessions-style)
- **Dashed segment boxes** — one box per confirmed regime run, sized
to that segment's high/low range. Mirrors the FX Market Sessions look.
- **Background tint** — semi-transparent regime color over the active span.
- **Bar color** (off by default) — paints OHLC bars with the regime color.
- **Segment label** — regime name anchored to the top of the box.
- **Info table** (top-right) — current state + live feature values.
- **Stats table** (bottom-right) — N bars and % share per regime across
the visible history.
UNCERTAIN bars deliberately render no box and no tint — keeps the
chart clean and matches the "no session" look of FX Sessions.
## Settings worth knowing
- **Calibrated v1.1 rules** (default on) — ~45% confident coverage on
EUR/USD M30. Turn off for strict v1 (~6% coverage, mostly UNCERTAIN —
useful for research only).
- **Hysteresis min_run** — bars of consistent raw state before commit.
Bigger value = less flicker, more boundary lag.
- **Norm median lookback** (500) — window for the rolling median of
BBwidth / RV / ATR / bar range. Lower it for faster adaptation.
- **Swing / drift window** (30) — pivot-count window and `price_drift_atr`
reference horizon.
- **All six regime colors** — fully overridable.
## Sanity-check expectation (EUR/USD M30, 2 years)
If the calibration baseline holds on your data window, the stats
table should land near:
| State | Share |
| --------- | ------ |
| BULL_CALM | ~12% |
| BEAR_CALM | ~12% |
| RANGE | ~7% |
| CHOPPY | ~10% |
| STRESS | ~3.5% |
| UNCERTAIN | ~55% |
Any major divergence on a fresh window = signal to re-validate
(regime shift, threshold drift, or data-feed alignment).
## Honest limitations — please read
- **Tuned to EUR/USD M30 vol scale.** Features themselves are
TF-agnostic, but the cut points (`rv20_norm < 1.8`, `ADX > 20`,
`price_drift_atr > 1.5`, etc.) were calibrated on M30. On H1, D1,
crypto or equities the regime distribution will be approximate
unless you re-tune.
- **v1.1 direction-mapping is incomplete.** Validation diagonal score
is 1/5 — BEAR_CALM bars in the 2024-2025 baseline have a slight
*positive* forward drift. The labels are statistically informative
(shuffle MC p<0.001) but trade-direction routing needs a v1.2 fix.
**Treat this indicator as a labeled regime overlay for research, not
as a stand-alone trade-direction signal.**
- **Streaming hysteresis ≠ offline two-sided smoothing.** Boundary
detection lags by approximately `min_run - 1` bars in real time.
## Alerts
Five alert conditions ship in:
- Regime → STRESS
- Regime → BULL_CALM
- Regime → BEAR_CALM
- Regime → RANGE
- Regime → CHOPPY
Each fires on transition (state differs from previous bar).
## Credits & attribution
- **Visual style** inspired by *FX Market Sessions* by **boitoki**
(Mozilla Public License 2.0). The segment-box-per-run pattern is
borrowed from that script; all classifier logic and feature math
is original to SAO · RUBIQ.
- **RUBIQ thesis** — *Rubik's-cube model of the market*: the right
algorithm in the wrong market phase still fails. Distilled from
100+ failed variants across the SAO portfolio.
- **Built by** SNP420 · Jarvis Claudos · Finexus s.r.o.
## License
Same as the parent SAO_RUBIQ project. Use freely, modify freely,
attribute when republishing.
---
*"Trh je proměnlivé prostředí. RUBIQ je centrální nervová soustava,
která to řeší pro všechny SAO strategie."*
— SNP420
**by SNP420 · Jarvis Claudos · Finexus s.r.o.**
*Pine Script v6 · Build 2026-05-26*
---
## What is it
A research-grade market regime overlay that classifies every confirmed
bar into one of **five regimes** and paints the chart accordingly.
Born out of a simple insight:
> *"The right algorithm in the wrong phase of the market still fails —
> even when it is 100% correct under ideal conditions."*
This is the central thesis of the **SAO · RUBIQ** project: every
strategy lives or dies inside a specific regime × timeframe cell.
Without active regime perception, every trading system is necessarily
under-performing on the bars it was not designed for. This indicator
makes those cells visible.
## The five regimes
| Regime | Meaning |
| ------------- | -------------------------------------------------------- |
| **BULL_CALM** | Trending up with low realized volatility |
| **BEAR_CALM** | Trending down with low realized volatility |
| **RANGE** | Sideways with narrow Bollinger width |
| **CHOPPY** | Sideways with high noise / many directional flips |
| **STRESS** | Volatility spike — any 2 of {rv, ATR z-score, bar range} |
| *UNCERTAIN* | Fallback — nothing fits cleanly (no box drawn) |
Priority order: **STRESS > BULL > BEAR > RANGE > CHOPPY > UNCERTAIN.**
## How it works
The indicator computes the full RUBIQ v1.1 feature stack on every bar:
- ATR(14), ADX/DI(14), Bollinger(20, 2)
- 20-bar realized volatility, 30-bar directional flips
- HH / HL / LH / LL pivot-swing counts in a 30-bar window
- 500-bar rolling medians for BBwidth, RV, ATR, bar range
- ATR z-score, bar-range ratio, price drift in ATR units
It then applies a calibrated rule set (per-feature thresholds derived
from EUR/USD M30 2024-2025 baseline) and assigns one of the six labels.
A hysteresis smoother (`min_run = 5` bars, configurable) suppresses
flicker — a regime is only committed after enough confirming bars.
## Visualization (FX-Sessions-style)
- **Dashed segment boxes** — one box per confirmed regime run, sized
to that segment's high/low range. Mirrors the FX Market Sessions look.
- **Background tint** — semi-transparent regime color over the active span.
- **Bar color** (off by default) — paints OHLC bars with the regime color.
- **Segment label** — regime name anchored to the top of the box.
- **Info table** (top-right) — current state + live feature values.
- **Stats table** (bottom-right) — N bars and % share per regime across
the visible history.
UNCERTAIN bars deliberately render no box and no tint — keeps the
chart clean and matches the "no session" look of FX Sessions.
## Settings worth knowing
- **Calibrated v1.1 rules** (default on) — ~45% confident coverage on
EUR/USD M30. Turn off for strict v1 (~6% coverage, mostly UNCERTAIN —
useful for research only).
- **Hysteresis min_run** — bars of consistent raw state before commit.
Bigger value = less flicker, more boundary lag.
- **Norm median lookback** (500) — window for the rolling median of
BBwidth / RV / ATR / bar range. Lower it for faster adaptation.
- **Swing / drift window** (30) — pivot-count window and `price_drift_atr`
reference horizon.
- **All six regime colors** — fully overridable.
## Sanity-check expectation (EUR/USD M30, 2 years)
If the calibration baseline holds on your data window, the stats
table should land near:
| State | Share |
| --------- | ------ |
| BULL_CALM | ~12% |
| BEAR_CALM | ~12% |
| RANGE | ~7% |
| CHOPPY | ~10% |
| STRESS | ~3.5% |
| UNCERTAIN | ~55% |
Any major divergence on a fresh window = signal to re-validate
(regime shift, threshold drift, or data-feed alignment).
## Honest limitations — please read
- **Tuned to EUR/USD M30 vol scale.** Features themselves are
TF-agnostic, but the cut points (`rv20_norm < 1.8`, `ADX > 20`,
`price_drift_atr > 1.5`, etc.) were calibrated on M30. On H1, D1,
crypto or equities the regime distribution will be approximate
unless you re-tune.
- **v1.1 direction-mapping is incomplete.** Validation diagonal score
is 1/5 — BEAR_CALM bars in the 2024-2025 baseline have a slight
*positive* forward drift. The labels are statistically informative
(shuffle MC p<0.001) but trade-direction routing needs a v1.2 fix.
**Treat this indicator as a labeled regime overlay for research, not
as a stand-alone trade-direction signal.**
- **Streaming hysteresis ≠ offline two-sided smoothing.** Boundary
detection lags by approximately `min_run - 1` bars in real time.
## Alerts
Five alert conditions ship in:
- Regime → STRESS
- Regime → BULL_CALM
- Regime → BEAR_CALM
- Regime → RANGE
- Regime → CHOPPY
Each fires on transition (state differs from previous bar).
## Credits & attribution
- **Visual style** inspired by *FX Market Sessions* by **boitoki**
(Mozilla Public License 2.0). The segment-box-per-run pattern is
borrowed from that script; all classifier logic and feature math
is original to SAO · RUBIQ.
- **RUBIQ thesis** — *Rubik's-cube model of the market*: the right
algorithm in the wrong market phase still fails. Distilled from
100+ failed variants across the SAO portfolio.
- **Built by** SNP420 · Jarvis Claudos · Finexus s.r.o.
## License
Same as the parent SAO_RUBIQ project. Use freely, modify freely,
attribute when republishing.
---
*"Trh je proměnlivé prostředí. RUBIQ je centrální nervová soustava,
která to řeší pro všechny SAO strategie."*
— SNP420
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
BOOST ME
6 in investing and 5 in traiding
Czechia
6 in investing and 5 in traiding
Czechia
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
BOOST ME
6 in investing and 5 in traiding
Czechia
6 in investing and 5 in traiding
Czechia
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.