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

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.