OPEN-SOURCE SCRIPT
CCI Standard Deviation

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.
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.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.