OPEN-SOURCE SCRIPT

SAO RUBIQ Regime v1.1

328
# 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

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。