ADX#
Description#
ADX (Average Directional Index, J. Welles Wilder Jr. 1978) measures trend strength, not direction. It is the canonical filter for "are we trending or chopping?" Returns the triple (+DI, -DI, ADX) per step:
3-input, 3-output (FunctorBase<_, 3, 3>) on (high, low, close). Outputs are (out[..., 0]=+DI, out[..., 1]=-DI, out[..., 2]=ADX).
Parameters and warmup#
window_size(int, default14, the Wilder convention).
Output |
First valid sample |
|---|---|
|
|
|
|
|
|
For the default window_size=14, +DI/-DI start at sample 14 and ADX at sample 27. Matches TA-Lib's PLUS_DI / MINUS_DI / ADX bit-exactly.
Convention note#
TA-Lib's Wilder smoother for the DI/DM/TR triplet uses a slightly different seed than its ATR smoother: accumulate w-1 values during warmup, then apply the recurrence at the w-th value (sum form). The ADX smoother itself uses the standard SMA-of-w-values seed (average form). screamer.ADX implements both conventions inline to match TA-Lib exactly; it does not share state with the existing ATR class.
Usage#
NaN handling#
Policy: ignore. A NaN in any input at index t causes the function to skip that step: output at t is NaN and internal state is unchanged. Subsequent finite samples are processed as if step t had not occurred.
Examples#
Usage#
import numpy as np
from screamer import ADX
rng = np.random.default_rng(0)
n = 300
close = 100 + np.cumsum(rng.normal(0, 1, n))
high = close + np.abs(rng.normal(0, 0.5, n))
low = close - np.abs(rng.normal(0, 0.5, n))
out = ADX(14)(high, low, close)
plus_di, minus_di, adx = out[:, 0], out[:, 1], out[:, 2]
# adx > 25 -> trending; adx < 20 -> ranging (Wilder's heuristic)
Reference#
Matches talib.PLUS_DI, talib.MINUS_DI, talib.ADX bit-exactly (verified to ~1e-14 in tests/test_third_party_alignment.py).