Bentrix Docs
HomePricingDashboard

Directional Movement Index DX

Trend strengthoscillatorone linein every package

The raw directional index, the absolute difference between +DI and −DI over their sum, before any smoothing.

It measures the same imbalance ADX measures; ADX is the Wilder average of this. It reacts a full smoothing stage earlier and reverses far more often, which is the trade the two make.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
2025
bar —O — H — L — C —main line —first value at —
Show where:

Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.

What this figure shows

The figure is computed over 300 sample bars. DX has no value on the first 14 — the bars it needs before it can answer — and its first value stands on bar 15. Its line runs between 1.72 and 76.79 on these bars, and the last value is 27.51. The pane's scale is fixed at 0 to 100, the range the study can take. Counting the conditions the study declares on these bars: crosses above 20 15 times; crosses below 20 15 times; crosses above 25 14 times; crosses below 25 14 times. Press a condition under the figure to see each place marked. As states rather than moments: is above 20 on 238 bars; is below 20 on 48 bars; is above 25 on 214 bars; is below 25 on 72 bars.

02Its parts, named

The bars it readseach bar's open, high, low and closeWarm-upno value on the first 14 bars: thestudy needs them before it cananswerThe main linethe study's own value on each barLevel 25a fixed reference the study is readagainstLevel 20a fixed reference the study is readagainst
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

DX is the unsmoothed directional index, before ADX averages it.

DX is one line in a pane of its own, between 0 and 100, with levels at 20 and 25. It is jagged: it jumps from bar to bar where the ADX, its average, moves in long arcs. It is high when one of the two directional lines stands well above the other, whichever of them it is.

04Where it comes from

J. Welles Wilder introduced it in New Concepts in Technical Trading Systems (1978) as one layer of his Directional Movement System — the same book that gave the RSI, the ATR and the Parabolic SAR. DX is the step between the two directional lines and the ADX: the size of the gap between +DI and −DI, as a share of their sum.

05The formula

Directional movement per bar:

+DM=Ht−Ht−1,−DM=Lt−1−Lt

keeping only the larger of the two (the other set to zero, both zero if negative). Smoothed by Wilder's method and divided by the ATR:

+DI=100·+DM~ATR,−DI=100·−DM~ATR,DX=100·|+DI−(−DI)|+DI+(−DI)
Ht, Ltthis bar's high and low; t−1, the bar before
+DM, −DMthe upward and downward directional movement of the bar
x~x smoothed Wilder's way over N bars
ATRthe average true range over the same N
+DI, −DIthe two directional lines, in per cent

06A worked example

The sample bars used here are eight: closes 20, 21, 23, 22, 24, 25, 24, 26; highs 21, 22, 24, 24, 25, 26, 26, 27; lows 18, 19, 20, 21, 21, 23, 23, 23; opens 19, 20, 21, 23, 22, 24, 25, 24.

Take a period of 3. From each bar to the next, the up-move is the rise of the high and the down-move the fall of the low; the larger of the two, if it is positive, is that bar's directional movement, and the other is zero.

For bars 2 to 4 the highs rose by 1, 2, 0 and the lows fell by -1, -1, -1 (a negative number is a rise). So +DM is 1, 2, 0 and −DM is 0, 0, 0; the true ranges are 3, 4, 3.

Wilder's running totals begin as the sums over the first two of those bars (the period less one): +DM = 1 + 2 = 3, −DM = 0, true range = 3 + 4 = 7. On bar 4 each total drops a third of itself and adds the new bar's figure (0, 0 and 3): +DM = 2.00, −DM = 0.00, true range = 7.67. So +DI = 100 × 2.00 / 7.67 = 26.09 and −DI = 0.00.

DX = 100 × |26.09 − 0.00| / (26.09 + 0.00) = 100.00

All of the directional movement in this window was upward, so DX is at its ceiling. It says nothing about which way: the mirror image of these bars gives the same 100.

One bar later +DI is 25.61 and −DI 0.00: DX = 100.00. A single bar can move DX a great deal, which is the reason Wilder averaged it into the ADX.

07Built in Assay

The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.

THE SCRIPT’S GRAPH
//@version=6
indicator("Directional Movement Index")
length = input.int(14, "Length")
upMove = high - high[1]
downMove = low[1] - low
// A bar's directional movement is the larger of its rise above the last high and its fall below the last low.
plusDM = upMove > downMove and upMove > 0 ? upMove : 0.0
minusDM = downMove > upMove and downMove > 0 ? downMove : 0.0
trueRange = math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1]))
// Wilder's running sums: the first is a plain sum, then each bar drops one part in `length` and adds the new bar.
var float plusSum = 0.0
var float minusSum = 0.0
var float rangeSum = 0.0
if bar_index > 0 and bar_index < length
    plusSum += plusDM
    minusSum += minusDM
    rangeSum += trueRange
else if bar_index >= length
    plusSum := plusSum - plusSum / length + plusDM
    minusSum := minusSum - minusSum / length + minusDM
    rangeSum := rangeSum - rangeSum / length + trueRange
plusDI = bar_index >= length ? 100 * (plusSum / rangeSum) : na
minusDI = bar_index >= length ? 100 * (minusSum / rangeSum) : na
// The gap between the two directional lines, as a share of their sum.
dx = 100 * (math.abs(minusDI - plusDI) / (minusDI + plusDI))
plot(dx, "DX")
hline(20)
hline(25)

Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.

08Readings — what traders look for

+DI above −DI is read as upward movement having dominated recently; a cross of the two as the dominant direction changing.

How a high DX fails. It says the two directional lines are far apart on this bar. Unsmoothed, it leaps and collapses within a few bars; a single wide bar in either direction is enough.

Against the ADX. DX above the ADX pulls the ADX up, below pulls it down; DX is where the ADX is heading. It fails as a guide when DX is whipping across the ADX every bar.

09In different markets and timeframes

DX is the raw gap between the directional lines and jumps from bar to bar; it is readable only in strong, clean moves. It is the ADX's input rather than a study to read alone.

10With other studies

Read beside the ADX, which is DX averaged: DX above the ADX pulls it up, below pulls it down.

11What it does not tell you

!

DX has no direction: +DI far above −DI and −DI far above +DI give the same value. And it has no memory — it is one bar's comparison of two smoothed lines, which is why Wilder did not read it directly.

12Inputs and defaults

DX (14, Chart)settings card
1Period14
2TimeframeChart
3Wait for the candle to closeOn
  1. 1
    Period — 14The window of Wilder's smoothing. Longer: a steadier line that reacts late. Shorter: quick and erratic. Wilder's own figure is 14.
  2. 2
    Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
  3. 3
    Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.

The settings in use

  • In use14.

13Limits and common misreadings

Unstable when both DI lines are small. In a quiet market the sum in the denominator is tiny and a small difference gives a large DX.

It is the ADX's raw material. Readings quoted as trend strength in books and platforms are of the ADX, not of DX; the two are not interchangeable.

14Conditions an alert or a strategy can watch

crosses above 20 eventcrosses below 20 eventis above 20 stateis below 20 statecrosses above 25 eventcrosses below 25 eventis above 25 stateis below 25 state

Event: the bar it happens on an event happens on one barState: every bar while it holds a state holds on every bar while it lasts

These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.

15Practise it in the laboratory

Put DX 14 and ADX 14 in one pane and watch the ADX follow the DX at a distance through a trend's start.

Open the laboratory

17In Bentrix

  • From the menu: a chart's Indicators button › Trend strength › DX, or type DX in its search.
  • Its settings: the settings card opens when it is added; its legend's name opens it again.

18From an agent or a program

Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "dx"}).

The study, as a chart files it

This is a new DX’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.

{
  "applied": "close",
  "convention": "talib",
  "kind": "dx",
  "settings": {
    "period": 14,
    "shape": "period"
  }
}

An agent

An agent calls the MCP tool with it:

{
  "name": "study_values",
  "arguments": {
    "bench": "bentrix://lab/\u2026/bench/\u2026",
    "symbol": "EURUSD",
    "timeframe": "H1",
    "limit": 5,
    "study": {
      "applied": "close",
      "convention": "talib",
      "kind": "dx",
      "settings": {
        "period": 14,
        "shape": "period"
      }
    }
  }
}

A program

A program does the same in its language — bench and market as in the built-in indicators guide:

Python

values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "talib", "kind": "dx", "settings": {"period": 14, "shape": "period"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
    print("line:", line["line"])
    print("  newest values:", line["values"])

JSJavaScript

const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "talib", "kind": "dx", "settings": { "period": 14, "shape": "period" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
  console.log("line:", line.line);
  console.log("  newest values:", line.values);
}

C#C#

var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "talib", ["kind"] = "dx", ["settings"] = new Dictionary<string, object?> { ["period"] = 14, ["shape"] = "period" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
    Console.WriteLine($"line: {line!["line"]!}");
    Console.WriteLine($"  newest values: {line!["values"]!}");
}

GOGo

values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "talib", "kind": "dx", "settings": map[string]any{"period": 14, "shape": "period"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
	fmt.Println("line:", at(line, "line"))
	fmt.Println("  newest values:", at(line, "values"))
}

Java

Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "talib", "kind", "dx", "settings", obj("period", 14, "shape", "period"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
    System.out.println("line:" + " " + at(line, "line"));
    System.out.println("  newest values:" + " " + at(line, "values"));
}

C++C++

auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "talib"}, {"kind", "dx"}, {"settings", Json::Object{{"period", 14}, {"shape", "period"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
    std::cout << "line:" << " " << line["line"].dump() << std::endl;
    std::cout << "  newest values:" << " " << line["values"].dump() << std::endl;
}

Julia

values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "talib", "kind" => "dx", "settings" => Dict{String,Any}("period" => 14, "shape" => "period")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
    println("line:", " ", line["line"])
    println("  newest values:", " ", line["values"])
end

RR

values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "talib", kind = "dx", settings = list(period = 14, shape = "period")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
  cat("line:", format(line$line), "\n")
  cat("  newest values:", format(line$values), "\n")
}

RRust

let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "talib", "kind": "dx", "settings": {"period": 14, "shape": "period"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
    println!("line: {}", line["line"]);
    println!("  newest values: {}", line["values"]);
}

Reading the answer

  • times — the candles’ open times, in milliseconds since 1970 (UTC), oldest first.
  • lines — one entry per line, in this order, each with its line name and its values; values[i] belongs to the candle at times[i].
  • The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
  • null is a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
  • Its fixed levels, drawn on the chart: [20.0, 25.0].
lineWhat it is
Mainthe indicator's own value

In a strategy

Filed under a key of your choice in a strategy document’s studies — here dx: {"dx": {"applied": "close", "convention": "talib", "kind": "dx", "settings": {"period": 14, "shape": "period"}}} — its rules can name:

WriteWhat it is
dxits main line, as a value in a compare
{"cond": "dx:level.cross_up:20"}a condition it declares itself
{"cond": "dx:level.cross_down:20"}a condition it declares itself
{"cond": "dx:level.above:20"}a condition it declares itself
{"cond": "dx:level.below:20"}a condition it declares itself
{"cond": "dx:level.cross_up:25"}a condition it declares itself
{"cond": "dx:level.cross_down:25"}a condition it declares itself
{"cond": "dx:level.above:25"}a condition it declares itself
{"cond": "dx:level.below:25"}a condition it declares itself

19Sources

  1. Wilder, J. Welles Jr. New Concepts in Technical Trading Systems. Trend Research, 1978.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed