Average Directional Index (DMI) ADX
Average Directional Index — the smoothed absolute difference between +DI and −DI over their sum, so it rises when one direction dominates regardless of which.
It measures trend STRENGTH and says nothing about direction; direction is what the two DI lines carry. Conventional readings: above about 25 as trending and below about 20 as ranging, with the ADX's own slope read as strength building or fading. The two conventions are two ALGORITHMS here, not two settings: MT5's plain iADX smooths with an EMA recursion seeded at zero and normalises the up and down moves by each BAR's true range before smoothing, while TA-Lib uses Wilder's smoothing on the classic mean seed and smooths the moves and true range separately. MT5's other ADX — Wilder's — is a third computation and is its own entry here rather than a convention of this one.
01The study, live
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. ADX 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 16.45 and 62.17 on these bars, and the last value is 31.34. 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 once; crosses below 20 once; crosses above 25 3 times; crosses below 25 3 times; +DI crosses above −DI 4 times; +DI crosses below −DI 4 times. Press a condition under the figure to see each place marked. As states rather than moments: is above 20 on 252 bars; is below 20 on 21 bars; is above 25 on 231 bars; is below 25 on 42 bars; +DI is above −DI on 158 bars; +DI is below −DI on 128 bars.
02Its parts, named
03What you see
Three lines in a pane: +DI and −DI, how much of the recent range was upward and downward movement, and ADX, how strong the difference between them has been — regardless of direction.
04Where it comes from
J. Welles Wilder introduced the Directional Movement System in his 1978 book. The ADX was his answer to a question his other studies could not answer: is there a trend at all?
05The formula
Directional movement per bar:
+DM = Hₜ − H_(t−1), −DM = L_(t−1) − Lₜ
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·(smoothed(+DM))/ATR, −DI = 100·(smoothed(−DM))/ATR, DX = 100·(| +DI − (−DI) |)/(+DI + (−DI))
and ADX is DX smoothed over (14).
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. From the next bar on, each total drops a third of itself and adds the new bar's figure. On bar 4 (0, 0 and 3): +DM = 3 − 1 + 0 = 2.00 and the true range = 7 − 2.33 + 3 = 7.67.
+DI = 100 × 2.00 / 7.67 = 26.09 and −DI = 100 × 0 / 7.67 = 0.00
On bar 5 the totals again drop a third and add the new bar (1, 0 and 4): +DM becomes 2.33, the true range 9.11, and +DI = 25.61.
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.
ADX is Wilder's average of DX. With a period of 3 it starts as the plain average of the first three DX values and then moves a third of the way to each new one: an ADX of 60.00 meeting a DX of 100.00 becomes 60.00 + (100.00 − 60.00) / 3 = 73.33. On these eight bars every DX is 100, so the ADX itself reads 100.00 from its first value on.
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.
//@version=6 indicator("Average Directional Index (DMI)") length = input.int(14, "Length") upMove = high - high[1] downMove = low[1] - low // A bar's directional movement counts only on the side that moved further, and only if it moved out. 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 totals: the first length - 1 bars added up, then each bar keeps // (length - 1) / length of the total and adds its own. 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 // Each side's movement as a share of the bars' whole movement. plusDI = bar_index >= length ? 100 * (plusSum / rangeSum) : na minusDI = bar_index >= length ? 100 * (minusSum / rangeSum) : na // How one-sided the movement is, whichever side it is on. dx = 100 * (math.abs(minusDI - plusDI) / (minusDI + plusDI)) // The ADX starts as the plain average of the first `length` DX values, then is smoothed Wilder's way. var float dxSum = 0.0 var float adx = na if bar_index >= length and bar_index < 2 * length dxSum += dx if bar_index == 2 * length - 1 adx := dxSum / length else if bar_index >= 2 * length adx := adx - (adx - dx) / length plot(adx, "ADX") plot(plusDI, "+DI") plot(minusDI, "-DI")
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
ADX above 20–25 is read as a trending market; below 20 as a ranging one. A rising ADX as the trend strengthening — in either direction.
+DI above −DI is read as upward movement having dominated recently; a cross of the two as the dominant direction changing.
ADX turning down from a high level is read as the trend's strength fading, not necessarily the trend ending.
How a rising ADX fails. A rising line says the gap between the two directional lines has been widening. It keeps rising for a while after the move has stopped, because it is a smoothing of a smoothing; the highest ADX readings usually come after the fastest part of a trend.
How the 20 and 25 levels fail. They are conventions from daily commodity charts. On another period or market the line may live entirely above or below them.
How a falling ADX fails. A falling line says direction is fading, which is how both a quiet range and the pause before a continuation look.
09In different markets and timeframes
The ADX answers one question — is there a trend — and answers it late, because it is a smoothing of a smoothing. It rises in sustained moves of either direction and falls in ranges and at reversals alike. On low timeframes it is erratic; Wilder's levels come from daily commodity data.
10With other studies
Read with its two directional lines, which supply the direction it lacks; as a switch between trend-following studies (averages, MACD) and range studies (RSI, stochastics); and beside the Choppiness Index and the Efficiency Ratio, which ask the same question in other ways.
11What it does not tell you
ADX has no direction: a strong fall raises it as much as a strong rise. It is built from three layers of smoothing and turns late.
12Inputs and defaults
- 1Period — 14The window of Wilder's smoothing. Longer: a steadier line that reacts late. Shorter: quick and erratic. Wilder's own figure is 14.
- 2Smoothing — 14The number of candles the index is smoothed over. Left alone, it is the period of the two directional lines.
- 3Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 4Calculation — TA-LibOr MT5, which computes it as MetaTrader 5 does — see the calculation convention below.
- 5Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.
What each input changes
- CalculationTA-Lib seeds Wilder's sums as Wilder did; MetaTrader 5's ADX uses exponential averages instead. The two differ throughout, most at the start.
- SmoothingThe number of candles the ADX line itself is smoothed over. Left as it is, it is the period of the two DI lines; a shorter smoothing makes the ADX turn sooner without changing +DI and −DI.
- In use14 is Wilder's. 7 to 10 for a quicker, noisier line; 20 and more for a slow one that seldom reaches 25.
13Calculation convention
This is one of the studies whose result differs between the two conventions Bentrix offers. The difference is in how the first values are seeded and how the series is smoothed, so the two agree after the warm-up and differ at its start. Choose it on the settings card's Calculation row.
defaultTA-Lib
The convention of the TA-Lib library, which most charting software follows.
MT5
Computed as MetaTrader 5 computes it, so a value matches the terminal's own.
14Limits and common misreadings
TA-Lib and MetaTrader 5 smooth the ADX differently, so their values differ, most at the start; ADX Wilder is MetaTrader's version of Wilder's own smoothing. See Calculation convention.
15Conditions an alert or a strategy can watch
an event happens on one bar 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.
16Practise it in the laboratory
Put ADX 14 on a chart and replay a strong trend through to its end. Note the bar where price made its extreme and the bar where the ADX made its own; count the bars between them.
Open the laboratory18On pages of their own
19In Bentrix
- From the menu: a chart's Indicators button › Trend strength › ADX, or type ADX in its search.
- Its settings: the settings card opens when it is added; its legend's name opens it again.
20From 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": "adx"}).
The study, as a chart files it
This is a new ADX’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": "adx",
"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": "adx",
"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": "adx", "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"])JavaScript
const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "talib", "kind": "adx", "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#
var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "talib", ["kind"] = "adx", ["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"]!}");
}Go
values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "talib", "kind": "adx", "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", "adx", "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++
auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "talib"}, {"kind", "adx"}, {"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" => "adx", "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"])
endR
values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "talib", kind = "adx", 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")
}Rust
let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "talib", "kind": "adx", "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 itslinename and itsvalues;values[i]belongs to the candle attimes[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.
nullis 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].
line | What it is |
|---|---|
Main | the indicator's own value |
PlusDi | the directional movement up (+DI) |
MinusDi | the directional movement down (−DI) |
In a strategy
Filed under a key of your choice in a strategy document’s studies — here adx: {"adx": {"applied": "close", "convention": "talib", "kind": "adx", "settings": {"period": 14, "shape": "period"}}} — its rules can name:
| Write | What it is |
|---|---|
adx | its main line, as a value in a compare |
adx.plus_di | this line, as a value in a compare |
adx.minus_di | this line, as a value in a compare |
{"cond": "adx:level.cross_up:20"} | a condition it declares itself |
{"cond": "adx:level.cross_down:20"} | a condition it declares itself |
{"cond": "adx:level.above:20"} | a condition it declares itself |
{"cond": "adx:level.below:20"} | a condition it declares itself |
{"cond": "adx:level.cross_up:25"} | a condition it declares itself |
{"cond": "adx:level.cross_down:25"} | a condition it declares itself |
{"cond": "adx:level.above:25"} | a condition it declares itself |
{"cond": "adx:level.below:25"} | a condition it declares itself |
{"cond": "adx:di.cross_up"} | a condition it declares itself |
{"cond": "adx:di.cross_down"} | a condition it declares itself |
{"cond": "adx:di.above"} | a condition it declares itself |
{"cond": "adx:di.below"} | a condition it declares itself |
21Sources
- 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