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.
| Part | Role |
|---|---|
| ADX | Filter: only trade when trend is strong (e.g. ADX > 25) |
| +DI / -DI | Direction: +DI above -DI is bullish, -DI above +DI is bearish |
| Signal | Rule (starter) |
|---|---|
| Buy | ADX > 25 AND +DI crosses above -DI |
| Sell | ADX > 25 AND -DI crosses above +DI |
In MQL5, one iADX [1] handle returns all three lines.
Classic ADX Settings and When It Works
| Setting | Starter |
|---|---|
| DI length / ADX smoothing | 14 / 14 (builder defaults) |
| ADX Threshold | 25 |
| Timeframe | H1 or H4 |
| Symbol | EURUSD, 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:
| Buffer | Line |
|---|---|
| 0 | ADX (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 feel | MA cross without a filter |
|---|---|---|
| Below ~20 | Chop | Many false signals |
| 20–25 | Emerging trend | Mixed |
| Above 25 | Trending enough | Fewer, often cleaner |
Two ways to build the gate:
- 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.
- 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
| Issue | Fix |
|---|---|
| Too many +DI / -DI crosses | Raise the ADX threshold to 30 |
| Late entries | Add a higher timeframe in Step 2 and read ADX from it, or lower the length |
| Range losses | Skip 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
- MA Crossover EA — No Code — a simpler trend EA without a strength gate
- MACD + RSI Confluence
- Build EA Without Coding
References: MQL5 iADX [1] · CopyBuffer [2] · Strategy Tester [3].

