fintech-algorithms

Directional Movement

From True Range to +DI, −DI, and DX

Install and import

bash
npm install fintech-algorithms
ts
import { directional_movement } from "fintech-algorithms/technical-indicators/trend-systems/directional-movement";

Signature

directional_movement(high, low, close, period)

The components beneath ADX: directional movement in each direction, Wilder-smoothed, divided by the average true range to give +DI and −DI.

Parameters

NameTypeNotes
highnumber[]Per-bar high prices, chronological.
lownumber[]Per-bar low prices, chronological.
closenumber[]Per-bar closing prices, chronological.
periodnumberWilder smoothing period.
min: 1 · integer: true

Returns

Record<string, (number | null)[]> · length same-as-input

Every intermediate as a parallel series — true_range, plus_dm, minus_dm, their smoothed forms, atr, plus_di, minus_di and dx.

Warm-up

The first period positions are null. Wilder smoothing seeds on the first full window.

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

high
[105.45, 106.10084, 106.816229, 107.542653, 108.232784, 108.852128]

Showing 6 of 180 elements.

low
[103.293, 103.437436, 103.948153, 104.603166, 105.372863, 106.203002]

Showing 6 of 180 elements.

close
[104.42, 104.954567, 105.585587, 106.282695, 107.006608, 107.713561]

Showing 6 of 180 elements.

period
14

Call

directional_movement(high, low, close, period)

Returns

object with 10 fields: true_range, plus_dm, minus_dm, smoothed_tr, smoothed_plus_dm, smoothed_minus_dm, atr, plus_di, …

{
  "true_range": [
    2.1569999999999965,
    2.663404,
    2.868076000000002,
    2.9394869999999997,
    2.859921,
    2.6491259999999954
  ],
  "plus_dm": [
    0,
    0.6508400000000023,
    0.7153890000000018,
    0.7264239999999944,
    0.6901309999999938,
    0.6193439999999981
  ],
  "minus_dm": [0, 0, 0, 0, 0, 0],
  "smoothed_tr": [null, null, null, null, null, null],
  "smoothed_plus_dm": [null, null, null, null, null, null],
  "smoothed_minus_dm": [null, null, null, null, null, null],
  "atr": [null, null, null, null, null, null],
  "plus_di": [null, null, null, null, null, null],
  "minus_di": [null, null, null, null, null, null],
  "dx": [null, null, null, null, null, null]
}

Diagrams

Directional Movement — canonical trace
Directional Movement — failure boundary
Directional Movement — mechanism map

Calculation flow

Directional Movement calculation flow
flowchart LR
    A["Validated finalized bar"] --> B["Causal window or recursive state"]
    B --> C["Explicit seed and boundary rule"]
    C --> D["Aligned Directional Movement 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.

Read the article →

References