Average Directional Index (ADX)
Smooth DX Without Inventing Direction
Install and import
npm install fintech-algorithmsimport { adx } from "fintech-algorithms/technical-indicators/trend-systems/adx";Signature
adx(high, low, close, period)Average directional index: the smoothed magnitude of the gap between +DI and −DI. It measures whether a trend exists at all, and says nothing about its direction — which is why it is used as a filter rather than a signal.
Parameters
| Name | Type | Notes |
|---|---|---|
high | number[] | Per-bar high prices, chronological. |
low | number[] | Per-bar low prices, chronological. |
close | number[] | Per-bar closing prices, chronological. |
period | number | Wilder smoothing period, applied twice: once to the DI components and once to DX. min: 1 · integer: true |
Returns
Record<string, (number | null)[]> · length same-as-input
Parallel series: plus_di, minus_di, dx and adx.
Warm-up
The first 2 × period − 1 positions are null. ADX is a smoothing of DX, which is itself computed from smoothed components.
Errors
- When period < 1 or is not an integer — throws RangeError
- When the input series are not all the same length — throws RangeError
Complexity: time O(n),
space O(n).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
[109.485, 110.139028, 110.859574, 111.590939, 112.283113, 112.89901]Showing 6 of 180 elements.
[107.2615, 107.406037, 107.92024, 108.58088, 109.35613, 110.189018]Showing 6 of 180 elements.
[108.42, 108.957755, 109.593932, 110.295981, 111.021937, 111.725443]Showing 6 of 180 elements.
14Call
adx(high, low, close, period)Returns
object with 4 fields: plus_di, minus_di, dx, adx
{
"plus_di": [null, null, null, null, null, null],
"minus_di": [null, null, null, null, null, null],
"dx": [null, null, null, null, null, null],
"adx": [null, null, null, null, null, null]
}Diagrams
Calculation flow
ADX calculation flow
flowchart LR
A["Validated finalized bar"] --> B["Causal window or recursive state"]
B --> C["Explicit seed and boundary rule"]
C --> D["Aligned ADX output"]
D --> E["Diagnostics and audit evidence"]
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- J. Welles Wilder, New Concepts in Technical Trading Systems — J. Welles Wilder
- TA-Lib ADX — TA-Lib project or TradingView, as identified by the linked page
- Pinned TA-Lib ta_ADX.c implementation — TA-Lib project or TradingView
- Canonical synthetic fixture and independent arithmetic — The Fintech Builder
- R5 — TA-Lib DX function documentation — TA-Lib project or TradingView