An indicator only plots a line or fires an alert — an Expert Advisor (EA) actually sends orders on your behalf. This free EA trades the breakout strategy covered in the Donchian Channels lesson directly: the moment price closes beyond the highest high or lowest low of the prior N bars, it opens a trade in the direction of that breakout, with Stop Loss, Take Profit, and position size all calculated automatically from ATR and account risk — the same entry logic that anchored the original Turtle Trading system, rebuilt as a self-contained EA.
How the Strategy Works
The entry signal is the same one covered in the Donchian Channels indicator lesson: has the just-closed bar's Close finished above the highest High of the prior DonchianPeriod bars, or below the lowest Low of the same window? Because the band is built only from bars before the one being tested, a breakout here always means price has moved into territory the recent lookback window genuinely hadn't covered — not merely that the current bar happens to be part of its own new extreme. A close above the upper band is read as a bullish breakout and triggers a BUY; a close below the lower band is the mirrored bearish case and triggers a SELL.
There's no built-in Donchian function in either MetaTrader 4 or MetaTrader 5, so this EA calculates the highest high and lowest low directly from the High/Low price series on every new bar, using the same prior-N-bar window described in the indicator lesson.
Stop Loss, Take Profit, and Position Sizing
Stop Loss and Take Profit are sized from ATR rather than from the Donchian band itself — 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), giving every trade this EA opens the same fixed reward-to-risk shape regardless of pair or timeframe.
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, keeping the dollar amount at risk roughly constant even as the ATR-based stop distance changes with volatility. See Lot Sizes Explained for how this lot size is then normalized to the broker's minimum, maximum, and step lot size before the order is sent. UseFixedLot is available as an escape hatch for a constant lot size regardless of account risk.
Entry Conditions
- BUY — the just-closed bar's Close is above the highest High of the
DonchianPeriodbars before it. - SELL — the just-closed bar's Close is below the lowest Low of the
DonchianPeriodbars before it.
Three safety mechanics govern every trade this EA can place, matching the standard used across every EA on this site: it evaluates entry conditions once per new bar only, tracked via the bar's open time, so a single qualifying bar can't trigger repeated entries 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 if the spread is too wide to trade at a reasonable price. Every order is tagged with MagicNumber (default 20260726), so the EA's position-counting logic never touches a trade opened manually or placed by a different EA running on the same account.
Parameters
- DonchianPeriod (default 20) — the lookback window the highest-high/lowest-low entry band is built from. A shorter period triggers more, smaller breakouts; a longer period (55, the second Turtle system) requires a larger move before entering.
- ATRPeriod (default 14) — the ATR lookback used 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
UseFixedLotis enabled. - RiskPercent (default 1.0) — percentage of account balance risked per trade when
UseFixedLotis disabled. - MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this.
- MagicNumber (default 20260726) — 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 This EA Uses ATR for the Stop, Not the Opposite Donchian Band
The original Turtle system used a second, shorter Donchian channel for exits — a 10-day low to exit a long, for example — rather than a fixed-distance stop. That approach is workable, but it couples the exit distance to whatever the shorter channel happens to measure at that moment, which can be very wide right after a strong breakout and very narrow during a quiet one, making risk per trade inconsistent from one signal to the next. This EA instead follows the same ATR-based Stop Loss pattern used across every other EA on this site: the stop distance is a direct multiple of current volatility, and position size is calculated backward from that distance to keep the dollar risk on every trade roughly constant. The trade-off is that this EA's stop doesn't structurally reference the channel itself the way the original Turtle exit channel did — it's a deliberate simplification that keeps the risk model consistent with the rest of this site's EAs rather than reproducing every detail of the historical Turtle system.
Installation and Setup
EAs install into a different folder than indicators, and 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 and multiple pairs, before risking real money — a good backtest or demo run never guarantees future results. This EA can and will lose on individual trades: a close beyond the Donchian band confirms only that price has reached a new N-bar extreme, not that a sustained move follows, and false breakouts that reverse immediately are common enough that a string of losses during choppy conditions should be expected. Consider combining this EA with a trend-strength filter such as ADX rather than trading every Donchian breakout in every market condition. 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
- Download the
donchian-breakout-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
donchian-breakout-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.