CCI (Commodity Channel Index)
The CCI measures how far the current price deviates from its historical average. Values above +100 suggest overbought conditions, below -100 suggest oversold.
Declaration
function init(ctx) { ctx.indicator('cci', 'CCI', { period: 20 }); }
Options
| Option | Type | Default | Description |
|---|---|---|---|
period | number | 20 | Lookback period |
Output
Returns a single number[] series. Values are unbounded but typically range from -200 to +200.
Accessing Values
function onBar(ctx, i) { const cciValue = ctx.ind.cci[i]; }
Use Cases
Overbought / Oversold
function onBar(ctx, i) { const cci = ctx.ind.cci[i]; if (cci < -100) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'cci_oversold' }); } if (cci > 100) { ctx.order.close('ASSET', { signal: 'sell', reason: 'cci_overbought' }); } }
Zero-Line Crossover
function onBar(ctx, i) { const cci = ctx.ind.cci[i]; const prevCci = ctx.ind.cci[i - 1]; if (prevCci < 0 && cci > 0) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'cci_cross_zero' }); } }
Calculation
$$CCI = \frac{TP - SMA(TP)}{0.015 \times MeanDeviation}$$
Where $TP = \frac{High + Low + Close}{3}$ (Typical Price)
Related
- RSI - Momentum oscillator with fixed 0-100 range
- Williams %R - Another mean-reversion indicator
- STOCH - Range-based oscillator
indicatorccimomentumoscillatormean-reversionqsl