Trend & MomentumIntermediate
CCI
Commodity Channel Index
Measures how far price has deviated from its statistical average.
4H, Daily
Crypto, Forex, Equities, Commodities
Pine Script v5
What is it?
Developed by Donald Lambert in 1980, CCI measures the difference between the typical price (average of high, low, close) and its simple moving average, normalised by the mean absolute deviation. The formula: CCI = (Typical Price - SMA) / (0.015 × Mean Absolute Deviation). The 0.015 constant ensures roughly 70–80% of values fall between ±100. Values above +100 indicate the asset is trading above its statistical norm (potential uptrend entry or overbought); below -100 indicates it is below its norm (potential downtrend entry or oversold). CCI has no upper or lower bound.
When to use it
- Trend entry: CCI crossing above +100 from below signals the start of a new uptrend; crossing below -100 signals a downtrend.
- Overbought/oversold reversals: CCI above +200 or below -200 in a ranging market suggests extreme deviation and a potential mean-reversion trade.
- Zero-line crossovers: CCI crossing above zero is a mild bullish signal; crossing below zero is bearish — useful as a trend filter.
- Divergence: price making a new high while CCI makes a lower high is a bearish divergence warning, similar to RSI.
- Combining with ADX: CCI crossover of ±100 with ADX above 25 is a trend-following entry; CCI at ±200 with ADX below 20 is a mean-reversion entry.
Common pitfalls
- CCI has no fixed upper or lower bound. Unlike RSI (0–100), CCI can reach ±300 or beyond in extreme moves — the ±100 levels are guidelines, not hard limits.
- The 0.015 constant was calibrated for commodity markets with regular cycles. In crypto's aperiodic market, the percentage of values within ±100 can vary significantly.
- CCI is calculated on the typical price (HLC/3), not just the close. This makes it more sensitive to intraday wicks than RSI.
- A CCI cross of +100 in a downtrend is a counter-trend signal, not a trend-following one. Always check the higher-timeframe trend before acting.
- The default 20-period CCI is quite noisy on short timeframes. Use 40–50 periods for smoother signals on 1H and 4H charts.
Free code template
Paste directly into TradingView Pine Editor → Add to chart.
Pine Script v5
/indicator("CCI — DAI Template", shorttitle="DAI CCI", overlay=false)
cciLen = input.int(20, "CCI Length", minval=1)
obLevel = input.int(100, "Overbought", minval=50)
osLevel = input.int(-100, "Oversold", maxval=-50)
cciVal = ta.cci(close, cciLen)
cciColor = cciVal >= obLevel ? #ef4444 : cciVal <= osLevel ? #3b82f6 : #22c55e
plot(cciVal, "CCI", color=cciColor, linewidth=2)
hline(obLevel, "Overbought", color=color.new(#ef4444, 40), linestyle=hline.style_dashed)
hline(0, "Zero", color=color.new(#94a3b8, 50), linestyle=hline.style_dotted)
hline(osLevel, "Oversold", color=color.new(#3b82f6, 40), linestyle=hline.style_dashed)
hline(200, "+200 Extreme", color=color.new(#ef4444, 70), linestyle=hline.style_dotted)
hline(-200, "-200 Extreme", color=color.new(#3b82f6, 70), linestyle=hline.style_dotted)
bgcolor(cciVal >= obLevel ? color.new(#ef4444, 94) : cciVal <= osLevel ? color.new(#3b82f6, 94) : na)
bullEntry = ta.crossover(cciVal, osLevel)
bearEntry = ta.crossunder(cciVal, obLevel)
plotshape(bullEntry, "Bull Entry", shape.triangleup, location.bottom, #22c55e, size=size.small)
plotshape(bearEntry, "Bear Entry", shape.triangledown, location.top, #ef4444, size=size.small)
alertcondition(bullEntry, "CCI Bull", "CCI crossed above " + str.tostring(osLevel))
alertcondition(bearEntry, "CCI Bear", "CCI crossed below " + str.tostring(obLevel))