# Directional Movement

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

`D07-F02-A04` · Technical Indicators → Trend Systems · archetype `series-transform` · difficulty 3/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/technical-indicators/trend-systems/directional-movement/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { directionalMovement } from "fintech-algorithms/technical-indicators/trend-systems/directional-movement";
```

## Signature

```ts
directionalMovement(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

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `high` | `number[]` | yes | Per-bar high prices, chronological. |
| `low` | `number[]` | yes | Per-bar low prices, chronological. |
| `close` | `number[]` | yes | Per-bar closing prices, chronological. |
| `period` | `number` | yes | Wilder 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

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`:

```json
[105.45, 106.10084, 106.816229, 107.542653, 108.232784, 108.852128]
```

Showing 6 of 180 elements.

`low`:

```json
[103.293, 103.437436, 103.948153, 104.603166, 105.372863, 106.203002]
```

Showing 6 of 180 elements.

`close`:

```json
[104.42, 104.954567, 105.585587, 106.282695, 107.006608, 107.713561]
```

Showing 6 of 180 elements.

`period`:

```json
14
```

### Call

```ts
directionalMovement(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, …

```json
{
  "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]
}
```

## Verification and provenance

Tier: **verified** (via scenario-fixture).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/technical-indicators/trend-systems/directional-movement/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/trend-systems/directional-movement/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/technical-indicators/llms.txt
