Sidechair

ta.cci()

Browse the reference

Returns the commodity channel index: how far source sits from its moving average, in units of 0.015 times the mean deviation.

Try it in the editor

ta.cci subtracts the simple average of source over length bars from the current value, then divides by 0.015 times the mean absolute deviation of the window (the same measure ta.dev returns).

The constant 0.015 scales the output so that roughly 70 to 80 percent of values land between -100 and +100. The oscillator starts on bar number length, when the first full window exists.

Syntax

Pine Script
ta.cci(source: series int/float, length: series int) -> series float

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredSeries to measure, often hlc3 for a typical-price CCI.
lengthseries intrequiredWindow length for the average and the deviation. A whole number of 1 or more.

Returns

series float: the channel index value, unbounded but usually within about -200 to 200, or na while the window is not full.

Remarks

  • A flat window has zero deviation, so the result is na there.

Example

Pine ScriptCCI on typical priceOpen in editor
//@version=6
indicator("CCI")
len = input.int(20, "Length", minval = 1)
value = ta.cci(hlc3, len)
plot(value, "CCI", color = color.blue)
hline(100)
hline(-100)
hline(0, color = color.gray)

See also

Runs on Sidechair