OPEN-SOURCE SCRIPT

Regime Filter V4C

252
Regime Filter V4 — Macro regime detection with rule-based LONG/SHORT filter


OVERVIEW

Regime Filter V4 is a macro regime detection indicator designed to filter trading signals on daily timeframe. It classifies the market into 3 regimes (UP / DN / RG), splits each regime into Early / Late phases, considers BTC macro context (Bull / Bear), and applies 4 explicit rules to decide whether LONG or SHORT trades are authorized.

This is the public version of the filter I use to systematically gate signals on my own multi-method trading bot. It has been validated across 8 years of BTC daily data (2018–2026) with documented performance (cumsum +3,051R, Sharpe 0.455, Max DD reduced 42% vs no-filter baseline).


HOW IT WORKS — THE 4 LAYERS

Layer 1 — Regime detection
Classify each daily bar into UP / DN / RG using EMA20 slope over a 7-day lookback:
- UP : EMA20 > EMA20[7] × (1 + 0.1%)
- DN : EMA20 < EMA20[7] × (1 - 0.1%)
- RG : in between (range / consolidation)

Layer 2 — Phase Early / Late
Count consecutive days in the same regime (streak):
- Early : streak ≤ 7 days (fresh trend)
- Late : streak > 7 days (mature trend)

Layer 3 — Macro context
Compare EMA50 vs EMA200 on the asset itself:
- Bull macro : EMA50 > EMA200
- Bear macro : EMA50 < EMA200

Layer 4 — The 4 rules (R1–R4)
- R1 : Regime UP → SHORT always blocked
- R2 : Regime UP → LONG: Early always OK; Late OK only if Bull macro
- R3 : Regime DN → SHORT: OK only if ADX(14) > 30
- R4 : Regime RG → LONG: OK only if Bear macro AND RSI(14) < 30 (contrarian)


VISUAL ELEMENTS

Background colors:
- Green = UP regime (lighter = Early, darker = Late)
- Red = DN regime (lighter = Early, darker = Late)
- Yellow / grey = RG regime (range)

Plotted lines:
- Blue (EMA20) — Regime EMA
- Orange (EMA50) — Macro fast
- Red (EMA200) — Macro slow

Transition markers:
- Red triangle down = UP → DN transition
- Green triangle up = DN → UP transition
- Grey diamond = transition into RG

Dashboard (top-right):
Live display of current regime, phase, streak, macro context, ADX, RSI, active rule, LONG / SHORT status, and approximate activity rate.


HOW TO USE

1. Apply on daily timeframe of any liquid asset (works best on BTC, but tested cross-asset on ETH and SOL).
2. Read the dashboard to know the current regime and which trades are authorized.
3. Use the LONG / SHORT YES/NO status as a filter for your own trading signals or systems — only take trades aligned with the regime decision.
4. Set up alerts on regime transitions (UP/DN/RG) and on LONG/SHORT signals to be notified.


VALIDATION CONTEXT

- Tested on 8 years of BTC daily data (2018–2026) with custom backtest engine
- Cross-asset validation on ETH and SOL
- Walk-forward in-sample / out-of-sample stable
- Reduces drawdown by ~42% vs unfiltered baseline
- Sharpe ratio improvement from ~0.22 (baseline) to ~0.455 (with filter)
- All numbers expressed in R-multiples (1R = sized risk per trade)


INPUTS YOU CAN ADJUST

- EMA Regime length (default 20)
- Regime lookback days (default 7)
- Regime threshold (default 0.1%)
- Macro EMAs Fast / Slow (default 50 / 200)
- ADX period & threshold for R3 (default 14 / 30)
- RSI period & threshold for R4 (default 14 / 30)
- Early/Late boundary in days (default 7)


ALERTS AVAILABLE

- Transition → UP
- Transition → DN
- Transition → RG
- LONG signal (R2 or R4)
- SHORT signal (R3)


DISCLAIMER

This indicator is a filter / decision-support tool, not a complete trading strategy. It tells you when the macro regime allows LONG or SHORT — it does not generate entry / exit prices. You must combine it with your own setup detection (Fibonacci retracement, trend continuation, structure breaks, etc.).

Past performance does not guarantee future results. Always backtest with your own assumptions and position sizing. Use at your own risk.


AUTHOR NOTE

This filter is part of a broader systematic trading framework I've developed over 10+ years of crypto trading. The published version is the macro regime layer only — you bring your own entry / exit logic on top.

If you find it useful, leave a like and feel free to comment with the asset / timeframe combinations that work best for you.

免責事項

これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。