Momentum OscillatorsPine Script v6

ta.cci()Commodity Channel Index

The CCI is calculated as the difference between the typical price and its simple moving average, divided by the mean absolute deviation, scaled by 0.015.

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

Detect overbought (>100) and oversold (<-100) conditions

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 compares the source to its simple moving average and normalizes by mean absolute deviation, multiplied by 0.015 so typical readings cluster around a useful scale.

Generate ta.cci() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.cci() and other built-in functions instantly.