ADX & DMI
Wilder's Directional Movement Index: ADX for trend strength and +DI and -DI for its direction.
- ADX
- Built into Spectral
- Updates every tick
- adx
- dmi
- directional movement
- +di -di
- trend strength
- wilder
MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.
Already in Spectral: add it from the Indicators toolbox. The file here is the same indicator written as a custom indicator, to change or learn from. Installed, it appears next to the built-in one, marked Custom.

Overview
The Directional Movement Index by J. Welles Wilder compares how far each bar extends above the previous high (plus directional movement) with how far it extends below the previous low (minus directional movement). Smoothed and divided by the smoothed true range, they give +DI and -DI, the share of the recent range made by upward and by downward moves.
The ADX (Average Directional Index) is the Wilder average of the gap between the two lines relative to their sum, on a scale of 0 to 100. It measures how strongly the market trends, not in which direction.
How to read it
+DI above -DI means upward moves dominate; -DI above +DI means downward moves dominate, and a cross of the two is the classic direction signal. The ADX tells you whether that direction is worth acting on: above the threshold (often 20 to 25) the market trends, below it the market drifts sideways and crossovers are unreliable.
A rising ADX shows a strengthening trend in either direction; a falling ADX from a high level shows the trend losing force, even while price still moves its way. A very high ADX often comes late in a move.
Settings and limitations
DI length (14) and ADX smoothing (14) are Wilder's defaults; shorter values react sooner and are noisier. +DI and -DI start on bar DI length + 1 and the ADX on bar DI length + ADX smoothing (bar 28 with the defaults), and both settle over the next few dozen bars because Wilder smoothing has a long memory. Trend threshold only moves the reference line.
Notes
Matches TradingView's built-in DMI and Wilder's definition: directional movement counts only the larger of the up and down move, both lines and the true range use Wilder smoothing seeded with a simple average, and the ADX smooths the directional index the same way.
Settings
Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.
| Setting | Type | Default | Range or options | What it does |
|---|---|---|---|---|
| DI length | Whole number | 14 | 1 – 500 | Number of bars in the Wilder smoothing of the directional movement and the true range behind +DI and -DI. |
| ADX smoothing | Whole number | 14 | 1 – 500 | Number of bars in the Wilder smoothing that turns the directional index (DX) into the ADX. |
| Trend threshold | Number | 25 | 0 – 100, step 1 | Reference line for a trending market; an ADX above it is usually read as a trend. 20 and 25 are common. |
| Show +DI and -DI | On / off | On | — | Draw the two directional lines; switch off to show only the ADX. |
Presets
Each preset is its own entry in the Indicators toolbox, with these settings changed.
| Toolbox entry | Short name | Settings |
|---|---|---|
| ADX & DMI (7) | ADX 7 | DI length: 7ADX smoothing: 7 |
What it draws
Lines
- ADXsolid · 2 px · primary
#E3B341 - +DIsolid · 1.5 px
#3FB950 - -DIsolid · 1.5 px
#E5534B
Levels
- Trend thresholddotted · 1 px · value on the axis
#788493
Source
Save it as adx-dmi.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.
// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV2} */
export default {
schemaVersion: 2,
id: 'adx-dmi',
name: 'ADX & DMI',
shortName: 'ADX',
version: '1.0.0',
author: 'Spectral',
description: 'Wilder\'s Directional Movement Index: ADX for trend strength and +DI and -DI for its direction.',
pane: 'oscillator',
live: { lookback: 1 },
inputs: {
diLength: { type: 'integer', label: 'DI length', default: 14, min: 1, max: 500, description: 'Number of bars in the Wilder smoothing of the directional movement and the true range behind +DI and -DI.' },
adxSmoothing: { type: 'integer', label: 'ADX smoothing', default: 14, min: 1, max: 500, description: 'Number of bars in the Wilder smoothing that turns the directional index (DX) into the ADX.' },
trendLevel: { type: 'number', label: 'Trend threshold', default: 25, min: 0, max: 100, step: 1, description: 'Reference line for a trending market; an ADX above it is usually read as a trend. 20 and 25 are common.' },
showDi: { type: 'boolean', label: 'Show +DI and -DI', default: true, description: 'Draw the two directional lines; switch off to show only the ADX.' },
},
plots: {
adx: { label: 'ADX', color: '#E3B341', lineWidth: 2, primary: true },
plusDi: { label: '+DI', color: '#3FB950', lineWidth: 1.5 },
minusDi: { label: '-DI', color: '#E5534B', lineWidth: 1.5 },
},
levels: {
trend: { label: 'Trend threshold', color: '#788493', lineStyle: 'dotted', showValue: true },
},
presets: [
{ id: 'fast', name: 'ADX & DMI (7)', shortName: 'ADX 7', inputs: { diLength: 7, adxSmoothing: 7 } },
],
docs: {
overview: 'The Directional Movement Index by J. Welles Wilder compares how far each bar extends above the previous high (plus directional movement) with how far it extends below the previous low (minus directional movement). Smoothed and divided by the smoothed true range, they give +DI and -DI, the share of the recent range made by upward and by downward moves.\n\nThe ADX (Average Directional Index) is the Wilder average of the gap between the two lines relative to their sum, on a scale of 0 to 100. It measures how strongly the market trends, not in which direction.',
howToRead: '+DI above -DI means upward moves dominate; -DI above +DI means downward moves dominate, and a cross of the two is the classic direction signal. The ADX tells you whether that direction is worth acting on: above the threshold (often 20 to 25) the market trends, below it the market drifts sideways and crossovers are unreliable.\n\nA rising ADX shows a strengthening trend in either direction; a falling ADX from a high level shows the trend losing force, even while price still moves its way. A very high ADX often comes late in a move.',
settings: 'DI length (14) and ADX smoothing (14) are Wilder\'s defaults; shorter values react sooner and are noisier. +DI and -DI start on bar DI length + 1 and the ADX on bar DI length + ADX smoothing (bar 28 with the defaults), and both settle over the next few dozen bars because Wilder smoothing has a long memory. Trend threshold only moves the reference line.',
notes: 'Matches TradingView\'s built-in DMI and Wilder\'s definition: directional movement counts only the larger of the up and down move, both lines and the true range use Wilder smoothing seeded with a simple average, and the ADX smooths the directional index the same way.',
},
calculate(ctx) {
const { bars, inputs, ta } = ctx;
const count = bars.length;
const plusMove = new Array(count).fill(null);
const minusMove = new Array(count).fill(null);
const trueRange = new Array(count).fill(null);
for (let index = 1; index < count; index += 1) {
const bar = bars[index];
const previous = bars[index - 1];
const up = bar.high - previous.high;
const down = previous.low - bar.low;
plusMove[index] = up > down && up > 0 ? up : 0;
minusMove[index] = down > up && down > 0 ? down : 0;
trueRange[index] = Math.max(bar.high - bar.low, Math.abs(bar.high - previous.close), Math.abs(bar.low - previous.close));
}
// Smoothing starts on the second bar, where the first move is known.
const range = ta.rma(trueRange, inputs.diLength);
const plusSmooth = ta.rma(plusMove, inputs.diLength);
const minusSmooth = ta.rma(minusMove, inputs.diLength);
const plusDi = new Array(count).fill(null);
const minusDi = new Array(count).fill(null);
const directional = new Array(count).fill(null);
for (let index = 0; index < count; index += 1) {
const total = range[index];
if (total === null || plusSmooth[index] === null || minusSmooth[index] === null) continue;
// Wilder smoothing only reaches zero when every bar so far had no range: no direction to show yet.
if (!(total > 0)) continue;
plusDi[index] = (100 * plusSmooth[index]) / total;
minusDi[index] = (100 * minusSmooth[index]) / total;
const sum = plusDi[index] + minusDi[index];
directional[index] = Math.abs(plusDi[index] - minusDi[index]) / (sum === 0 ? 1 : sum);
}
const adx = ta.rma(directional, inputs.adxSmoothing).map((value) => (value === null ? null : 100 * value));
const hidden = new Array(count).fill(null);
return {
plots: { adx, plusDi: inputs.showDi ? plusDi : hidden, minusDi: inputs.showDi ? minusDi : hidden },
levels: { trend: inputs.trendLevel },
};
},
};Adapt it with an LLM
Paste this into your assistant and replace the second-to-last line with the change you want.
Start from this Spectral custom indicator: https://spectral.trade/indicators/adx-dmi.js Format reference: https://spectral.trade/docs/custom-indicators.llm.md Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match. Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow. Change I want: <describe the change> Answer with the complete file in one code block, ready to save as <id>.js.


