ADX Trend EA MT5 — No Code

ADX > 25 plus a +DI / -DI cross: classic settings, how to build the rule in the Strategy Builder, and the iADX buffers in MQL5.

📖 7 min read

📝 1,391 words

🏷️ MQL5 and Expert Advisors

Share this article:

ADX Trend-Following EA for MT5 — No Code

Can I build an ADX trend-following EA for MT5 without coding?

Yes. ADX and its +DI / -DI lines are in the MT5 Strategy Builder, one of the 47 indicator types. Add ADX in Step 3 (Entry rules); the starter rule is ADX above 25 and +DI crossing above -DI for buy, mirrored for sell. Then set exits and risk and press Get the code in Step 7. If you prefer to hand-code the rule, one iADX handle gives you ADX, +DI and -DI (outline below).

Disclosure: Educational guide — not financial advice.

Related guides: ADX Indicator (academy) · MA Crossover EA — No Code · Build EA Without Coding · EA Strategy Library


What Is an ADX Trend-Following EA?

ADX (Average Directional Index) measures how strong a trend is — typically 0–100. It does not tell you up vs down by itself.

PartRole
ADXFilter: only trade when trend is strong (e.g. ADX > 25)
+DI / -DIDirection: +DI above -DI is bullish, -DI above +DI is bearish
SignalRule (starter)
BuyADX > 25 AND +DI crosses above -DI
SellADX > 25 AND -DI crosses above +DI

In MQL5, one iADX [1] handle returns all three lines.


Classic ADX Settings and When It Works

SettingStarter
DI length / ADX smoothing14 / 14 (builder defaults)
ADX Threshold25
TimeframeH1 or H4
SymbolEURUSD, GBPUSD

Works best: Established trends after ADX rises above 25.

Struggles in: Sideways markets — ADX below 25, whipsaw on +DI / -DI crosses. Restricting trading to liquid sessions helps.

ADX academy guide, with +DI, −DI and DMI.


ADX and DMI in MQL5

A hand-written EA needs one handle and three buffers:

BufferLine
0ADX (MAIN_LINE)
1+DI (PLUSDI_LINE)
2-DI (MINUSDI_LINE)
// OnInit
adxHandle = iADX(_Symbol, PERIOD_H1, 14);

// OnTick, once per new bar: read the last two closed bars
CopyBuffer(adxHandle, 0, 1, 2, adx);      // index 0 = older bar, 1 = last closed bar
CopyBuffer(adxHandle, 1, 1, 2, plusDi);
CopyBuffer(adxHandle, 2, 1, 2, minusDi);
bool strong  = adx[1] > 25.0;
bool buyCross  = plusDi[0] <= minusDi[0] && plusDi[1] > minusDi[1];
bool sellCross = minusDi[0] <= plusDi[0] && minusDi[1] > plusDi[1];

Read the values with CopyBuffer [2] on closed bars only, so the signal does not change while the current bar is still forming.


ADX in the Builder

In Step 3 (Entry rules) add the ADX indicator. It has three lines — ADX, +DI and -DI — and three settings: DI length (default 14), ADX smoothing (default 14) and Smoothing method (Wilder by default; the last two are under More settings). Write the buy rule as ADX is above 25 in the group All of these with +DI crosses above -DI; the sell rule mirrors it with -DI crossing above +DI (Sell mirrors Buy). Add a Market sessions filter in Step 4 and a stop loss in Step 5. For a trend EA without a strength gate, see MA Crossover EA — No Code.

Note: ATR measures volatility, not direction or trend strength, so it is not an ADX substitute.


Use ADX as a Trend Filter for Another Entry

ADX does not have to be the signal. Its other common job is a gate in front of an entry you already use. An MA cross on EURUSD H1 fires often in a sideways market — buy, sell four hours later, repeat — and each cross means little. ADX asks the question before the trade: is there enough trend strength right now?

ADX reading (typical)Market feelMA cross without a filter
Below ~20ChopMany false signals
20–25Emerging trendMixed
Above 25Trending enoughFewer, often cleaner

Two ways to build the gate:

  1. Step 3: keep the entry rule (the fast MA crosses above the slow MA — see MA Crossover EA — No Code) and put ADX is above 25 in the same group All of these. Direction comes from the MA cross; ADX only says yes or no.
  2. Step 4: the quick filter Only trade when there is a trend (ADX(14) above 25) applies the same gate to the whole strategy, whatever the entry rule.

Hand-coded, the gate is one more iADX [1] handle ANDed with the entry, read on the last closed bar:

// OnTick, once per new bar
CopyBuffer(adxHandle, 0, 1, 2, adx);   // buffer 0 = ADX main line
bool trendStrongEnough = adx[1] > 25.0;
bool entrySignal = /* your MA cross or other condition */;
bool takeTrade = entrySignal && trendStrongEnough;

Compile and Backtest

Compile your .mq5 (hand-written, or from Get the code in Step 7) with F7 → Strategy Tester Every tick [3] → Demo. If you use ADX as a filter, run the same test with and without the ADX gate to see its effect on trade count and drawdown.


Improvements: Filters and Risk

IssueFix
Too many +DI / -DI crossesRaise the ADX threshold to 30
Late entriesAdd a higher timeframe in Step 2 and read ADX from it, or lower the length
Range lossesSkip entries when ADX is < 20

Wilder's DMI cross with ADX: history and rules

Who and when: J. Welles Wilder, in his 1978 book.

J. Welles Wilder's Directional Movement system is also from his 1978 book. It has three lines, by default over 14 bars. +DI measures upward movement and −DI downward movement; ADX measures how strong the trend is, whatever its direction.

Wilder asked first for a trend: ADX above 25 (many traders use 20). Then for the direction: a buy when +DI crosses above −DI, a sell when −DI crosses above +DI. He set the first stop at the low of the signal day for a buy, and he kept the signal alive while that low held, even if the lines crossed back.

The rule as the source states it

ADX above 25. Buy when +DI crosses above −DI; sell when −DI crosses above +DI. First stop at the low of the signal day; the signal stays in force while that low holds. [4] [5] [6]

Our version

ADX and DI (14, 14, Wilder smoothing) on daily bars of a currency pair. Buy when +DI crosses above −DI and ADX is above 25. Sell short on the mirror. An opposite signal closes the trade and reverses it.

How ours differs

  • The stop is our default distance, not the low of the signal day.
  • Ours reverses on the opposite cross; Wilder held the trade while the signal day's low held.
  • Like every library file, ours also adds the builder's default stop, position size and account limits (Steps 5 and 6). You can change them in the form.

Needs the Starter plan or higher. Open in the builder →

Being well known says nothing about how a strategy will do. Test it on your own data.

Next Steps

References: MQL5 iADX [1] · CopyBuffer [2] · Strategy Tester [3].

Frequently Asked Questions

Yes. ADX and its +DI / -DI lines are in the MT5 Strategy Builder, one of the 47 indicator types. Add ADX in Step 3 (Entry rules): ADX above 25 and a +DI / -DI cross for buy, mirrored for sell. Then set exits and risk and press Get the code in Step 7. You can also code the rule yourself in MQL5 with iADX.

ADX measures trend strength, not direction. Direction comes from +DI and -DI: +DI above -DI is bullish, -DI above +DI is bearish. In MQL5, iADX returns all three lines from one handle.

Period 14 and threshold 25 are common starting values. Raise the threshold (30) for fewer trades; lower it (20) for more signals in choppy markets.

No. Educational template only. ADX filters reduce trades in ranges but do not eliminate losses. Backtest and Demo on your broker.

Yes. Keep your entry rule (an MA cross, for example) in Step 3 and add ADX is above 25 in the same All of these group, or use the Step 4 quick filter Only trade when there is a trend (ADX(14) above 25) for the whole strategy. Direction then comes from your entry signal; ADX only gates it on trend strength.

No. ATR measures volatility, not trend strength or direction. It can keep an EA out of very quiet markets, but it is not an ADX substitute. ADX itself is in the builder.

J. Welles Wilder, in his 1978 book. ADX and DI (14, 14, Wilder smoothing) on daily bars of a currency pair. Buy when +DI crosses above −DI and ADX is above 25. Sell short on the mirror. An opposite signal closes the trade and reverses it. Being well known says nothing about how a strategy will do. Test it on your own data.

References

  1. MetaQuotes, MQL5 Reference. iADX. https://www.mql5.com/en/docs/indicators/iadx
  2. MetaQuotes, MQL5 Reference. CopyBuffer. https://www.mql5.com/en/docs/series/copybuffer
  3. MetaQuotes. MetaTrader 5 Built-in Trading Strategy Tester. https://www.metatrader5.com/en/automated-trading/strategy-tester
  4. StockCharts ChartSchool. Average Directional Index (ADX). https://chartschool.stockcharts.com/table-of-contents/technical-indicators-and-overlays/technical-indicators/average-directional-index-adx
  5. Fidelity Learning Center. What Is DMI?. https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/dmi
  6. Open Library. J. Welles Wilder, New Concepts in Technical Trading Systems (1978). https://openlibrary.org/works/OL5039607W