OPEN-SOURCE SCRIPT

Fractional CUSUM Regime Filter [Jamallo]

758
🔹Intro

The Fractional CUSUM Regime Filter is a quantitative trend and volatility channel indicator designed to identify structural market regimes with high stability. Unlike traditional filters that suffer from lag or whipsaw signals, this indicator applies a dual-layered preprocessor combining Lopez de Prado’s Fixed-Window Fractional Differentiation (FFD) with a classic Cumulative Sum (CUSUM) statistical trigger.

🔹Break down

  • Fractional Differentiation (FFD): Stationarizes pricing input while retaining long-term historical memory (controlled by the "d" parameter).
  • Classic CUSUM Filter: Accumulates deviations from a rolling baseline relative to current volatility. When cumulative deviation exceeds the threshold multiplier (h), a new regime change is triggered, and the baseline steps dynamically to the new price level.
  • Vol-Adjusted Percentile Bands: Linear interpolation percentiles of price deviation relative to the stepped baseline. The distances are "locked" and only update on CUSUM regime triggers to prevent wobbly bands.


🔹Visual Guide: Indicator Anatomy

Here we have the structure of the indicator, including the CUSUM baseline, the 68% inner percentile band, and the 95% outer percentile band.

istantanea

How to use: Mean Reversion (Pullbacks to the Mean)

The channel boundaries represent statistical extremes. When the price is pushed outside the bands, it is mathematically overextended and highly likely to revert back to the CUSUM baseline.

Long Setup (Pullbacks in Bullish Trend): During a green CUSUM uptrend, watch for price to pull back to the lower bands ("micro pullback") and enter as it heads back up to the baseline mean.

istantanea

Short Setup (Pullbacks in Bearish Trend): During a red CUSUM downtrend, watch for price to rally into the upper bands ("micro pullback") and enter as it reverts down to the baseline mean.

istantanea

🔹How to use: Trend Following & Risk Management

The indicator is designed to capture sustained macro trends while providing clear risk parameters.

  • Entering on Breakthroughs: Enter when the BUY/SELL signal flags appear (indicating a new CUSUM regime shift).
  • Stop Loss Placement: Place stop loss orders just below the opposite outer band or below the stepped baseline.
  • Letting Winners Run: Ride the trend as long as the CUSUM baseline maintains its colored regime state (Green for Long, Red for Short).


istantanea
istantanea

🔹Settings Parameters

  • d (0.01 - 0.99): Differentiation order. Lower values retain more historical memory; higher values approach first-difference.
  • CUSUM Drift & Threshold: Controls baseline sensitivity to regime changes.
  • Percentile Lookback & Targets: Set the statistical width of the inner and outer boundaries.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.