Loading…

Donchian Breakout EA

The Donchian channel is the oldest trend-following breakout in this catalogue: the entry channel is the highest high and lowest low of the last InpEntryPeriod bars, and a close beyond either edge opens a position in that direction. The channel is read starting one bar back, so the level being tested never includes the bar doing the testing - without that, every bar would trivially "break out" of a level it just helped set. The exit is the classic second half of the rule: instead of a fixed stop, the position is closed when price crosses the opposite edge of a shorter InpExitPeriod channel. A breakout that reverses hard enough to cross back through recent price action has failed on its own terms, and the position is let run until that happens rather than being capped by an arbitrary distance. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the initial stop distance, using the broker's tick value and tick size rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Signals are evaluated once per closed bar, not on every tick, and the initial stop is placed at the exit channel's opposite edge at entry time - it is not actively trailed bar by bar. - Like any breakout system, it gives back some profit waiting for the exit channel to be crossed rather than locking in gains early, and it can whipsaw in a ranging market where the entry channel is repeatedly tagged without a sustained move following. - Requires AutoTrading enabled and trading permitted at the terminal, account and Expert Advisor level; if trading is disabled the EA logs it and skips the entry, on both platforms.

Expert advisor · MT5 · v1.0 · Free

About Donchian Breakout EA

Donchian Breakout EA is an expert advisor (trading robot) for MetaTrader 5. It can size trades from your balance and risk percent and trades breakouts. It has 9 settings, such as Entry period, Exit period and Use risk sizing. MQL source code included.

Files in the download: DonchianBreakoutEa.ex5, DonchianBreakoutEa.mq5, DonchianBreakoutEa.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Entry period20Bars in the entry channel (breakout lookback)
Exit period10Bars in the exit channel (opposite-edge exit lookback)
Use risk sizingfalseSize by percent risk instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a fallback
Magic number20260607Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Breakout · Channels & Envelopes · Trend · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria