TAlib.Indicators.CCI (TAlib v0.13.0)

Copy Markdown View Source

Commodity Channel Index Wikipedia.

With the typical price TP = (high + low + close) / 3:

CCI = (TP - SMA(TP, period)) / (0.015 * mean_deviation)

where the mean deviation is the average of |TP - SMA| across the window. Bars are maps with at least :high, :low and :close. See TAlib for the remaining conventions: chronological order, oldest first, series aligned with the input, nil when there is not enough data or the deviation is zero.

Summary

Functions

Calculate the latest CCI value.

Calculate the full CCI series.

Functions

cci(bars, period \\ 20)

@spec cci([map()], pos_integer()) :: float() | nil

Calculate the latest CCI value.

Parameters

  • bars: list of bars, oldest first.
  • period: lookback window, a positive integer (default 20).

Examples

iex> bars = [
...>   %{high: 12, low: 8, close: 10},
...>   %{high: 11, low: 9, close: 10},
...>   %{high: 13, low: 9, close: 12}
...> ]
iex> TAlib.Indicators.CCI.cci(bars, 2) |> Float.round(4)
66.6667

cci_list(bars, period \\ 20)

@spec cci_list([map()], pos_integer()) :: [float() | nil]

Calculate the full CCI series.

Returns a list aligned with bars: the first period - 1 entries are nil, and every later entry is the CCI of the window ending at that point.

Parameters

  • bars: list of bars, oldest first.
  • period: lookback window, a positive integer (default 20).

Examples

iex> bars = [
...>   %{high: 12, low: 8, close: 10},
...>   %{high: 11, low: 9, close: 10},
...>   %{high: 13, low: 9, close: 12}
...> ]
iex> TAlib.Indicators.CCI.cci_list(bars, 2) |> Enum.map(fn
...>   nil -> nil
...>   x -> Float.round(x, 4)
...> end)
[nil, nil, 66.6667]