adxΒΆ

Defined in fynance.features.ohlcv

adx(high, low=None, close=None, w=14)[source]

Average Directional Index (Wilder), causal.

Trend-strength oscillator built from the smoothed directional movement (+DI / -DI) and their normalized spread (DX), itself Wilder-smoothed.

Parameters:
high, low, closearray-like, or high = OHLCV

High/Low/Close series, or a single OHLCV.

wint, optional

Smoothing window. Default 14.

Returns:
numpy.ndarray

ADX series in [0, 100], aligned with the input.

Raises:
ValueError

If w < 1, or if low / close are missing without an OHLCV first argument.

Examples

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> n = 60
>>> h = 100 + np.cumsum(np.abs(rng.standard_normal(n)))
>>> low = h - np.abs(rng.standard_normal(n))
>>> c = (h + low) / 2
>>> out = adx(h, low, c, w=14)
>>> bool(np.all((out >= 0) & (out <= 100)))
True