Skip to content

Free MT5 Expert Advisor

ADX DMI EA

MT5 Expert Advisor that trades +DI/-DI crossovers only when ADX is above a threshold and rising, with an ATR stop and R target.

Trendv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Stop-loss on every trade
Strategy
Buys when +DI crosses above -DI while ADX is above 25 and rising, and sells when -DI crosses above +DI under the same conditions. The stop is 1.5 x ATR and the target is 2R.
Risk model
1% of balance per trade (configurable), stop-loss on every order, one position at a time

What it does

The ADX DMI EA is built on Welles Wilder's Directional Movement system. The +DI and -DI lines measure upward and downward pressure; when they cross, direction may be changing. ADX measures how strong the trend is, regardless of direction.

The EA only acts on a DI crossover when ADX says a trend is present and strengthening. The aim is to avoid the many DI crosses that happen in quiet, directionless markets.

How it works

Signals are checked once per bar on the last closed bar using MetaTrader's built-in ADX.

  • Buy setup: +DI was at or below -DI two bars ago and is above it on the last closed bar.
  • Sell setup: -DI was at or below +DI and is now above it.
  • Strength filter: ADX on the signal bar must be at least 25.
  • Rising filter: ADX on the signal bar must be higher than on the bar before.
  • If either filter fails, the cross is ignored and the reason is printed.
  • Stop-loss: 1.5 x ATR(14). Take-profit: 2R. Exit: by default the position closes on the opposite DI cross.

How to use it

ADX-based systems are most useful on instruments that alternate between clear trending and ranging phases, such as major pairs, gold and indices on H1 or H4. Raising the ADX threshold makes the EA trade less often but only in stronger conditions; lowering it gives more trades and more noise.

Remember that ADX is direction-neutral: a high ADX in a falling market supports sell signals just as much as buy signals.

Settings

InputDefaultWhat it changes
ADX / DI period14Period of the ADX and directional indicators.
Minimum ADX value25Crosses are ignored while ADX is below this level.
Require ADX risingtrueADX must be higher than on the previous bar.
Stop-loss distance (x ATR)1.5Stop distance as a multiple of ATR(14).
Take-profit (R multiple)2.0Target as a multiple of the stop distance.
Exit on opposite crosstrueCloses the trade when the DI lines cross the other way.
Risk per trade (% of balance)1.0Share of balance risked between entry and stop.
Fixed lots0Fixed volume instead of risk %; 0 = risk-based.
Maximum spread (points)20Skips signals when the spread is wider; 0 = off.
Trading start / end hour7 / 20Server-time window for new trades; equal values = 24 hours.
Move stop to break-eventrueStop to entry + 20 points once profit reaches 1R.
Use trailing stopfalseTrails the stop 2 x ATR behind price.
Magic number2611004Identifies this EA's trades.

Limitations

  • ADX is heavily smoothed and lags; it often peaks after the strongest part of a move.
  • Requiring a rising ADX at the exact bar of a DI cross is strict and can skip valid trends.
  • DI lines can cross several times in a row around the threshold, producing quick losses.
  • No adjustment is made for news releases, when ATR and spreads can jump.

Before you run it live

Test on a demo account and in the MetaTrader 5 Strategy Tester over several years first. No backtest results are published for this EA, and any test describes the past only.

  • Match the spread limit and trading hours to your broker's spreads, stop level and session times, and include commission and swap in tests.
  • Start with 1% risk or less and check the lot sizes in the Experts log; the Position Size Calculator is a useful cross-check.
  • Use a different magic number on each chart, and keep the terminal (or a VPS) running so stops are managed.

Try a few ADX thresholds in the Strategy Tester, but avoid fine-tuning until the history looks perfect; that rarely carries forward.

Key inputs

Key inputs of ADX DMI EA
InputDefaultDescription
ADX / DI period14Period of the ADX and directional indicators.
Minimum ADX value25Crosses are ignored while ADX is below this level.
Require ADX risingtrueADX must be higher than on the previous bar.
Stop-loss distance (x ATR)1.5Stop distance as a multiple of ATR(14).
Take-profit (R multiple)2.0Target as a multiple of the stop distance.
Risk per trade (% of balance)1.0Share of balance risked between entry and stop.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors