Momentum OscillatorsPine Script v6

ta.cci()Commodity Channel Index

CCI is (source - SMA(source, length)) divided by (0.015 × mean absolute deviation). Typical price (hlc3) is a common source; ta.cci uses the supplied series.

TradingView language reference

Syntax

Syntax
ta.cci(source, length) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatPrice or value series to analyze (often hlc3 or close).
lengthseries intLookback length for mean deviation and averaging.

Returns

Commodity channel index of source for length bars back.

Remarks

na values in the source series are ignored.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.cci")
plot(ta.cci(hlc3, 20))

Trading Applications

Identify cyclical trends in price

Monitor values above +100 or below -100 in context; they do not imply an imminent reversal

Spot divergences between price and CCI

Use zero-line crossovers for trend confirmation

Related Functions

Frequently Asked Questions

ta.cci() returns the Commodity Channel Index, measuring how far price deviates from its statistical mean over length bars, scaled by a constant (0.015).

Common references use +100 and -100 as elevated extremes, with zero as a mean-reversion midpoint. Interpretation depends on volatility and market regime.

CCI divides the source-minus-SMA difference by 0.015 times the mean absolute deviation. The factor belongs in the denominator; it does not multiply the final ratio.

Generate ta.cci() Code with AI

Draft Pine Script using ta.cci() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.