# `TAlib.Indicators.ADX`
[🔗](https://github.com/benyblack/talib/blob/main/lib/indicators/adx.ex#L1)

Average Directional Index [Wikipedia](https://en.wikipedia.org/wiki/Average_directional_movement_index).

* `+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 first `period` DX 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.

# `adx`

```elixir
@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

# `adx_all`

```elixir
@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}

# `adxr`

```elixir
@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

# `dx`

```elixir
@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

# `minus_di`

```elixir
@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

# `minus_dm`

```elixir
@spec minus_dm([map()]) :: [number()]
```

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]

# `plus_di`

```elixir
@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

# `plus_dm`

```elixir
@spec plus_dm([map()]) :: [number()]
```

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]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
