Explainers / ADX and DI
ADX and DI, explained from the source
"ADX and DI for v4" by BeikabuOyaji is one of the most-boosted free scripts on TradingView, with more than 45,000 boosts. It draws three lines: a green DI+, a red DI- and a navy ADX, plus a flat line at 20. Its DI+ and DI- are the standard ones, but its ADX is not: it averages DX with a simple 14-bar average instead of Wilder's smoothing, so it will not match TradingView's built-in DMI indicator.
How to read the three lines
- DI+ measures how much of the recent range came from highs pushing above the previous high.
- DI- measures how much came from lows pushing below the previous low.
- ADX measures how far apart DI+ and DI- are, averaged over time. It says how one-sided the movement has been, not which side. A high ADX with DI- on top is a strong move down.
The usual reading is: DI+ above DI- means upward movement has dominated, DI- above DI+ means downward, and ADX above a threshold (this script draws 20) means that dominance has been strong. Those are descriptions of the past 14 bars, not forecasts.
What the code does
| Step | This script | TradingView's built-in DMI | ||
|---|---|---|---|---|
| True range, +DM, -DM | standard Wilder definitions | the same | ||
| Smoothing of TR, +DM, -DM | Wilder's running sum (sum - sum/14 + new) | Wilder's average (RMA) | ||
| DI+ and DI- | smoothed DM / smoothed TR x 100 | the same | ||
| DX | \ | DI+ - DI-\ | / (DI+ + DI-) x 100 | the same |
| ADX | simple 14-bar average of DX | Wilder's average (RMA) of DX |
The running sum is 14 times the Wilder average, and the 14 cancels when DM is divided by TR, so DI+ and DI- come out the same as the built-in once the start of the chart is behind you. In our simulation they matched to the 13th decimal place, and every DI cross fell on the same bar.
The ADX is where they part. A simple average gives each of the last 14 DX values equal weight and drops the 15th entirely; Wilder's average keeps a fading memory of all of them. On the same prices, in our simulation:
- the two ADX lines were about 4 points apart on average, and more than 10 points apart on 1 bar in 20;
- they disagreed about whether ADX was above 20 on about 1 bar in 10;
- the simple-average version crossed 20 about a quarter to a third more often, and only about one cross in six happened on the same bar in both.
So if you compare this script with the built-in DMI, or with ADX on another platform, a different number is expected. Neither is a bug; they are two definitions.
The start of the chart
The script fills missing previous values with zero. On the very first bar of the chart, "previous close" is therefore 0, so that bar's true range and +DM are the whole price. That oversized first value fades by 13/14 each bar. In our test series (prices near 100, bars about 1% wide) DI+ and DI- were more than 1 point off for the first 76 to 83 bars, and ADX over its first 40 bars was off by about 50 points on average. The warm-up is longer when the bars are narrow compared with the price.
This only matters where the chart starts: a newly listed symbol, a monthly or weekly chart with little history, or the first screen of a long backtest. Ignore the first hundred or so bars.
The settings
| Setting | Default | What it does |
|---|---|---|
| len | 14 | the length of the DI smoothing and of the ADX average |
| th | 20 | where the flat line is drawn; nothing else uses it |
One length drives both steps. The built-in DMI lets you set DI length and ADX smoothing separately.
Does it repaint?
No more than any indicator calculated on the current bar. It uses no higher-timeframe data. While a bar is open, its DI and ADX values move with price and settle when the bar closes, so a cross seen mid-bar can disappear. More in what repainting is and how to check a script yourself.
Where it fails
- Its ADX is not Wilder's ADX. The simple 14-bar average differs from the built-in DMI by about 4 points on average and crossed 20 a quarter to a third more often in our simulation.
- The first ~100 bars are wrong. Zero-filled previous values inflate the first bar; ignore the start of the chart.
- The 20 line is decoration. There are no alerts and no colour change when ADX crosses it.
- One length for two jobs. DI smoothing and ADX averaging cannot be set separately.
- ADX has no direction. A rising ADX can be a strengthening move down as easily as up.
- It describes the last 14 bars. DI crosses and ADX levels come after the movement they describe; there is no test of any setting here.
Also explained: Supertrend · Squeeze Momentum · CM MacD MTF · Repainting
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. ADX and DI for v4 is by BeikabuOyaji on TradingView, published under the Mozilla Public License 2.0; this page explains its published open-source code and is not affiliated with the author. Simulation figures come from synthetic random-walk prices and say nothing about how the indicator trades.
Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, HalfTrend, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue
Get the next teardown by email
One short email when a new teardown or free tool goes live, about twice a month. No signals, no hype. Unsubscribe in one click.
Almost done. Check your inbox and click the confirmation link.
Sent with Kit. Your address is used only for these emails. Privacy
No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.