Forex
EA

EA: ADX Trend Strength Expert Advisor

Last updated 2026-07-17

An Expert Advisor (EA) is different from every other download on this site — an indicator only plots a line or fires an alert, while an EA actually sends orders on your behalf. This free EA trades a trend-following strategy built around ADX and its two companion lines, +DI and -DI: it watches for a directional cross between +DI and -DI, but only acts on that cross when ADX itself confirms a genuinely strong trend is underway. Stop Loss, Take Profit, and position size are then all handled automatically using the same volatility- and risk-based tools taught elsewhere on this site.

How the Strategy Works

The raw entry signal is a +DI/-DI cross: +DI (Plus Directional Indicator) measures upward price pressure, -DI (Minus Directional Indicator) measures downward price pressure, and whichever one is currently above the other is, in theory, in control of price. When +DI crosses above -DI, buyers have just taken over from sellers; when -DI crosses above +DI, the reverse. On their own, though, these two lines cross constantly in a quiet, directionless market — they hover close together and swap places every few bars without any real trend developing, which makes the raw crossover a noisy, low-quality signal by itself.

That's where ADX comes in. ADX doesn't say which direction price is moving — it says how strong the current trend is, on a scale of 0-100, regardless of direction. This EA only acts on a +DI/-DI cross when the current ADX reading is at or above TrendLevel (default 25.0), a threshold widely treated as the boundary between a choppy market and a market with an established trend. In practice this means the EA is not simply "buy when +DI crosses -DI" — it is "buy when +DI crosses -DI and the broader market is already proving, through ADX, that one side is dominating." That single extra condition is what separates this EA from a much noisier version of itself, and it's the core idea the rest of this lesson builds on.

Stop Loss, Take Profit, and Position Sizing

PriceTake Profit (TP)Stop Loss (SL)BUY25ADX / +DI / -DI (0–100)ADX+DI-DI
Entry conditions: BUY when +DI crosses above -DI while ADX is above 25 — SELL on the mirrored cross — SL and TP are placed automatically from ATR

Both Stop Loss and Take Profit are sized from ATR rather than a fixed pip distance, so the stop always reflects how much a pair is actually moving right now instead of a number picked once and left unchanged. Stop Loss distance is ATRMultiplier × ATR (default multiplier 2.0, ATR calculated over ATRPeriod, default 14), and Take Profit is then set at RiskRewardRatio × Stop Loss distance (default 2.0) — so a BUY placed with a 20-pip ATR-based stop automatically gets a 40-pip target, and every trade this EA opens, on any pair or timeframe, carries the same fixed reward-to-risk proportion.

Position size follows the exact worked-example method from Risk Management Basics: RiskPercent (default 1.0%) of account balance is divided by the Stop Loss distance to produce a lot size, so the dollar amount at risk stays roughly constant trade to trade even though the ATR-based stop distance itself changes as volatility changes. A wide stop on a volatile pair yields a smaller lot; a tight stop on a calm pair yields a larger one. The calculated lot is normalized to the broker's minimum, maximum, and step lot size before the order is sent. UseFixedLot is available as an escape hatch for traders who would rather trade a constant lot size regardless of account risk — useful for testing, or for small accounts where percentage-based sizing would otherwise round down to the broker's minimum lot anyway.

Entry Conditions

  • BUY — +DI crosses above -DI on the just-closed bar, and the current ADX reading is at or above TrendLevel (default 25.0).
  • SELL — -DI crosses above +DI on the just-closed bar, and the current ADX reading is at or above TrendLevel — the mirrored setup.

If a DI cross happens while ADX is still below the threshold, the EA simply does nothing — the cross is logged internally as "seen" but never acted on, because the market hasn't yet proven it's trending strongly enough to trust the signal. Beyond the ADX filter itself, three safety mechanics govern every trade this EA can place: it evaluates entry conditions once per new bar only (tracked via the bar's open time), so a single cross can't trigger repeated trades within the same candle; it opens only one position at a time, checked by counting open trades filtered to this EA's own symbol and magic number before any new entry is considered; and it checks the current spread against MaxSpreadPoints (default 30) before sending an order, skipping the entry entirely if the spread is too wide to trade at a reasonable price. Every order is tagged with MagicNumber (default 20260728), so the EA's position-counting logic — and any future management logic — never touches a trade you opened manually or a trade placed by a different EA running on the same account.

Parameters

  • ADXPeriod (default 14) — the lookback used to calculate ADX, +DI, and -DI. Shorter periods react faster but produce more crosses; longer periods are smoother but slower to confirm a trend.
  • TrendLevel (default 25.0) — the minimum ADX reading required before a +DI/-DI cross is acted on. Raising it (e.g. to 30-35) demands a stronger, more established trend and produces fewer, higher-conviction trades; lowering it (e.g. to 20) lets more crosses through, including some from trends that are still forming.
  • ATRPeriod (default 14) — the lookback used to calculate ATR for Stop Loss sizing.
  • ATRMultiplier (default 2.0) — Stop Loss distance = ATR × this multiplier.
  • RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance × this ratio.
  • UseFixedLot — switches position sizing from risk-based to a constant lot size.
  • FixedLotSize (default 0.01) — the lot size used when UseFixedLot is enabled.
  • RiskPercent (default 1.0) — percentage of account balance risked per trade, used to calculate lot size when UseFixedLot is disabled.
  • MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this, to avoid opening trades at a bad price during illiquid conditions.
  • MagicNumber (default 20260728) — tags every order this EA places so its position-management logic never touches trades opened by hand or by a different EA.
  • EnableTrading — a master on/off switch, useful for pausing the EA without removing it from the chart.

Why Filter DI Crosses by ADX

This is the single design choice this whole EA is built around, so it's worth spelling out why it exists rather than treating it as a throwaway detail. A +DI/-DI cross by itself only tells you that upward pressure has just edged out downward pressure, or vice versa — it says nothing about how convincingly. In a tight, range-bound market, price chops back and forth around a flat average, and +DI and -DI trade places constantly as first buyers and then sellers briefly gain the upper hand for a few candles before losing it again. A strategy that traded every one of those crosses would open and close positions repeatedly in a market that isn't actually going anywhere, paying spread and slippage on each false start with no real trend ever developing to pay for it.

ADX solves this because it measures something a DI cross alone cannot: persistence. ADX only climbs when one side — buyers or sellers — keeps winning candle after candle; it stays low and flat when the two sides keep swapping control, exactly the condition that produces frequent, low-quality DI crosses. Requiring ADX to be at or above 25 before acting on a cross is effectively asking the market to first demonstrate, through its own directional consistency, that the cross is worth trusting. This filters out the majority of the false, back-and-forth crosses that occur during consolidation, and lets through the crosses that occur alongside (or shortly after) a market that has already shown it can sustain a move in one direction. The tradeoff is that this EA will sometimes enter a little later than a strategy trading raw DI crosses — a real trend has to build some evidence of itself first — and it will occasionally still be caught out by a trend that scores high on ADX right before it stalls, since ADX measures strength that has already happened rather than strength still to come. No trend-strength filter, ADX or otherwise, can promise that a confirmed trend continues; it can only raise the odds that a signal is meaningful rather than noise, which is exactly the kind of edge a trend-following EA needs and a reason to still combine it with sound risk management and, ideally, a read of the broader trend vs range context before trading a given pair.

Installation and Setup

EAs install into a different folder than indicators, and this is the step people miss most often.

  1. Download the file below for your platform.
  2. Open MetaTrader → click FileOpen Data Folder.
  3. Place the file in MQL4/Experts (MetaTrader 4) or MQL5/Experts (MetaTrader 5) — not the Indicators folder.
  4. Restart MetaTrader, then drag the EA from the Navigator window onto a chart.
  5. Enable AutoTrading (MT4) or Algo Trading (MT5) in the toolbar — the EA will not place any trades while this is off, even if it's attached to a chart.
  6. Review and adjust the input parameters in the EA's settings dialog before confirming.

A Word of Caution

Test on a demo account first, across different market conditions and multiple pairs, before risking real money — a backtest or a good run on a demo account never guarantees future results. This EA can and will lose on individual trades; the ADX filter reduces the number of false DI crosses it acts on, but it cannot eliminate them, and it does nothing to protect against a trend that is genuinely strong right up until it reverses — a high ADX reading is a description of what has already happened, not a promise of what happens next. Consider combining this EA with other reads on trend quality (price structure, higher-timeframe direction, or the ADX-slope discussion in the ADX lesson) rather than trading the signal in isolation. Both the MT4 and MT5 files below are source code — open and read them fully, and understand exactly what every parameter does, before attaching this EA to a live account. This content is general education, not personalized investment advice.

Download the EA

How to Install — MetaTrader 4

  1. Download the adx-trend-strength-ea.mq4 file below.
  2. Open MetaTrader 4 → click FileOpen Data Folder.
  3. Place the file in the MQL4/Experts folder.
  4. Restart MetaTrader 4, then drag the EA from the Navigator window onto the chart.

How to Install — MetaTrader 5

  1. Download the adx-trend-strength-ea.mq5 file below.
  2. Open MetaTrader 5 → click FileOpen Data Folder.
  3. Place the file in the MQL5/Experts folder.
  4. Restart MetaTrader 5, then drag the EA from the Navigator window onto the chart.

Both files are source code — open and review the full code before using it, for your own safety.

Download adx-trend-strength-ea.mq4

For MetaTrader 4 — this is source code (.mq4), open and review it fully before using it.

Download File

Download adx-trend-strength-ea.mq5

For MetaTrader 5 — this is source code (.mq5), open and review it fully before using it.

Download File