- 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
| Input | Default | What it changes |
|---|---|---|
| Entry channel length | 20 | Bars used for the breakout channel. |
| Exit channel length | 10 | Bars used for the opposite exit channel. |
| Stop-loss distance (x ATR) | 2.0 | Protective stop as a multiple of ATR(14). |
| Take-profit (R multiple) | 0.0 | Optional fixed target; 0 leaves the exit to the channel. |
| Use exit channel | true | Closes trades on the opposite 10-bar channel. |
| Risk per trade (% of balance) | 1.0 | Share of balance risked between entry and stop. |
| Fixed lots | 0 | Fixed volume instead of risk %; 0 = risk-based. |
| Maximum spread (points) | 20 | Skips signals when the spread is wider; 0 = off. |
| Trading start / end hour | 1 / 23 | Server-time window for new trades; equal values = 24 hours. |
| Move stop to break-even | false | Stop to entry + 20 points once profit reaches 1R. |
| Use trailing stop | false | Trails the stop 2 x ATR behind price. |
| Magic number | 2611010 | Identifies 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.

