TAlib.Indicators.Keltner (TAlib v0.13.0)

Copy Markdown View Source

Keltner Channels Wikipedia.

  • middle = EMA(close, period)
  • upper = middle + mult * ATR(period)
  • lower = middle - mult * ATR(period)

The EMA and ATR are both seeded at index period - 1, so the channels are defined for the same points. Bars are maps with at least :high, :low and :close. See TAlib for the remaining conventions: chronological order, oldest first, nil when there is not enough data.

Summary

Functions

Calculate the latest Keltner Channels as a map.

Calculate the full Keltner Channels series.

Functions

keltner(bars, period \\ 20, mult \\ 2)

@spec keltner([map()], pos_integer(), number()) ::
  %{upper: float(), middle: float(), lower: float()} | nil

Calculate the latest Keltner Channels as a map.

Parameters

  • bars: list of bars, oldest first.
  • period: EMA/ATR lookback window, a positive integer (default 20).
  • mult: ATR multiplier, a number (default 2).

Examples

iex> bars = [
...>   %{high: 12, low: 8, close: 10},
...>   %{high: 11, low: 9, close: 10},
...>   %{high: 13, low: 9, close: 12}
...> ]
iex> %{upper: u, middle: m, lower: l} = TAlib.Indicators.Keltner.keltner(bars, 2, 2)
iex> {Float.round(u, 4), Float.round(m, 4), Float.round(l, 4)}
{17.3333, 11.3333, 5.3333}

keltner_list(bars, period \\ 20, mult \\ 2)

@spec keltner_list([map()], pos_integer(), number()) :: [map() | nil]

Calculate the full Keltner Channels series.

Returns a list aligned with bars: the first period - 1 entries are nil, and every later entry is a map with :upper, :middle and :lower.

Parameters

  • bars: list of bars, oldest first.
  • period: EMA/ATR lookback window, a positive integer (default 20).
  • mult: ATR multiplier, a number (default 2).

Examples

iex> bars = [
...>   %{high: 12, low: 8, close: 10},
...>   %{high: 11, low: 9, close: 10},
...>   %{high: 13, low: 9, close: 12}
...> ]
iex> TAlib.Indicators.Keltner.keltner_list(bars, 2) |> Enum.count(&is_nil/1)
2