Directional Movement DMI with Cross Alerts
- 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 is a TV-compatible Directional Movement Index (DMI) for MetaTrader 5. It calculates ADX, +DI and -DI in the same way as the "Directional Movement Index" built into TradingView and draws them with the same default colors in a separate window: ADX (#F50057), +DI (#2962FF) and -DI (#FF6D00).
DMI describes how strong the recent movement has been (ADX) and which side has moved more (+DI or -DI). It is a charting aid, not a buy or sell signal, and it does not predict where price will go.
HOW IT IS CALCULATED
- up = high - previous high, down = previous low - low. +DM = up when up > down and up > 0, otherwise 0. -DM = down when down > up and down > 0, otherwise 0.
- TR = true range: the largest of high - low, |high - previous close| and |low - previous close|.
- +DI = 100 x RMA(+DM) / RMA(TR) and -DI = 100 x RMA(-DM) / RMA(TR), over DI Length (default 14).
- ADX = 100 x RMA(|+DI - -DI| / (+DI + -DI)), over ADX Smoothing (default 14).
- RMA is Wilder's smoothing, the same as TradingView's ta.rma(): the first value is a simple average, after that alpha = 1 / length.
- Values are compared with the same small tolerance (1e-10) that Pine Script uses, so a cross is found on the same bar as on TradingView even when two lines are almost equal.
HOW WE CHECKED IT
- We loaded TradingView's own price bars into MetaTrader and compared the output with TradingView's built-in DMI. ADX, +DI and -DI agreed to floating-point rounding (differences around 1e-12).
- On a broker's chart the values are a little different, because the prices come from a different data feed.
- Wilder smoothing starts at the oldest loaded bar. If your history starts at a different bar than TradingView's, the oldest part of the chart can differ slightly; the effect fades out as more bars are calculated.
DISPLAY
- Three lines in a separate window. Colors and line width (1 to 5) can be changed.
- Optional dashed ADX threshold line (default 25, gray). TradingView's built-in DMI does not have this line; it is an extra. 25 is only a common reference level, not a rule.
- Values are shown with 4 decimals, as on TradingView.
THE LATEST BAR (REPAINT)
- The bar that is still forming is recalculated on every tick, exactly like on TradingView. Its values can change until the bar closes.
- Once a bar has closed, its values do not change.
ALERTS (OFF BY DEFAULT)
- +DI / -DI cross: +DI crossed above or below -DI on the bar that has just closed.
- ADX threshold: ADX crossed above the threshold on the bar that has just closed (upward crosses only).
- Checked once per closed bar. Bars that closed before the indicator was loaded do not raise alerts, so attaching it or restarting MT5 does not produce old alerts.
- Message example: "DMI TV EURUSD H1: +DI crossed above -DI (+DI 27.41 / -DI 19.85)".
- Pop-up, sound and push notification can be combined. Push needs your MetaQuotes ID in the terminal options. Alert texts in English or Japanese.
FOR EA AND iCUSTOM USERS
- Buffer 0 = ADX, buffer 1 = +DI, buffer 2 = -DI. Bars without a value return EMPTY_VALUE. All three values also appear in the Data Window.
- When an EA or another indicator loads it through iCustom, it raises no alerts; it only calculates the buffers.
PLEASE READ BEFORE USE
- ADX needs DI Length + ADX Smoothing bars of history before it appears (28 bars with the defaults); +DI and -DI appear earlier.
- Right after loading, the short name in the indicator list may briefly show "probe#..." while the indicator checks whether it is on a chart. This is normal.
- In the Strategy Tester it raises no alerts.
- No DLLs, no external files, no internet connection.
- It does not trade, and no trading result is promised.
INPUTS
DMI: ADX Smoothing (14, 1-1000), DI Length (14, 1-1000)
Style: 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)
Alerts: 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)
If an input is out of range, the indicator does not load and writes the reason to the Experts log.
SUPPORT
Questions about installation, settings and bugs are welcome through MQL5 messages. Questions about market direction or individual trades are outside the support scope.
This is part of a series of free TV-style tools. An MT4 edition is also available as a separate product. 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.
