Commodity Channel Index

All functions · nseries package

CCI

func (s Series) CCI(h, l, c Series, n int) Series

CCI computes the Commodity Channel Index over a period of n bars. Developed by Donald Lambert, CCI measures how far the typical price deviates from its average, scaled by the mean absolute deviation. Values above +100 suggest overbought conditions; below -100 suggest oversold. A window whose typical prices are all equal and finite gives exactly 0, rather than ±66.67 from rounding in the mean.

The warm-up reads 0, not NaN: bars 0 to n-2 are 0, the neutral centre of the oscillator; the first valid index is n-1 and the minimum length is n.

If h, l and c differ in length the result is an empty Series. Otherwise it has their length, and every bar is 0 when n < 1 or n > len(h): a history shorter than the window gives zeros rather than an empty Series, so CCI over a prefix of the bars is that prefix of CCI over all of them. Releases before this change returned an empty Series when n < 1 or n > len(h).