Average Directional Index Wikipedia.
+DM/-DM: the up-/down-move that exceeds the opposite move on a bar+DI/-DI:100 * RMA(+DM) / RMA(TR)and its mirror (RMA = Wilder smoothing)DX = 100 * |+DI - -DI| / (+DI + -DI)ADX = RMA(DX), seeded with the SMA of the firstperiodDX values
The directional lines are defined from index period - 1 on and ADX from
index 2 * period - 2 (i.e. 2 * period - 1 bars). 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 ADX value: Wilder's smoothed average of DX.
Calculate +DI, -DI and ADX of the latest point in a single pass.
Calculate the latest ADX Rating: the average of the current ADX and the
ADX period - 1 bars ago.
Calculate the latest DX value: 100 * |+DI - -DI| / (+DI + -DI).
Calculate the latest -DI (negative directional index).
The raw -DM per bar; the first bar is 0.
Calculate the latest +DI (positive directional index).
The raw +DM per bar (the up-move that exceeds the opposite down-move); the first bar has no previous bar to compare against and is 0.
Functions
@spec adx([map()], pos_integer()) :: float() | nil
Calculate the latest ADX value: Wilder's smoothed average of DX.
Parameters
- bars: list of bars, oldest first.
- period: lookback window, a positive integer (default 14).
At least 2 * period - 1 bars are required for the DX seed window;
otherwise nil is returned.
Examples
iex> bars = [
...> %{high: 10, low: 5, close: 7},
...> %{high: 11, low: 6, close: 9},
...> %{high: 12, low: 7, close: 8},
...> %{high: 11, low: 8, close: 10},
...> %{high: 13, low: 9, close: 12}
...> ]
iex> TAlib.Indicators.ADX.adx(bars, 3)
100.0
@spec adx_all([map()], pos_integer()) :: %{ plus_di: float() | nil, minus_di: float() | nil, adx: float() | nil }
Calculate +DI, -DI and ADX of the latest point in a single pass.
Parameters
- bars: list of bars, oldest first.
- period: lookback window, a positive integer (default 14).
Returns a map with :plus_di, :minus_di and :adx. Each value is
nil when its own data requirement is not met, so the directional
lines can be defined while ADX is still nil.
Examples
iex> bars = [
...> %{high: 10, low: 5, close: 7},
...> %{high: 11, low: 6, close: 9},
...> %{high: 12, low: 7, close: 8},
...> %{high: 11, low: 8, close: 10},
...> %{high: 13, low: 9, close: 12}
...> ]
iex> %{plus_di: p, minus_di: m, adx: a} = TAlib.Indicators.ADX.adx_all(bars, 3)
iex> {Float.round(p, 4), Float.round(m, 4), Float.round(a, 4)}
{22.807, 0.0, 100.0}
@spec adxr([map()], pos_integer()) :: float() | nil
Calculate the latest ADX Rating: the average of the current ADX and the
ADX period - 1 bars ago.
At least 3 * period - 2 bars are required; otherwise nil is
returned.
iex> bars = [
...> %{high: 10, low: 5, close: 7},
...> %{high: 11, low: 6, close: 9},
...> %{high: 12, low: 7, close: 8},
...> %{high: 12, low: 8, close: 10}
...> ]
iex> TAlib.Indicators.ADX.adxr(bars, 2) |> Float.round(4)
100.0
@spec dx([map()], pos_integer()) :: float() | nil
Calculate the latest DX value: 100 * |+DI - -DI| / (+DI + -DI).
iex> bars = [
...> %{high: 10, low: 5, close: 7},
...> %{high: 11, low: 6, close: 9},
...> %{high: 12, low: 7, close: 8}
...> ]
iex> TAlib.Indicators.ADX.dx(bars, 2) |> Float.round(4)
100.0
@spec minus_di([map()], pos_integer()) :: float() | nil
Calculate the latest -DI (negative directional index).
Parameters
- bars: list of bars, oldest first.
- period: lookback window, a positive integer (default 14).
Examples
iex> bars = [
...> %{high: 10, low: 5, close: 7},
...> %{high: 11, low: 6, close: 9},
...> %{high: 12, low: 7, close: 8},
...> %{high: 11, low: 8, close: 10},
...> %{high: 13, low: 9, close: 12}
...> ]
iex> TAlib.Indicators.ADX.minus_di(bars, 3)
0.0
The raw -DM per bar; the first bar is 0.
iex> TAlib.Indicators.ADX.minus_dm([
...> %{high: 10, low: 5, close: 7},
...> %{high: 11, low: 6, close: 9},
...> %{high: 12, low: 7, close: 8}
...> ])
[0, 0, 0]
@spec plus_di([map()], pos_integer()) :: float() | nil
Calculate the latest +DI (positive directional index).
Parameters
- bars: list of bars, oldest first.
- period: lookback window, a positive integer (default 14).
Examples
iex> bars = [
...> %{high: 10, low: 5, close: 7},
...> %{high: 11, low: 6, close: 9},
...> %{high: 12, low: 7, close: 8},
...> %{high: 11, low: 8, close: 10},
...> %{high: 13, low: 9, close: 12}
...> ]
iex> TAlib.Indicators.ADX.plus_di(bars, 3) |> Float.round(4)
22.807
The raw +DM per bar (the up-move that exceeds the opposite down-move); the first bar has no previous bar to compare against and is 0.
iex> TAlib.Indicators.ADX.plus_dm([
...> %{high: 10, low: 5, close: 7},
...> %{high: 11, low: 6, close: 9},
...> %{high: 12, low: 7, close: 8}
...> ])
[0, 1, 1]