An Expert Advisor (EA) is different from every other download on this site — an indicator only plots or alerts, while an EA actually sends orders on your behalf. This free EA trades a single, transparent trend-following strategy end to end: entry, Stop Loss, Take Profit, and position size, all calculated automatically from the same tools taught elsewhere on this site.
How the Strategy Works
The entry signal is a Moving Average crossover — a fast MA (default 20-period) crossing above or below a slow MA (default 50-period) — but the crossover alone isn't enough to trigger a trade. It's filtered by ADX: the crossover only fires if ADX is above a configurable threshold (default 25), confirming the market is actually trending rather than chopping sideways. This is the exact filter taught in the ADX lesson — a moving-average signal is far more reliable when there's a real trend behind it, and far noisier when the market is range-bound.
Stop Loss, Take Profit, and Position Size
Both Stop Loss and Take Profit are sized from ATR rather than a fixed pip distance — a volatile pair or session gets a wider stop automatically, and a calm one gets a tighter stop, so the stop always reflects what the market is actually doing right now. Take Profit is then set at a multiple of the Stop Loss distance (the Risk:Reward ratio), keeping every trade's risk and reward in a fixed, known proportion.
Position size is calculated from a Risk % input against your account balance and the Stop Loss distance — the exact worked-example method from Risk Management Basics: risk amount ÷ Stop Loss distance = lot size. This means the EA automatically trades smaller on wider stops and larger on tighter ones, rather than using a fixed lot size that ignores how far away the stop actually is.
Entry Conditions
- BUY — fast MA crosses above slow MA while ADX is above the threshold.
- SELL — fast MA crosses below slow MA while ADX is above the threshold.
The EA only evaluates these conditions once per new bar (not on every tick), only opens one position at a time, and only manages positions tagged with its own magic number — so it won't interfere with trades you open manually on the same account, and it won't stack additional trades on top of an open one.
Parameters
- FastMAPeriod / SlowMAPeriod (default 20 / 50) — the two Moving Average periods that form the crossover signal.
- ADXThreshold (default 25) — minimum ADX reading required before a crossover is allowed to trigger a trade.
- ATRMultiplier (default 2.0) — Stop Loss distance = ATR × this multiplier.
- RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance × this ratio.
- RiskPercent (default 1.0) — percentage of account balance risked per trade, used to calculate lot size. Ignored if
UseFixedLotis enabled. - MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this, to avoid opening trades at a bad price during illiquid conditions — the same concern covered in Spread and Slippage.
- EnableTrading — a master on/off switch, useful for pausing the EA without removing it from the chart.
Why a Trend Filter on a Crossover Strategy
A plain moving-average crossover, on its own, is one of the noisiest signals in trading — in a ranging market, price whipsaws back and forth across both MAs repeatedly, firing crossover after crossover with no real trend to ride. Requiring ADX confirmation before acting on a crossover is a direct, mechanical version of the advice given throughout this site's trend vs range lesson: know what kind of market you're in before picking a strategy for it. The tradeoff is that this EA will sit out ranging markets entirely, taking no trades — which is the correct behavior for a trend-following system, even though it can feel like the EA is "doing nothing" during quiet periods.
Installation and Setup
EAs install into a different folder than indicators — this is the step people miss most often.
- Download the file below for your platform.
- Open MetaTrader → click
File→Open Data Folder. - Place the file in
MQL4/Experts(MetaTrader 4) orMQL5/Experts(MetaTrader 5) — not the Indicators folder. - Restart MetaTrader, then drag the EA from the Navigator window onto a chart.
- 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.
- 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, before risking real money — past performance, in backtests or live, never guarantees future results. No strategy, automated or manual, wins every trade, and this EA can and will lose money on individual trades; the ADX filter reduces how often it trades in a poor-fit market, it doesn't eliminate losing trades. Both files are source code — open and review them fully, and understand what every parameter does, before using it. This content is general education, not personalized investment advice.
Download the EA
How to Install — MetaTrader 4
- Download the
trend-following-ea.mq4file below. - Open MetaTrader 4 → click
File→Open Data Folder. - Place the file in the
MQL4/Expertsfolder. - Restart MetaTrader 4, then drag the EA from the Navigator window onto the chart.
How to Install — MetaTrader 5
- Download the
trend-following-ea.mq5file below. - Open MetaTrader 5 → click
File→Open Data Folder. - Place the file in the
MQL5/Expertsfolder. - 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.