fintech-algorithms

Commodity Channel Index (CCI)

Install and import

bash
npm install fintech-algorithms
ts
import { cci } from "fintech-algorithms/technical-indicators/momentum/cci";

Signature

cci(high, low, close, p, k)

Commodity channel index: the typical price's distance from its moving average, scaled by mean absolute deviation. Unbounded, unlike RSI or the stochastics.

Parameters

NameTypeNotes
highnumber[]Per-bar high prices, chronological.
lownumber[]Per-bar low prices, chronological.
closenumber[]Per-bar closing prices, chronological.
pnumberLookback for the average and the mean absolute deviation.
min: 1 · integer: true
knumberScaling constant. The conventional 0.015 places roughly 70–80% of readings within ±100; changing it changes what any threshold means.
min: 0
optional

Returns

Record<string, (number | null)[]> · length same-as-input

Parallel series: typical_price and cci.

Warm-up

The first p − 1 positions are null.

Errors

  • When p < 1, is not an integer, or k is negative — throws RangeError
  • When the input series are not all the same length — throws RangeError

Complexity: time O(n × p), space O(n).

Worked example

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input

high
[101, 101.992465, 103.28276, 104.655405, 105.856544, 106.661472]

Showing 6 of 120 elements.

low
[99.08, 99.149664, 100.233798, 101.654978, 103.180913, 104.534685]

Showing 6 of 120 elements.

close
[100, 100.999214, 102.324548, 103.755998, 105.030823, 105.911843]

Showing 6 of 120 elements.

Call

cci(high, low, close, p, k)

Returns

object with 2 fields: typical_price, cci

{
  "typical_price": [
    100.02666666666666,
    100.713781,
    101.94703533333332,
    103.35546033333333,
    104.68942666666668,
    105.70266666666667
  ],
  "cci": [null, null, null, null, null, null]
}

Other exports

This module also exports rsi, stochastic, stochastic_rsi, williams_r, ultimate_oscillator, tsi, connors_rsi. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams

Commodity Channel Index (CCI) — cci mechanism

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References

  • Commodity Channel Index (CCI) — TA-Lib
  • TA-Lib Technical Analysis Documentation — TA-Lib
  • Claim-role ledger
  • Evidence boundary