Skip to content

Free MT5 Expert Advisor

Donchian Breakout EA

MT5 Expert Advisor that trades 20-bar Donchian channel breakouts and exits on the 10-bar opposite channel, with an ATR stop.

Breakoutv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Stop-loss on every trade
Strategy
Buys when price closes above the highest high of the previous 20 bars and sells when it closes below the lowest low. Long trades exit on a close below the 10-bar low (shorts above the 10-bar high), with a 2 x ATR protective stop on every order.
Risk model
1% of balance per trade (configurable), stop-loss on every order, one position at a time

What it does

The Donchian Breakout EA follows a channel-breakout model that has been used by trend followers for decades. It buys when price closes above the highest high of the last 20 bars and sells when price closes below the lowest low, then stays in the trade until price breaks the shorter 10-bar channel in the other direction.

Every order also carries an ATR-based stop-loss, and the EA never adds to a position: one trade per symbol at a time. The defaults are chosen for EURUSD on H4.

How it works

Channels are measured from completed bars only, excluding the bar being tested.

  • Entry channel: highest high and lowest low of the 20 bars before the last closed bar.
  • Buy: the last closed bar closed above that high and the bar before had not already closed above its own 20-bar high, so only the first breakout counts.
  • Sell: the mirror with the 20-bar low.
  • Stop-loss: 2 x ATR(14) from the entry price.
  • Exit channel: a long closes when a bar closes below the lowest low of the previous 10 bars; a short closes when a bar closes above the 10-bar high.
  • No pyramiding: while a position is open, new breakouts in either direction are logged and skipped. Break-even is off by default to let the channel manage the trade.

How to use it

Breakout systems depend on a minority of large trends, so they tend to suit higher timeframes such as H4 and D1 and markets that trend for weeks, including major pairs, gold and indices. Expect long stretches of small losses between good trends.

The volatility lesson explains why ATR-based stops widen and shrink with market conditions, which keeps the money at risk per trade roughly constant.

Settings

InputDefaultWhat it changes
Entry channel length20Bars used for the breakout channel.
Exit channel length10Bars used for the opposite exit channel.
Stop-loss distance (x ATR)2.0Protective stop as a multiple of ATR(14).
Take-profit (R multiple)0.0Optional fixed target; 0 leaves the exit to the channel.
Use exit channeltrueCloses trades on the opposite 10-bar channel.
Risk per trade (% of balance)1.0Share of balance risked between entry and stop.
Fixed lots0Fixed volume instead of risk %; 0 = risk-based.
Maximum spread (points)20Skips signals when the spread is wider; 0 = off.
Trading start / end hour1 / 23Server-time window for new trades; equal values = 24 hours.
Move stop to break-evenfalseStop to entry + 20 points once profit reaches 1R.
Use trailing stopfalseTrails the stop 2 x ATR behind price.
Magic number2611010Identifies this EA's trades.

Limitations

  • Many breakouts fail and reverse back into the channel, especially in ranging markets.
  • The exit channel gives back part of each trend's profit before it triggers.
  • On H4 and D1 the EA trades rarely, so a short test period says very little.
  • Breakouts around news or session opens can suffer slippage beyond the closing price.

Before you run it live

Test on a demo account and in the MetaTrader 5 Strategy Tester over several years first. No backtest results are published for this EA, and any test describes the past only.

  • Match the spread limit and trading hours to your broker's spreads, stop level and session times, and include commission and swap in tests.
  • Start with 1% risk or less and check the lot sizes in the Experts log; the Position Size Calculator is a useful cross-check.
  • Use a different magic number on each chart, and keep the terminal (or a VPS) running so stops are managed.

Use the longest history your broker provides in the Strategy Tester, and check that the number of trades is large enough to be meaningful.

Key inputs

Key inputs of Donchian Breakout EA
InputDefaultDescription
Entry channel length20Bars used for the breakout channel.
Exit channel length10Bars used for the opposite exit channel.
Stop-loss distance (x ATR)2.0Protective stop as a multiple of ATR(14).
Take-profit (R multiple)0.0Optional fixed target; 0 leaves the exit to the channel.
Use exit channeltrueCloses trades on the opposite 10-bar channel.
Risk per trade (% of balance)1.0Share of balance risked between entry and stop.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors