Pipsgrowth EX02031 Breakout
MT5 Expert Advisor (Open Source) · XAUUSD · M15
Pipsgrowth.com EX02031 XAUUSDBreakout — London/NY open breakout on XAUUSD, full 12-layer stack.
Overview
Pipsgrowth EX02031 XAUUSD Breakout is a single-purpose breakout EA for gold that fires on two specific clock times each trading day — 8:00 and 13:00 server time — and arms a paired stop-entry on either side of the prior 1-hour M15 range. The strategy ignores trend, momentum, volatility regime, and indicator consensus; it is a pure scheduled break-and-enter system. Every other decision in the code is about whether it is safe to place those orders right now, not whether the market looks like it wants to break.
The range is built from the four most recent completed M15 candles at the moment the trigger fires, so a BuyStop at the London open (8:00) is positioned relative to the high and low of the 7:00–7:45 M15 block. The same logic at 13:00 reads the 12:00–12:45 block for the New York open. The high of that range becomes the BuyStop trigger, the low becomes the SellStop trigger, and a 10-point buffer (InpBreakoutBuf) is added on each side so the order is not sitting exactly on the boundary where noise tends to spike. SL is set 40 points (InpStopLoss) on the far side of the range and TP is set 80 points (InpTakeProfit) on the profitable side, giving a 1:2 reward-to-risk on every breakout arm.
Both pending orders are sent in a single tick using CTrade.BuyStop and CTrade.SellStop, with a margin pre-check via OrderCalcMargin: if the projected BuyStop cannot be funded from ACCOUNT_MARGIN_FREE, the EA skips the cycle and waits for the next session open. Order acceptance is verified by TRADE_RETCODE_DONE or TRADE_RETCODE_PLACED, and the EA retries up to three times on transient errors (REQUOTE, TIMEOUT, PRICE_OFF, PRICE_CHANGED) with a 200ms sleep between attempts. Anything that is not a transient error breaks the loop immediately, and the EA moves on.
A guard called HasTrade() runs at the top of the cycle and rejects any arming attempt when at least one position is already open for this symbol and magic number. This means only one breakout attempt can be live at a time — once a pending order is filled and the position is opened, the second pending order (or the next session's setup) is suppressed until the position is closed. A second throttle on the same variable is lastSession: a timestamp that prevents re-arming within 3000 seconds (~50 minutes) of the previous arm, so even if both triggers fire in the same M15 candle the EA only places orders once.
The hardening layer is unusually heavy for such a small EA. DetectGMTOffset_EX02031 walks every offset from −12 to +12 and scores each by weekday (Mon–Fri +10) and hour (07:00–21:00 +5) to pick the most plausible GMT offset for the broker. IsMarketOpen_EX02031 blocks trading on Saturday and Sunday, blocks the first two hours of Monday (broker rollover), and blocks the last two hours of Friday. InActiveSession_EX02031 reads InpUseGMTSessions and — when true — restricts to the London window (07:00–16:00 GMT) or the New York window (12:00–21:00 GMT); the default for that flag is false, which means in default configuration the session filter is permissive and only the clock-time trigger decides.
IsNewsTime_EX02031 pulls CalendarValueHistory for the ±30 minute window around the current server time and flags any high-importance event, blocking entries while InpFilterNews is true. Capital protection is built from four inputs: InpCapAmount caps the effective capital when non-zero, InpCapFloor (1000 by default) is the minimum effective capital that must remain, InpMinEquityPct (70%) is the equity floor relative to the initial balance captured at OnInit, and InpDailyLossLimitPct (5%) cuts off trading the moment the day's realized P&L breaches that share of the initial balance. The daily counters — g_tradesToday, g_realizedToday, g_consecLosses — are rotated at the day boundary by UpdateDailyCounters_EX02031, with a separate weekly counter for the realized P&L aggregate.
Trade lifecycle is tracked through OnTradeTransaction: only DEAL_ENTRY_OUT, INOUT, and OUT_BY deals are summed into realized P&L (entries are ignored), and the profit figure includes swap and commission so the cooldown logic reacts to net loss, not just gross. After InpMaxConsecLosses (5 by default) consecutive losses, the EA sets g_cooldownUntil to the current time plus InpCooldownHours × 3600 (4 hours) and refuses all new entries until that timestamp passes. The OnTester routine is a simple composite: profit × profit factor ÷ max equity drawdown, with profit factor clamped to 1.0 if it falls outside (0, 1000) and drawdown floored to 1.0 to avoid divide-by-zero; the result is gated to zero when total trades is below 10, which is the minimum sample size this EA needs in a backtest to be considered meaningful.
What this means in practice: a trader who loads EX02031 on an XAUUSD M15 chart gets one well-defined behavior — twice a day, the EA places a buy above and a sell below the most recent hour's range, and either one fills (the other is suppressed by HasTrade) or neither fills and the cycle resets at the next session open. There is no partial close, no breakeven ratchet, no trailing stop, no pyramiding, and no news-aware TP management. The exit is whatever the SL or TP hits first, or the position being closed by the broker on margin/EOB, or the EA's own cooldown path after a losing streak. That is the whole strategy.
The clock trigger itself is server time, not GMT — the EA reads TimeCurrent into an MqlDateTime and tests dt.hour==8 && dt.min==0 or dt.hour==13 && dt.min==0. That means the broker's server time zone determines when the EA sees London and New York opens, which is why DetectGMTOffset_EX02031 still exists: the offset is used to evaluate the session and news guards correctly even though the trigger hours are hard-coded in server time. On a GMT+2 or GMT+3 broker the trigger aligns naturally with the real session opens; on a GMT broker the trigger is 8 and 13 GMT, which is one hour after the standard London open (08:00 GMT) and exactly the NY open (13:00 GMT) — that gap is intentional in the source, and a trader who wants different behavior has to either shift InpLondonStartGMT/InpNewYorkStartGMT inside the optional InpUseGMTSessions gate, or run the EA on a broker whose server time already matches their preferred session definition.
Strategy Deep Dive
Every tick, the EA checks the server clock: if it is exactly 8:00 (London open) or 13:00 (New York open), the cycle fires; otherwise the tick returns immediately. When the cycle fires, IsSafeToTrade_EX02031 layers seven independent guards — weekend block, optional GMT session filter, news filter (±30min high-impact events), effective-capital floor, equity drawdown floor, daily loss cap, and consecutive-loss cooldown — and any single failure aborts the arming. If all guards pass and no position with this magic is already open, the EA reads the last 4 M15 candles' high and low to build the session range, computes the BuyStop/SellStop trigger prices with a 10-point buffer, and submits both pending orders in a single tick with 3-attempt retry on transient errors. The 50-minute lastSession throttle ensures both session triggers in the same M15 candle do not double-arm. Position exits are pure SL/TP — no trailing, no partial, no news-aware management — and OnTradeTransaction accumulates realized P&L to drive the consec-loss counter and the 4-hour cooldown.
At the London open (8:00 server time) and New York open (13:00 server time), the EA reads the high and low of the most recent 4 completed M15 candles, then arms a BuyStop at the range high plus a 10-point buffer and a SellStop at the range low minus 10 points, each with 40 points of risk and 80 points of reward. The cycle is suppressed for 50 minutes after each arming and skipped entirely when a position with this magic is already open.
Positions close at the fixed TP (80 points) or SL (40 points); there is no trailing stop, no breakeven ratchet, and no partial close in this EA. The session-open pending orders are also one-shot — once one fills, the HasTrade guard suppresses further entry attempts until the open position is closed.
Fixed stop loss of 40 points (InpStopLoss) placed on the far side of the pre-session range — below rangeLow for BuyStop fills, above rangeHigh for SellStop fills. The pre-order OrderCalcMargin check also implicitly filters trades the account cannot margin.
Fixed take profit of 80 points (InpTakeProfit), placed on the profitable side of the breakout entry, giving a 1:2 risk-to-reward on every position opened from a filled pending order.
Best for XAUUSD M15 traders who want a low-decision, mechanical breakout that fires only at the London and New York opens and who can accept a fixed 1:2 reward-to-risk with no trailing or partial-close management. Minimum recommended balance is $1,000 when the capital cap is enabled (InpCapFloor=1000) or the deposit itself when InpCapAmount=0 disables the cap; the default 0.01 lot, 40-point SL/80-point TP sizing means even a $100 account can arm orders, though tighter account equity raises the daily-loss trip risk. Run on a low-spread ECN or RAW account on a VPS with reliable clock and calendar connectivity (the news filter and GMT detection both depend on CalendarValueHistory and a stable server clock), and avoid running on brokers whose stops_level exceeds the 10-point breakout buffer.
Strategy Logic
Pipsgrowth EX02031 Breakout — Strategy Logic Analysis (from .mq5 source)
Family: Breakout
Magic: 22202031
Version: 2.00
BRIEF:
London and NY open breakout EA for XAUUSD that detects the pre-session range on M15 candles and places BuyStop/SellStop pending orders with buffer, SL and TP
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
HasTrade()OnTradeTransaction()DetectGMTOffset_EX02031()ServerToGMT_EX02031()IsMarketOpen_EX02031()InActiveSession_EX02031()IsNewsTime_EX02031()IsSafeToTrade_EX02031()UpdateDailyCounters_EX02031()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (5 total across 3 groups):
- [=== Identity ===]
InpMagicNumber=22202031// Magic Number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_02031" // TradeComment - [===
GMTSessionFilter(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 ---
// Pipsgrowth EX02031 Breakout — Execution Flow (from source analysis)
// Family: Breakout
// London and NY open breakout EA for XAUUSD that detects the pre-session range on M15 candles and places BuyStop/SellStop pending orders with buffer, SL and TP
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
How to Install This EA on MT5
- 1Download the .mq5 file using the button above
- 2Open MetaTrader 5 on your computer
- 3Click File → Open Data Folder in the top menu
- 4Navigate to MQL5 → Experts and paste the .mq5 file there
- 5In MT5, right-click Expert Advisors in the Navigator panel → Refresh
- 6Drag the EA onto an H1 or H4 chart
- 7Set the range detection period, breakout buffer, and lot size in the EA dialog
- 8Enable Allow Algo Trading and click OK
EA Parameters
| Parameter | Default | Description |
|---|---|---|
| InpMagicNumber | 22202031 | Magic Number |
| InpTradeComment | "Psgrowth.com Expert_02031" | Trade Comment |
| InpNewYorkEndGMT | 21 | --- Hardening: Capital Protection --- |
| InpCapAmount | 0.0 | Capital cap amount (0=disabled) |
| InpDailyLossLimitPct | 5.0 | --- Hardening: Trade Safety --- |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX02031 XAUUSDBreakout — London/NY open breakout on XAUUSD, full 12-layer stack."
#include <Trade\Trade.mqh>
input group "=== Identity ==="
input int InpMagicNumber = 22202031; // Magic Number
input string InpTradeComment = "Psgrowth.com Expert_02031"; // Trade Comment
input group "=== Strategy Parameters ==="
input int InpRangeCandles = 4;
input int InpBreakoutBuf = 10;
input group "=== Trade Management ==="
input double InpLotSize = 0.01;
input int InpStopLoss = 40;
input int InpTakeProfit = 80;
CTrade trade; datetime lastSession=0;
//--- Hardening Globals
int g_gmtOffset = 3;
int g_tradesToday = 0;
datetime g_dayStartTime = 0;
double g_initialBalance = 0.0;
datetime g_cooldownUntil = 0;
int g_consecLosses = 0;
double g_realizedToday = 0.0;
double g_realizedWeek = 0.0;
datetime g_weekStartTime = 0;
// --- Hardening: GMT Session Filter ---
input group "=== GMT Session Filter (Hardening) ===";
input bool InpUseGMTSessions = false;
input int InpLondonStartGMT = 7;
input int InpLondonEndGMT = 16;
input int InpNewYorkStartGMT = 12;
input int InpNewYorkEndGMT = 21;
// --- Hardening: Capital Protection ---
input group "=== Capital Protection (Hardening) ===";
// InpCapEnabled removed — use InpCapAmount=0 to disable
input double InpCapAmount = 0.0; // Capital cap amount (0=disabled)
input double InpCapFloor = 1000.0;
input double InpMinEquityPct = 70.0;
input double InpDailyLossLimitPct = 5.0;
// --- Hardening: Trade Safety ---
input group "=== Trade Safety (Hardening) ===";
input int InpMaxTradesPerDay = 10;
input int InpMaxConsecLosses = 5;
input int InpCooldownHours = 4;
input bool InpFilterNews = true;
input int InpNewsBufferMinutes = 30;
int OnInit() {
trade.SetExpertMagicNumber(InpMagicNumber);
trade.SetDeviationInPoints(30);
Full source code available on download
Educational purposes only. Do NOT use with real money. Test on demo accounts only.
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
Markets.com
Exness
IC Markets
Similar Expert Advisors
View All Expert AdvisorsMore Breakout strategy EAs from our library
Pipsgrowth EX02026 Breakout
Pipsgrowth.com EX02026 XAUUSD_M5_Donchian_EA — Donchian breakout with RSI and speed filter, full 12-layer stack.
Pipsgrowth EX02001 Breakout
Pipsgrowth.com EX02001 HFS NS92 XAUUSD 5M — fractal Donchian breakout with RSI extreme filter, full 12-layer stack.
Pipsgrowth EX02027 Breakout
Pipsgrowth.com EX02027 EX8 Multi-Symbol VWAP+KAMA Donchian — multi-symbol scalper with ADX regime switch, full 12-layer stack.
Community
Educational purposes only. Do NOT use with real money. Test on demo accounts only.