OPEN-SOURCE SCRIPT

CUSUM Volatility Breakout

305
CUSUM Volatility Breakout A statistical trend-detection and volatility-breakout indicator that identifies subtle momentum shifts earlier than traditional tools.

OVERVIEW
The CUSUM control chart is a statistical tool designed to detect small, gradual shifts from a target value. In trading, it helps identify the early stages of a trend, giving traders a heads-up before momentum becomes obvious on standard price charts. By spotting these subtle movements, the CUSUM Volatility Breakout indicator (CUSUM VB) can highlight potential breakout opportunities earlier than traditional indicators. In other words, a statistical trend detection & breakout indicator.

Copyright © 2025 CoinOperator

HOW IT WORKS
CUSUM VB uses a combination of differenced price series, volume normalization, and dynamic control limits:
  1. CUSUM Principle: Tracks cumulative deviations of price from a zero reference. Signals occur when cumulative deviations exceed a control limit shown on the chart and clears any enabled filters.
  2. Adaptive Volatility: H adjusts automatically based on short- vs long-term ATR ratios, allowing faster detection during volatile periods and reduced false signals in calm markets.
  3. Volume Weighting (optional): Amplifies price CUSUM values during high-volume bars to prioritize market participation strength.
  4. ATR Confirmation (optional): Ensures breakouts are accompanied by expanded volatility.
  5. Bollinger Band Squeeze Integration (optional): Confirms trend breakouts by detecting volatility contraction and release shown on the chart as triangles.

Signals:
Arrows on the price chart mark the bars where trades are actually filled, based on conditions detected on the prior signal bar.
  • Long Entry: Confirmed positive CUSUM breach (price & volume) with BB breakout (signal bar).
  • Short Entry: Confirmed negative CUSUM breach (price & volume) with BB breakout (signal bar).
  • Exit Signals: Triggered automatically by opposite-side signals.
  • Alerts, when created, fire on the bars where fills occur.


CHART COMPONENTS
  • CUSUM Upper Price (CU Price) and CUSUM Lower Price (CL Price) are green/red circles for confirmed signals.
    ● Rapid upward accumulation of CU Price indicates a developing bullish trend.
    ● Rapid downward accumulation of CL Price indicates a developing bearish trend.
  • Decision/Control limits (UCL/LCL, red)
  • Zero line (reference for the differenced price series baseline)
  • Optional BB triangles and volume CUSUM


SETUP AND CONFIGURATION
Differenced Price Series
cuplikan
Differenced Price Length and Lag
  • Increase differencing lag or window length → Increases variance of residuals → Wider control limits (UCL/LCL) → Slower to trigger.
  • Decrease lag or window → Tighter limits, more responsive to short-term regime shifts.


CUSUM Parameters
Volume-Weighted CUSUM
  • NOTE: Uses price length if 'Confirm Price with Volume' is disabled, otherwise will use volume length.
  • Amplifies CUSUM price responses during high-volume bars and reduces them during low-volume bars. This links trend detection to market participation strength.
  • Volume-Weighted CUSUM doesn’t replace price confirmation with volume; it modulates it by volume intensity, amplifying price signals when participation is strong and suppressing them when weak.
  • Recommended when analyzing assets with consistent volume patterns (e.g., stocks, major futures).
  • Disable for low-liquidity or irregular-volume instruments (e.g., crypto pairs, small-cap stocks).


ATR Confirmation
Enable this feature to confirm CUSUM signals only when price deviations are accompanied by higher-than-normal volatility. The indicator compares current ATR to a smoothed ATR to detect volatility expansion. This helps distinguish true breakouts from low-volatility noise and reduces false signals during quiet periods.

Adjust the ATR lookback length, smoothing length, and expansion factor to control sensitivity. Rule of thumb:
  • ATR Length ≈ 0.5 × differenced price length to 1.5 × differenced price length gives balanced sensitivity.
  • ATR Smoothing 5–10 bars.
  • ATR Expansion 5% to 50%.


CUSUM Input Mode
Select how CUSUM processes differenced price and log-normalized volume — either directly (Txfrm Data) or as deviations from a short-term EMA baseline (Residuals):
  • Txfrm Data = transformed input: differenced price & log-normalized volume as input for CUSUM (larger swings, more frequent control limit breaches)
  • Residuals = deviation from short-term EMA baseline (smaller swings, fewer control limit breaches, but higher signal quality).
  • Residual EMA Length: Defines how quickly the residual baseline adapts to recent differenced price moves. Shorter = more reactive; longer = smoother baseline. Keep EMA length moderate; over-smoothing can distort timing.

cuplikan

Control Sensitivity (K)
  • Increase K → Less sensitive → CUSUM accumulates slower → Fewer signals, captures only major trends.
  • Decrease K → More sensitive → CUSUM accumulates faster → More signals, captures minor swings too.


Reset Mode: Method of resetting CUSUM values.
  • Immediate Reset: Reset both immediately after any signal breach. Traditional SPC.
  • Opposite-Side Reset: Reset only the opposite side when a valid signal fires. Best for ongoing trend tracking.
  • Decay Reset: Gradually reduce CUSUM values toward zero with a decay factor each bar. Maintains trend memory but allows slow “forgetting.”
  • Threshold Reset: Reset only if CUSUM returns below a small threshold (10 % of H). Filters noise without full wipe.
  • No Reset / Continuous: Never reset; instead track running totals. Long-term cumulative bias measurement.


Conflict Handling: Method of handling conflicting signals.
  • Ignore Both: Discards both when overlap occurs.
  • Prioritize Latest: Chooses the direction implied by the most recent close.
  • Prioritize Stronger: Compares absolute magnitudes of CU Price vs CL Price.
  • Average Resolve: Looks at the difference; small overlap → ignore, otherwise pick direction by sign.
  • Sequential Confirm: Requires N consecutive same-direction signals before confirmation.


Volume Parameters (Optional)
cuplikan

Amplification Factor
  • Adjusts volume sensitivity and effectively rescales the log series of volume to a comparable magnitude with price changes.
  • Since price and volume are normalized in a compatible way, the amplification factor is used instead of independent K and H values for volume.


Bollinger Bands (Optional)
cuplikan

Lookback Synchronization
  • BB Lookback (for CUSUM): Number of bars that define a window for the BB signal to look back for the CUSUM signal.
  • CUSUM Lookback (for BB): Number of bars that define a window for the CUSUM signal to look back for the BB signal.
  • Both can be enabled for stricter alignment.


Relationship Between K, H, ARL₀ and ARL₁
cuplikan
H (max) is usually the only H you need to adjust. With everything else being constant, increasing either K or H (max) generally increases both ARL₀ and ARL₁ : higher thresholds reduce false alarms but slow detection, and lower thresholds do the opposite.

Increase Min Target ARL ratio →
  • ARL₀ increases (safer, fewer false alarms)
  • ARL₁ decreases or stays small (faster detection)
  • Control limits slightly expand to achieve separation
  • Strategy becomes more selective and stable


Decrease Min Target ARL ratio →
  • ARL₀ decreases (more false alarms tolerated)
  • ARL₁ increases (slower detection tolerated)
  • Control limits tighten
  • Strategy becomes more sensitive but lower quality


The ARL Ratio of ARL₀ / ARL₁ is typically between 3 and 8. This implies you want your ARL₀ (false-alarm interval) ≈ 'Min Target ARL ratio' × differenced price length window.

Example:
"Min Target ARL ratio = 4.0"
⇒ implies you want your ARL₀ (false-alarm interval) ≈ 4 × differenced price length.

Assume price length = 50 (typical differencing window).
  • ARL ratio = 4.0 → target ARL = 4 × 50 = 200 bars.
    ● On a 6-hour chart (≈4 bars/day) → ~50 days between expected false alarms (on average).
    ● On a daily chart → ~200 trading days between false alarms (very conservative).
  • ARL ratio = 8.0 → target ARL = 400 bars → twice as infrequent signals vs ratio=4.
  • ARL ratio = 2.0 → target ARL = 100 bars → about half the inter-signal interval.


Another way to think about it: probability of a false alarm on any bar ≈ 1 / target ARL. If you want ~1% of bars producing alarms, target ARL ≈ 100.

QUICK START
  1. Start with the defaults.
  2. Set price series → length/order/lag
  3. Configure CUSUM thresholds → K, H min/max
    1. Adjust the price differencing lag/window.
    2. Verify that it captures real price inflection points without overreacting to bar noise.
  4. Enable optional filters → Volume, ATR, BB
    The optional Bollinger Bands squeeze usually works best if used with CUSUM Input Mode = Txfrm Data.
  5. Monitor CUSUM chart → CU Price, CL Price, thresholds, zero line
  6. Act on signals → data window / chart triangles
  7. Adjust sensitivity → H (max), K, lengths
  8. Monitor ARL ratio and CUSUM behavior for fine-tuning


Note: When you’ve finalized the length, lag, and order of the Price Difference, as well as the Ln(Vol) Series of “Confirm Price with Volume” if enabled, then pass both through the Augmented Dickey–Fuller (ADF) mean reversion test to ensure they are stationary, i.e., mean reverting. You can find a ready-made indicator for such use at https://www.tradingview.com/v/KjD8ByIQ/. Many thanks to tbtkg for this indicator.

SUMMARY
CUSUM VB combines CUSUM statistical control, volatility-adaptive thresholds, volume weighting, and optional BB breakout confirmation to provide robust, actionable signals across a wide variety of trading instruments.
  • Why traders use it: Fast detection of shifts, reduced false alarms, versatile across markets.
  • Ideal for: Futures (continuous contracts), forex, crypto, stocks, ETFs, and commodity/index CFDs, especially where:
    ● Price and volume data exist
    ● Breakouts and volatility shifts are tradable
    ● There’s enough liquidity for meaningful signals
  • Visualization: Upper/lower CUSUM circles, UCL/LCL thresholds, optional highlight traded background, optional volume and BB overlays on the chart, optional entry/exit labels on the price chart, as well as entry/exit signals in the data window.
  • Alerts: For entry/exit labels when trades are actually filled.

CUSUM VB is designed for traders who want statistically grounded trend detection with configurable sensitivity, visual clarity, and multi-market versatility.

DISCLAIMER
This software and documentation are provided “as is” without any warranties of any kind, express or implied. CoinOperator assumes no responsibility or liability for any errors, omissions, or losses arising from the use or interpretation of this software or its outputs. Trading and investing carry inherent risks, and users are solely responsible for their own decisions and results.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.