Directional Movement DMI with Cross Alerts MT4
- Indicators
-
Kazuma Uezono
MQL5 / MQL4 / Pine Script v6 developer and active trader.
Seller on the MQL5 Market (indicators for MT4/MT5).
Services:
- TradingView Pine Script to MT5/MT4 conversion (bar-by-bar matching, with tester report)
- MT4 to MT5 migration - Version: 1.0
Directional Movement DMI with Cross Alerts MT4 brings a TV-compatible DMI to MetaTrader 4. If you also chart on TradingView, you know its built-in "Directional Movement Index": a pink ADX line, a blue +DI line and an orange -DI line in a panel under the price. This MT4 indicator uses the same formula, the same defaults and the same colors.
What it is for: reading how strong the recent movement has been (ADX) and whether upward (+DI) or downward (-DI) movement has been larger. What it is not: a buy or sell signal or a forecast. A cross of the lines says nothing certain about what price will do next.
THE CALCULATION IN SHORT
Setting | Default | Same as TradingView?
ADX Smoothing | 14 | yes
DI Length | 14 | yes
Smoothing method | RMA (Wilder) | yes (same as ta.rma)
Threshold line | 25, dashed gray | extra (not in TradingView's DMI)
+DM and -DM come from the change of the high and the low against the previous bar (only the larger move counts, and only if it is positive). TR is the true range. +DI = 100 x RMA(+DM) / RMA(TR), -DI = 100 x RMA(-DM) / RMA(TR), ADX = 100 x RMA(|+DI - -DI| / (+DI + -DI)). Comparisons use the same 1e-10 tolerance as Pine Script, so crosses fall on the same bar as on TradingView.
DOES IT REPAINT?
Closed bars: no. Their ADX, +DI and -DI values are final.
The forming bar: yes, in the same way as on TradingView. It is recalculated on every tick until it closes. Alerts therefore look only at closed bars.
MT4 SETUP NOTES - PLEASE READ
1. Colors come from the inputs. Set "ADX line color", "+DI line color" and "-DI line color" in the Inputs tab; the Colors tab is overridden by these inputs.
2. ADX needs DI Length + ADX Smoothing bars (28 with the defaults) before it is drawn; +DI and -DI start earlier.
3. Right after loading, the name in the indicator list can briefly read "probe#..." while it checks that it is attached to a chart. This is normal.
4. MT4 shows the inputs without group headings, in the order listed below.
ALERTS
Off by default. Two independent switches:
- "Alert: +DI / -DI cross": one alert when a bar closes with +DI crossed above or below -DI;
- "Alert: ADX crosses above the threshold": one alert when a bar closes with ADX crossed above the threshold (upward only);
- never for bars that closed before the indicator was loaded, so a restart does not repeat old alerts;
- text example: "DMI TV GBPUSD H4: ADX crossed above 25.0 (ADX 25.63)";
- pop-up, sound and push (MetaQuotes ID required) can be combined; English or Japanese text (Language input).
- No alerts in the Strategy Tester.
COMPARED WITH TRADINGVIEW
We fed TradingView's own price bars into MetaTrader and compared the three lines with TradingView's built-in DMI: they agreed to floating-point rounding (differences around 1e-12). Your MT4 chart uses your broker's prices, which differ slightly from TradingView's feed, so expect small differences. Wilder smoothing starts at the oldest bar in your history; if that bar is not the same as on TradingView, the oldest part of the chart can differ a little, and the difference fades as more bars are calculated.
iCUSTOM BUFFERS
Buffer 0: ADX. Buffer 1: +DI. Buffer 2: -DI. EMPTY_VALUE where there is no value yet.
Called through iCustom, the indicator sends no alerts; it only fills the buffers. The inputs have no group headings, so pass the inputs in the order below.
INPUTS (MT4 ORDER)
ADX Smoothing = 14 (1-1000); DI Length = 14 (1-1000); ADX line color = #F50057; +DI line color = #2962FF; -DI line color = #FF6D00; Line width = 1 (1-5); Show ADX threshold line = true; ADX threshold = 25 (0-100); Threshold line color = #787B86; Alert: +DI / -DI cross = false; Alert: ADX crosses above the threshold = false; Alert by pop-up = true; Alert by sound = false; Alert by push notification = false; Language = Auto (terminal language), English or Japanese.
Out-of-range values stop the indicator from loading, with the reason in the Experts log.
GOOD TO KNOW
- The threshold value 25 is a common reference, not a rule. Change it or switch the line off as you like.
- No DLLs, no files, no internet access.
- This is an analysis tool. It does not open or close trades, and no trading result is promised.
SUPPORT
Help with installation, settings and bug reports via MQL5 messages. I do not answer questions about market direction or specific trades.
The MT5 edition (a separate product) and other tools by the same author are listed on my seller profile.
TradingView is a trademark of TradingView, Inc. This product is not affiliated with, sponsored by or endorsed by TradingView, Inc.
