P
PipsGrowth
BreakoutOpen Source – Free

Pipsgrowth EX02026 Breakout

MT5 Expert Advisor (Open Source) · XAUUSD · M5

Pipsgrowth.com EX02026 XAUUSD_M5_Donchian_EA — Donchian breakout with RSI and speed filter, full 12-layer stack.

Overview

Pipsgrowth EX02026 trades Donchian-channel breakouts on the 5-minute XAUUSD chart, but unlike the textbook Turtle system it requires the breakout bar to satisfy a small set of guard conditions before any order is sent. The Donchian band itself is calculated inline in the source — there is no iCustom or built-in iDonchian handle. On every new bar, CalculateDonchian() walks InpDonchianPeriod (default 20) of prior iHigh/iLow values to build the upper and lower rails and the midpoint, all stored in three global arrays g_donchianHigh, g_donchianLow, and g_donchianMid with ArraySetAsSeries on. This keeps the channel self-contained: the user changes InpDonchianPeriod and InpDonchianShift, and the band recomputes from raw history. The source file is Pipsgrowth_com_EX02026.mq5, version 2.00, magic 22202026, with 37 inputs across 13 groups and 20 functions.

The actual signal is two-line simple. CheckSignal() reads the previous closed bar (shift 1) and the bar before that (shift 2), then asks a single question: did the prior bar close outside the rail? A long fires when iClose(shift 2) was at or below g_donchianHigh[1] and iClose(shift 1) closes above g_donchianHigh[0]; a short is the mirror — the bar was at or above the lower rail two bars back and closes below it now. Crucially the bar that prints the breakout is the closed bar, not the forming bar, so EX02026 is honest about avoiding repaint. There is no body/range or strong-candle ratio at the entry — the breakout bar is taken at face value, and the rest of the gating is delegated to two stacked filters.

The first guard is the RSI filter. GetRSI() pulls RSI(InpRSIPeriod) at shift 1, with InpRSIPeriod defaulting to 14. When InpUseRSIFilter is on, a long signal is rejected if RSI is already at or above InpRSIOverbought (default 70), and a short is rejected if RSI is at or below InpRSIOversold (default 30). The point is to suppress breakouts that are extending an exhausted move: a gold candle that is breaking the 20-bar high while RSI is already pinned to 70 is more likely to reverse than to continue. The second guard is the speed filter. CalculateSpeed() averages |close - open| over InpSpeedBars (default 10) of closed bars and divides that average by the current ATR(14). If the ratio is below InpMinSpeed (default 0.5), the breakout is treated as a low-velocity event and is killed. When InpUseSpeedFilter is on, the EA effectively refuses breakouts that occur during quiet tape — only breakouts that form while gold is actually moving enter the queue.

Position management has three independent layers. The fixed stop and target are set at order entry: InpStopLoss = 500 points and InpTakeProfit = 1500 points, a 1:3 reward-to-risk that the EA will not negotiate on. Both prices are computed from the live ask/bid in ExecuteTrade() and snapped to the broker tick via NormalizePrice_EX02026(). On every tick, before the next bar's signal is even evaluated, ManageBreakeven() walks open positions and, once price has moved InpBEStart (200) points in profit, pushes the stop to openPrice + InpBEProfit (50) points — locking in a small but positive offset rather than pure break-even. ManageTrailingStop() then takes over: once profit reaches InpTrailStart (300) points, the stop ratchets to InpTrailDistance (200) points behind bid (or ahead of ask for shorts) and only ever moves in the favourable direction, never backward. Both modification calls are routed through TryModify_EX02026(), which retries up to three times on requote, timeout, price-off, and price-changed responses with a 200 ms back-off. There is no opposite-signal exit and no time exit; positions run until SL, TP, the trailing ratchet, or the broker.

Sizing runs through CalculateLotSize(). With InpRiskPercent at 1.0 (the default), the function reads the account balance, multiplies by 1%, and divides by the per-lot dollar loss at InpStopLoss. The per-lot loss is computed as slPoints * (tickValue * point / tickSize), which accounts for the broker's tick economics on gold. The result is floored to the symbol's volume step, clamped between the minimum and maximum lot, and finally capped at InpMaxLotSize (1.0). Setting InpRiskPercent to 0 switches the EA to a flat InpFixedLot (0.01) — a clean escape hatch for operators who want to ignore the risk math. Order sends use the CTrade wrapper and retry up to three times on requote/timeout/price-off/price-changed with a 200 ms gap, after a pre-check via OrderCalcMargin to refuse entries the free margin cannot cover.

The session structure is unusual for the family. EX02026 ships with two configurable server-time windows: InpEnableSession1 (true) running InpSession1Start 8 through InpSession1End 12, and InpEnableSession2 (true) running InpSession2Start 14 through InpSession2End 18. IsWithinTradingSession() converts server time to local hour and accepts a bar only if it falls inside either window — which on most broker servers corresponds to the London morning and the London-New York afternoon overlap. The hardening layer adds an independent GMT filter via InpUseGMTSessions (default false): when on, InActiveSession_EX02026() returns true only inside London 7-16 GMT or New York 12-21 GMT, with the GMT offset auto-detected by DetectGMTOffset_EX02026() through a best-of -12..+12 scoring heuristic. The spread filter is plain: if InpEnableSpreadFilter is on, the current spread in points must be at or below InpMaxSpread (200 points — a wide ceiling suitable for gold, where the raw spread in points can spike during thin liquidity).

Pyramiding is implemented but off by default. InpEnablePyramid = false, and the user has to flip it on to use IsPyramidSafe(). When enabled, the function will approve an additional entry only if (a) the current open trade count is below InpMaxPyramidLevels (default 3), and (b) for an existing buy, the current stop-loss is at least InpMinSLProfit (150) points above the open price (or below for shorts). The condition keeps new units from being added to a fresh or losing position — pyramiding only stacks onto a winner whose stop has already been pushed up by the breakeven function.

The hardening stack sits in front of every entry attempt. IsSafeToTrade_EX02026() rejects trades when IsMarketOpen_EX02026() reports a closed weekend (no Saturday, no Sunday, no Monday before 22:00 GMT, no Friday from 22:00 GMT onward), when InActiveSession_EX02026() fails the GMT check, when IsNewsTime_EX02026() finds a high-impact MQL5 calendar event inside a ±InpNewsBufferMinutes (30) window, when the effective equity is below 70% of g_initialBalance, when g_tradesToday has hit InpMaxTradesPerDay (10), when the cooldown timer is active, or when the realized loss for the day has crossed InpDailyLossLimitPct (5%). Consecutive losses are tracked in OnTradeTransaction: at InpMaxConsecLosses (5), g_cooldownUntil is set to TimeCurrent() + InpCooldownHours (4) hours and the EA refuses entries until that timestamp passes. The OnTester() fitness is profit * profitFactor / maxDD with a 10-trade minimum gate — a permissive fitness that lets the optimizer explore the full parameter space rather than culling low-trade-count configurations.

Practical notes for first-time users. The 1:3 reward-to-risk on a 500/1500 point setup is wider than the family's 1:2 standard; on a 5-digit gold quote this resolves to a 50-pip stop and a 150-pip target, which is a meaningful run. The 200-point spread ceiling is permissive — most ECN/RAW feeds sit below 50 points on XAUUSD M5, so the filter is a no-op for normal conditions and only triggers during news volatility or thin liquidity windows. InpUseGMTSessions is off by default, which means the server-time windows (8-12 and 14-18) are the active filter out of the box; if your broker's server is in a different time zone, the default windows will not line up with London or New York hours and you will need to either shift InpSession1Start/InpSession2Start or flip InpUseGMTSessions to true. The RSI and speed filters are independent and can both be disabled; the speed filter in particular is the EA's noise-killer, and turning it off will let in breakouts during dead sessions. Pyramiding is the last input to consider — leave it off until you have a backtest that justifies the exposure.

Backtest expectations. The OnTester fitness rewards configurations that improve profit-per-drawdown, but the 10-trade gate is the only quality filter, so very quiet configurations that put on only a handful of trades are still scored. On XAUUSD M5 with the default 1.5x ATR-of-the-day average move, expect a few trades per day during active sessions and stretches of dead bars during the Asian session. The 1:3 RR profile means the strategy can stay profitable with a relatively low win rate (above ~30%) provided the trailing stop does not curtail the larger winners. If the backtest produces many trades but a flat or down equity curve, the speed filter is the first input to tighten — raise InpMinSpeed from 0.5 to 0.75 or 1.0 and rerun.

Strategy Deep Dive

Each new M5 bar triggers CalculateDonchian(), which rebuilds the upper rail, lower rail, and midpoint from raw iHigh/iLow history over InpDonchianPeriod (default 20) bars; the three arrays are stored as series so index 0 is the most recent bar. CheckSignal() then asks whether the prior closed bar closed outside the rail versus the bar before it, gates the answer through GetRSI(14) (no trades at RSI ≥ 70 on longs, no trades at RSI ≤ 30 on shorts) and CalculateSpeed() (average |close − open| over 10 bars must be ≥ 0.5× ATR(14)), and returns a clean SIGNAL_BUY or SIGNAL_NONE/SIGNAL_SELL. The tick path also calls ManageBreakeven() and ManageTrailingStop() on every tick, pushing stops to BE+50 once profit hits 200 points and trailing by 200 points behind price once profit hits 300 points; the only path to exit is the SL, the TP, or the trailing/breakeven ratchet. The safety gate (IsSafeToTrade_EX02026) sits in front of every entry attempt: weekend hours via IsMarketOpen_EX02026, the two server-time session windows (8-12 and 14-18 by default), the optional London/NY GMT filter, ±30-minute high-impact news buffer via MQL5 CalendarValueHistory, 70% equity floor, 5% daily loss cap, 10 trades-per-day limit, and the 4-hour cooldown triggered by 5 consecutive losses. Order sends go through CTrade with three retries on requote/timeout/price-changed at 200 ms, after OrderCalcMargin pre-checks free margin; modifications route through TryModify_EX02026 with the same retry pattern.

Entry Signal

A Donchian channel breakout fires when the prior closed M5 bar prints outside the 20-bar upper or lower rail of the inline-calculated channel. Two stacked filters must pass: RSI(14) at shift 1 must not be at or beyond 70 for a long (or at or below 30 for a short), and the average |close − open| over the last 10 bars must be at least 0.5× the current ATR(14). Sessions (default 8-12 and 14-18 server time), spread ≤ 200 points, weekend, news buffer, and the safety gate all gate the entry before ExecuteTrade() sends the order.

Exit Signal

Every order carries a fixed 500-point stop and 1500-point target (1:3 RR) at placement, with no opposite-signal exit and no time-based exit. ManageBreakeven() ratchets the stop to open + 50 points once profit reaches 200 points. ManageTrailingStop() then takes over once profit reaches 300 points, pulling the stop to 200 points behind bid (or ahead of ask for shorts), only ever forward. The Trailing/BE pipeline is the only path to exit; positions are otherwise held to SL or TP.

Stop Loss

Each order is opened with InpStopLoss = 500 points of fixed distance from entry (50 pips on a 5-digit XAUUSD quote). There is no portfolio-level stop; the only drawdown protection is the InpDailyLossLimitPct (5%) gate, the InpMinEquityPct (70% of initial balance) gate, and the 4-hour cooldown triggered by 5 consecutive losing trades tracked in OnTradeTransaction.

Take Profit

Take-profit is fixed at InpTakeProfit = 1500 points (150 pips on a 5-digit XAUUSD quote), giving a 1:3 reward-to-risk against the 500-point stop. There is no partial close, no scaling out, and no time-based exit; the TP is the only fixed profit target.

Best For

XAUUSD M5 on a low-spread ECN or RAW account is the primary target; the EA is calibrated to gold's intraday rhythm and uses point-based SL/TP rather than pips. Minimum recommended balance: $100 (the input cap is 0/disabled by default, so risk scales with real equity, but the 5% daily loss cap and 70% equity floor work best with at least a few hundred dollars to absorb a normal losing streak). Best trading hours are the two server-time windows that ship enabled — 8-12 and 14-18 — which on most broker servers line up with the London morning and the London–New York afternoon overlap. Suitable for traders who want a 1:3 RR breakout system with RSI and speed gating and are comfortable with the family-standard hardening stack (weekend, news, equity floor, 5-loss cooldown).

Strategy Logic

Pipsgrowth EX02026 Breakout — Strategy Logic Analysis (from .mq5 source)

Family: Breakout Magic: 22202026 Version: 2.00

BRIEF: Donchian Channel breakout EA for XAUUSD M5 with RSI confirmation, average-speed filter, session filtering, trailing stop, breakeven, and optional safe pyramiding

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • CalculateDonchian()
  • CalculateSpeed()
  • GetRSI()
  • CalculateLotSize()
  • IsWithinTradingSession()
  • IsSpreadOK()
  • CountOpenTrades()
  • IsPyramidSafe()
  • ManageTrailingStop()
  • ManageBreakeven()
  • IsNewBar()
  • ExecuteTrade()
  • ...and 10 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (37 total across 13 groups):

  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_02026" // Trade Comment
  • [=== Identity ===] InpMagicNumber = 22202026 // Magic Number
  • [=== Donchian Channel Settings ===] InpDonchianPeriod = 20 // Donchian Period
  • [=== Donchian Channel Settings ===] InpDonchianShift = 0 // Donchian Shift
  • [=== RSI Filter ===] InpUseRSIFilter = true // Enable RSI Filter
  • [=== RSI Filter ===] InpRSIPeriod = 14 // RSI Period
  • [=== RSI Filter ===] InpRSIOverbought = 70 // RSI Overbought
  • [=== RSI Filter ===] InpRSIOversold = 30 // RSI Oversold
  • [=== Speed Filter ===] InpUseSpeedFilter = true // Enable Speed Filter
  • [=== Speed Filter ===] InpSpeedBars = 10 // Speed Calculation Bars
  • [=== Speed Filter ===] InpMinSpeed = 0.5 // Min Speed (ATR multiple)
  • [=== Risk Management ===] InpRiskPercent = 1.0 // Risk % per Trade
  • [=== Risk Management ===] InpFixedLot = 0.01 // Fixed Lot (if Risk=0)
  • [=== Risk Management ===] InpMaxLotSize = 1.0 // Max Lot Size
  • [=== Stop Loss & Take Profit ===] InpStopLoss = 500 // Stop Loss (Points)
  • [=== Stop Loss & Take Profit ===] InpTakeProfit = 1500 // Take Profit (Points)
  • [=== Trailing & Breakeven ===] InpUseTrailing = true // Enable Trailing Stop
  • [=== Trailing & Breakeven ===] InpTrailStart = 300 // Trail Start (Points)
  • [=== Trailing & Breakeven ===] InpTrailDistance = 200 // Trail Distance (Points)
  • [=== Trailing & Breakeven ===] InpUseBreakeven = true // Enable Breakeven
  • [=== Trailing & Breakeven ===] InpBEStart = 200 // BE Trigger (Points)
  • [=== Trailing & Breakeven ===] InpBEProfit = 50 // BE Lock Profit (Points)
  • [=== Time Management ===] InpEnableSession1 = true // Enable Session 1
  • [=== Time Management ===] InpSession1Start = 8 // Session 1 Start Hour
  • [=== Time Management ===] InpSession1End = 12 // Session 1 End Hour
  • [=== Time Management ===] InpEnableSession2 = true // Enable Session 2
  • [=== Time Management ===] InpSession2Start = 14 // Session 2 Start Hour
  • [=== Time Management ===] InpSession2End = 18 // Session 2 End Hour
  • [=== Spread Filter ===] InpEnableSpreadFilter = true // Enable Spread Filter
  • [=== Spread Filter ===] InpMaxSpread = 200 // Max Spread (Points)
  • [=== Safe Pyramid ===] InpEnablePyramid = false // Enable Pyramiding
  • [=== Safe Pyramid ===] InpMaxPyramidLevels = 3 // Max Pyramid Positions
  • [=== Safe Pyramid ===] InpMinSLProfit = 150 // Min SL in Profit (Points)
  • [=== GMT Session Filter (Hardening) ===] InpNewYorkEndGMT = 21 // --- Hardening: Capital Protection ---
  • [=== Capital Protection (Hardening) ===] InpCapAmount = 0.0 // Capital cap amount (0=disabled)
  • [=== Capital Protection (Hardening) ===] InpDailyLossLimitPct = 5.0 // --- Hardening: Trade Safety ---
  • [=== Trade Safety (Hardening) ===] InpNewsBufferMinutes = 30 // +------------------------------------------------------------------+
Pseudocode
// Pipsgrowth EX02026 Breakout — Execution Flow (from source analysis)
// Family: Breakout
// Donchian Channel breakout EA for XAUUSD M5 with RSI confirmation, average-speed filter, session filtering, trailing stop, breakeven, and optional safe pyramiding

ON_INIT:
    Create indicator handles: standard set
    Initialize state variables
    Detect broker GMT offset

ON_TICK:
    1. Refresh indicator buffers (closed-bar shift=1)
    2. Manage existing positions:
       - Break-even check
       - ATR trailing stop
       - Profit lock ratchet
       - Time-based exit
       - Opposite-signal exit
    3. If new bar:
       a. ClassifyRegime() — ADX/ATR/BB regime detection
       b. NoTradeGate() checks:
          - Market open + session filter
          - Spread limit
          - Cooldown after loss
          - Consecutive loss limit
          - Kill switch
          - Max drawdown
          - Max concurrent positions
          - Daily/weekly loss limits
       c. GenerateSignal() — strategy-specific entry logic
       d. CheckConfirm() — HTF alignment + R:R + ADX minimum
       e. Calculate position size from risk %
       f. Execute with retry logic
       g. Mark bar to prevent duplicates

ON_TESTER:
    Custom fitness = weighted(RecoveryFactor, ROI, ProfitFactor, TradeCount, Sharpe, Drawdown)

Optimization Profile

Optimized Brokers:
ExnessIC Markets
Optimized Symbols:
XAUUSD
Optimized Timeframes:
M5

How to Install This EA on MT5

  1. 1Download the .mq5 file using the button above
  2. 2Open MetaTrader 5 on your computer
  3. 3Click File → Open Data Folder in the top menu
  4. 4Navigate to MQL5 → Experts and paste the .mq5 file there
  5. 5In MT5, right-click Expert Advisors in the Navigator panel → Refresh
  6. 6Drag the EA onto an H1 or H4 chart
  7. 7Set the range detection period, breakout buffer, and lot size in the EA dialog
  8. 8Enable Allow Algo Trading and click OK

EA Parameters

ParameterDefaultDescription
InpTradeComment"Psgrowth.com Expert_02026"Trade Comment
InpMagicNumber22202026Magic Number
InpDonchianPeriod20Donchian Period
InpDonchianShift0Donchian Shift
InpUseRSIFiltertrueEnable RSI Filter
InpRSIPeriod14RSI Period
InpRSIOverbought70RSI Overbought
InpRSIOversold30RSI Oversold
InpUseSpeedFiltertrueEnable Speed Filter
InpSpeedBars10Speed Calculation Bars
InpMinSpeed0.5Min Speed (ATR multiple)
InpRiskPercent1.0Risk % per Trade
InpFixedLot0.01Fixed Lot (if Risk=0)
InpMaxLotSize1.0Max Lot Size
InpStopLoss500Stop Loss (Points)
InpTakeProfit1500Take Profit (Points)
InpUseTrailingtrueEnable Trailing Stop
InpTrailStart300Trail Start (Points)
InpTrailDistance200Trail Distance (Points)
InpUseBreakeventrueEnable Breakeven
InpBEStart200BE Trigger (Points)
InpBEProfit50BE Lock Profit (Points)
InpEnableSession1trueEnable Session 1
InpSession1Start8Session 1 Start Hour
InpSession1End12Session 1 End Hour
InpEnableSession2trueEnable Session 2
InpSession2Start14Session 2 Start Hour
InpSession2End18Session 2 End Hour
InpEnableSpreadFiltertrueEnable Spread Filter
InpMaxSpread200Max Spread (Points)
InpEnablePyramidfalseEnable Pyramiding
InpMaxPyramidLevels3Max Pyramid Positions
InpMinSLProfit150Min SL in Profit (Points)
InpNewYorkEndGMT21--- Hardening: Capital Protection ---
InpCapAmount0.0Capital cap amount (0=disabled)
InpDailyLossLimitPct5.0--- Hardening: Trade Safety ---
InpNewsBufferMinutes30+------------------------------------------------------------------+
Source Code (.mq5)Open Source
Pipsgrowth_com_EX02026.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX02026 XAUUSD_M5_Donchian_EA — Donchian breakout with RSI and speed filter, full 12-layer stack."

#include <Trade/Trade.mqh>
CTrade trade;

//+------------------------------------------------------------------+
//| Signal Type Enum                                                   |
//+------------------------------------------------------------------+
enum ENUM_SIGNAL_TYPE {
   SIGNAL_NONE,
   SIGNAL_BUY,
   SIGNAL_SELL
};

//+------------------------------------------------------------------+
//| Input Parameters                                                  |
//+------------------------------------------------------------------+
input group "=== Identity ==="
input string    InpTradeComment = "Psgrowth.com Expert_02026";  // Trade Comment
input ulong     InpMagicNumber = 22202026;            // Magic Number

input group "=== Donchian Channel Settings ==="
input int       InpDonchianPeriod = 20;             // Donchian Period
input int       InpDonchianShift = 0;               // Donchian Shift

input group "=== RSI Filter ==="
input bool      InpUseRSIFilter = true;             // Enable RSI Filter
input int       InpRSIPeriod = 14;                  // RSI Period
input int       InpRSIOverbought = 70;              // RSI Overbought
input int       InpRSIOversold = 30;                // RSI Oversold

input group "=== Speed Filter ==="
input bool      InpUseSpeedFilter = true;           // Enable Speed Filter
input int       InpSpeedBars = 10;                  // Speed Calculation Bars
input double    InpMinSpeed = 0.5;                  // Min Speed (ATR multiple)

input group "=== Risk Management ==="
input double    InpRiskPercent = 1.0;               // Risk % per Trade
input double    InpFixedLot = 0.01;                 // Fixed Lot (if Risk=0)
input double    InpMaxLotSize = 1.0;                // Max Lot Size

input group "=== Stop Loss & Take Profit ==="
input int       InpStopLoss = 500;                  // Stop Loss (Points)
input int       InpTakeProfit = 1500;               // Take Profit (Points)

input group "=== Trailing & Breakeven ==="
input bool      InpUseTrailing = true;              // Enable Trailing Stop
input int       InpTrailStart = 300;                // Trail Start (Points)
input int       InpTrailDistance = 200;             // Trail Distance (Points)
input bool      InpUseBreakeven = true;             // Enable Breakeven
input int       InpBEStart = 200;                   // BE Trigger (Points)
input int       InpBEProfit = 50;                   // BE Lock Profit (Points)

input group "=== Time Management ==="
input bool      InpEnableSession1 = true;           // Enable Session 1
input int       InpSession1Start = 8;               // Session 1 Start Hour

Full source code available on download

Educational purposes only. Do NOT use with real money. Test on demo accounts only.

Tags:ex02026breakoutpipsgrowthfreemt5xauusd

Clear Warning: Educational Purposes Only

Clear Warning: This Expert Advisor is for educational and testing purposes only. Do NOT use it with real money. Test only on demo accounts. Trading with real money involves substantial risk of capital loss. This does not constitute investment advice.

Recommended Brokers for This EA

These EAs run on MT5 — use a regulated broker with fast execution and tight spreads

Community

Sign in to contributeSign In

Educational purposes only. Do NOT use with real money. Test on demo accounts only.

File NamePipsgrowth_com_EX02026.mq5
File Size31.2 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyBreakout
Risk LevelMedium Risk
Timeframes
M5
Currency Pairs
XAUUSD
Min. Deposit$100