OPEN-SOURCE SCRIPT

CCI Standard Deviation

86
CCI Standard Deviation – Asymmetric Volatility-Adjusted Trend Filter (CCI SD)

The Commodity Channel Index (CCI), created by Donald Lambert in 1980, measures how far the typical price deviates from its statistical average to identify cyclical momentum and trend strength.
The standard formula is:
CCI = (Typical Price − SMA(Typical Price, n)) / (0.015 × Mean Deviation)

where Typical Price = (High + Low + Close)/3.

CCI is unbounded and centered around zero: sustained readings above zero indicate bullish momentum, below zero bearish. Classic interpretations often use zero-line crosses or fixed levels (±100, ±200, ±250), but these can be unreliable when CCI volatility changes across market regimes.

This indicator was developed to create a more disciplined trend-following tool that aligns with my core risk principle: “always protect to the downside.”
Starting from the standard CCI zero-line concept for trend direction, I experimented with standard deviation bands to make the oscillator volatility-adjusted. I then applied deliberate asymmetry: requiring the lower 1σ envelope (CCI − stdev) to cross above a positive threshold for bullish confirmation (high-probability entry only in robust trends), while exiting immediately on any raw CCI weakness below a negative threshold (quick downside protection). User inputs for both thresholds were added to allow fine-tuning and adaptability across different assets and timeframes.
An optional DEMA-smoothed version of the lower envelope provides additional clarity when desired.

Extreme zones
快照
raw CCI ±240 and lower envelope > 200 or < –200 - are highlighted with background shading to flag rare acceleration or capitulation phases.

How it works
快照
Standard CCI calculated on typical price (default length 38).
Rolling standard deviation of the CCI itself (default length 13) measures the oscillator’s recent volatility.
Lower envelope = CCI − stdev (dn).
Optional DEMA smoothing (default length 12) can be toggled.

Trend logic:
Bullish regime only when lower envelope
→ Long Threshold (default +10)
→ statistical proof of strength

Bearish/neutral immediately when raw CCI
→ Short Threshold (default –25)
→ fast downside protection

Origin and development

The indicator emerged from wanting a cleaner, more reliable CCI for trend direction. After testing volatility-adjusted versions, the asymmetric design proved superior:
it enters only high-conviction uptrends and exits rapidly on weakness, significantly reducing whipsaws while preserving trend capture.

Parameters were optimized through extensive backtests on major assets (BTC, ETH, SOL and many more Cryptos; Magnificent 7 stocks, QQQ, SPX, gold).
The defaults were selected for the best average Sortino ratio and lowest maximum drawdown across this broad universe, ensuring robustness and avoiding single-asset overfitting.

How to use it

Green triangle below bar
→ lower envelope crosses above Long Threshold
→ high-conviction bullish trend confirmed
→ enter or add to longs

Magenta triangle above bar
→ CCI crosses below Short Threshold
→ exit longs or go cash/short

While lower envelope remains above Long Threshold
→ hold bullish positions

Extreme background shading (dn >200 or CCI ±240)
→ rare high-attention zones (potential acceleration or exhaustion)

Recommended defaults

CCI length: 38
SD length: 13
Long threshold: +10
Short threshold: –25
Optional MA length: 12 (DEMA of lower envelope)

All visual elements (bar coloring, signals, background, smoothed line) are toggleable for personal preference.

This indicator is designed as a trend-strength and risk-management filter and is not intended as a standalone trading system.

Disclaimer:
This is not financial advice. Backtests are based on past results and are not indicative of future performance.

免责声明

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