Pipsgrowth EX03016 Grid
MT5 Expert Advisor (Open Source) · XAUUSD, XAGUSD · M5, M30
Pipsgrowth.com EX03016 PipsGrowth_EA_GoldScalpingPyramid — gold breakout scalper with pyramid scaling, full 12-layer stack.
Overview
Pipsgrowth EX03016 — Gold Scalping Pyramid takes a $100 starting account and aims to scalp breakout continuations on XAUUSD and XAGUSD with progressive position scaling. Unlike a martingale grid, it only adds same-direction legs when every open position is in profit, which means exposure grows with confirmed momentum rather than against a losing streak. The EA runs on a configurable scalp timeframe (default M30) and is built around a multi-timeframe scoring engine, a swing break-of-structure detector, and a dollar-denominated risk envelope.
Signal scoring drives every entry. AnalyzeMarket() reads three RSIs(14) on three different timeframes (scalp, medium, trend) plus ATR(14) on the scalp timeframe, then combines them with a swing break-of-structure test. The default mapping is M30 (scalp) / H4 (medium) / D1 (trend), but each of the three RSI timeframes is a numeric input (1–7 → M1, M5, M15, M30, H1, H4, D1), so the EA can be retargeted to any combination. RSI extremes contribute ±20 points (scalp oversold/overbought vs InpRSIOversold/InpRSIOverbought, default 30/70), the medium RSI adds ±15 as a momentum cross-check, and the trend RSI adds ±15 as a directional bias. A confirmed break above the most recent swing high — or below the most recent swing low — by at least InpMinBreakoutPoints (50 points) awards ±30. Finally, if current ATR is more than InpATRVelocityThreshold (1.2×) above the 20-bar average, the side currently leading the score gets +20. Any side whose score exceeds the other side and clears the threshold InpMinSignalStrength (50) fires a trade. The dashboard prints the line "BUY: RSI(74.2,55.1,62.3) BOS=1 Str=78" so the exact contributing factors are visible on every bar.
UpdateMarketStructure() rebuilds the swing high and swing low each new bar. It walks the last 3× InpSwingLookback (45 bars by default) on the scalp timeframe and tags any bar whose high strictly exceeds its 3-bar neighbors in both directions as a swing high; the same applies to the lows. The most recent qualifying swing sets the levels CheckBreakOfStructure() compares to current bid/ask. The 50-point minimum breakout size keeps the EA away from noise breaks on a quiet gold session.
The pyramid path is what makes EX03016 different from a vanilla breakout EA. Once a first leg is open, the EA can add up to InpMaxPyramidLegs-1 (2) additional same-direction legs, but only when CanAddPyramidLeg() approves: there must already be an open position of the same direction; if InpRequireAllProfitable is on (default), every open position must be in profit; the most recent position must show at least InpMinProfitForNextLeg ($1.50 default) of profit; and at least 60 seconds must have elapsed since the last trade. When those gates all pass, ExecutePyramidLeg() opens a new entry at a lot size scaled by InpPyramidLotMultiplier^(leg-1) — so with the default multiplier of 1.0, every leg is the same size; raise the multiplier to 1.2–1.5 for proper geometric scaling. Total lot size is hard-capped at InpMaxLotSize (0.05 default for a 100-dollar account), and CalculateLotSize() also shrinks orders automatically if OrderCalcMargin shows the trade would consume more than 80% of the free margin. The first leg is sized from InpBaseLotSize (0.01), normalized to the symbol's lot step and minimum lot, so a 0.01/0.05 configuration gives 1–5 legs before the cap binds.
Risk is expressed in dollars rather than pips. The default configuration is $3 stop loss and $6 take profit per position — a 1:2 reward-to-risk ratio scaled to the lot size of the leg. DollarsToPoints() converts the dollar value into points using the symbol's tick value, tick size, and per-lot notional, so a 0.01-lot gold position gets a wider point stop than a 0.05-lot position, and the dollar risk stays constant. ManageTrailingStops() runs on every tick (not just new bars) once InpUseTrailingStop is on: when a position's profit exceeds InpTrailActivationDollars ($2), the EA ratchets the stop to bid-trailDistance for buys or ask+trailDistance for sells, and only ratchets forward — never backward — and never behind the open price, so the stop locks into profit territory after activation. The static $3 stop and the trailing stop work in concert: the static defines the per-position maximum loss, and the trailing protects open profits once the move is underway.
A 30% trailing-drawdown kill switch sits on top of the position-level stops. IsDrawdownExceeded() tracks g_peakEquity as the high-water mark and computes ((peak − equity) / peak) × 100. If the drawdown crosses InpMaxDrawdownPercent (30%), tradingEnabled flips to false, no new entries are accepted, and the EA only resumes on the next calendar day when CheckNewDay() resets the flag. There is no equity-floor kill switch or daily-loss-limit kill switch — the global DD cap is the single hard stop, which is intentional for a 100-dollar account the EA is configured to grow through breakouts. The OnTick logic also has a per-bar filter: it only processes signals on new bars of the scalp timeframe, runs ManageTrailingStops() on every tick, and respects a spread filter that blocks entries when the symbol spread exceeds InpMaxSpreadPoints (50 points, ≈ 5 pips on a 3/5-digit gold quote).
Session control is opt-in. InpUseSessionFilter defaults to false, so the EA will trade every hour the market is open if you leave the flag alone. Flip it on and IsValidSession() limits entries to London (InpLondonStartHour–InpLondonEndHour, default 8–16 GMT) and New York (13–21 GMT), which for XAUUSD gives a continuous window from 8 GMT to 21 GMT. The on-chart dashboard shows live values: balance, equity, peak equity, drawdown percent, scalp RSI, ATR, current spread, pyramid legs vs. the cap, aggregate dollar P/L, the most recent signal description, and an ACTIVE / HALTED status flag with the day's trade count. Colors are configurable via InpDashColor, InpProfitColor, InpLossColor.
Order handling uses TRADE_ACTION_DEAL with a 50-point slippage allowance and ORDER_FILLING_FOK. TryOrderSend_EX03016() retries up to 3 times with a 200ms sleep on TRADE_RETCODE_REQUOTE, TIMEOUT, PRICE_OFF, and PRICE_CHANGED; any other retcode (insufficient margin, invalid stops, etc.) breaks the loop and returns false so the EA does not hammer the order queue. Positions are identified by symbol + magic 22203016, so the EA will not touch positions opened manually or by other EAs on the same account.
What the backtester needs to know: with InpMinBreakoutPoints at 50, the EA prefers wide swings and will be quiet on the 5-minute chart of gold but reasonably active on M30 and H1, where the 50-point threshold is a much smaller fraction of the bar range. The dollar-based stops scale with lot size, so a backtest on a $100 account and a backtest on a $1,000 account will produce different per-trade dollar P/L but the same pips-equivalent move. The 30% trailing drawdown cap is the single most important portfolio-level risk parameter — drop it lower (15–20%) if you want the EA to be more conservative, or raise it (40–50%) if you want to give the pyramid room to scale on a fast XAUUSD move. The InpInitialBalance input (default 100) is purely a label printed at init — actual sizing flows from AccountInfoDouble(ACCOUNT_BALANCE) — so the field is a comment for the user, not a sizing cap.
Strategy Deep Dive
EX03016 runs a multi-timeframe RSI stack alongside a swing break-of-structure test and an ATR velocity filter to score each side of the market on every new scalp-timeframe bar. The score components — scalp-RSI extremes (20), medium-RSI momentum (15), trend-RSI direction (15), break of structure (30), and velocity (20) — are summed, and the leading side opens a position when it clears InpMinSignalStrength and no positions are open. Once a first leg is in profit, the same score can trigger pyramid additions up to InpMaxPyramidLegs (3), gated by CanAddPyramidLeg() which requires same direction, all positions profitable, the latest leg at InpMinProfitForNextLeg ($1.50) profit, and a 60-second cooldown. The trade envelope is dollar-based — $3 stop, $6 target, $2 trail activation, $1 trail distance — with a 30% trailing-drawdown kill switch on top that halts new entries until the next day. OnTick also enforces a 50-point spread filter, and a per-bar signal filter that runs only on new bars of the configured scalp timeframe (M30 by default), with a live on-chart dashboard showing every relevant value.
A long signal fires when the multi-timeframe RSI stack (default M30/H4/D1), the swing break-of-structure test, and the ATR velocity filter collectively push the buy score above the sell score by at least InpMinSignalStrength (50). Break of structure is the single largest contributor at 30 points, followed by scalp-RSI extremes (20 points) when RSI(14) crosses below InpRSIOversold (30) or above InpRSIOverbought (70), and the velocity check (20 points). A short signal mirrors the same scoring with inverted thresholds. The first leg opens immediately when no positions are open; subsequent pyramid legs require CanAddPyramidLeg() to clear the same-direction, all-profitable, last-leg-min-profit, and 60-second timing gates.
Exits happen through three paths: the static $3 stop loss closes losing positions at the leg level, the $6 take profit locks in winners at 1:2 RR, and ManageTrailingStops() ratchets the stop forward once profit exceeds $2 to protect open gains. The 30% trailing-drawdown kill switch flips tradingEnabled to false and prevents new entries when portfolio drawdown breaches the cap, resuming only at the next calendar day via CheckNewDay(). There is no time-based or bar-based exit — positions are held until the stop, the target, or the trailing stop, whichever comes first.
Per-position stop is set in dollars rather than pips, defaulting to $3 converted to points via DollarsToPoints() so the stop scales with lot size while the dollar risk stays constant. The same dollar value is applied to every leg of the pyramid, and the 30% trailing-drawdown cap is the single portfolio-level hard stop that halts new entries on the day the cap is hit.
Per-position take profit is $6, giving a 1:2 reward-to-risk ratio against the $3 stop. Trailing stop activation at $2 profit and a $1 trail distance is the second profit-taking layer, designed to let winners run past the static target by ratcheting the stop forward on every tick once the position is in profit.
Minimum recommended balance: $100 (per InpInitialBalance default) — the EA sizes from account balance and applies an 80% free-margin safety in CalculateLotSize(), so larger accounts simply scale up the cap. The 30% drawdown cap and dollar-based stops make this a very-high-risk tool, so it's best suited to accounts that can absorb that drawdown without forcing a stop-out, ideally on XAUUSD or XAGUSD. Default working timeframes are M30 scalp / H4 medium / D1 trend; the supported list is M5 to M30 per the brief. The session filter is off by default, so turn it on if you want to limit entries to London + New York hours (8–21 GMT combined).
Strategy Logic
Pipsgrowth EX03016 Grid — Strategy Logic Analysis (from .mq5 source)
Family: Grid
Magic: 22203016
Version: 2.00
BRIEF:
Gold breakout scalper with pyramid scaling using multi-TF RSI alignment, break of structure detection, ATR velocity filter and session filter. Adds same-direction legs only when all positions are profitable. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
CheckNewDay()IsDrawdownExceeded()IsValidSession()CountPyramidPositions()AllPositionsProfitable()LastPositionAtMinProfit()GetAggregateProfitDollars()GetCurrentPositionDirection()CanAddPyramidLeg()GetRSIValue()GetATRValue()GetAverageATR()- ...and 14 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (35 total across 9 groups):
- [=== Core Settings ===]
InpMagicNumber=22203016// Magic number - [=== Core Settings ===]
InpInitialBalance=100.0// Initial account balance ($) - [=== Pyramid Settings ===]
InpMaxPyramidLegs= 3 // Maximum pyramid positions - [=== Pyramid Settings ===]
InpMinProfitForNextLeg=1.50// Min profit ($) before adding leg - [=== Pyramid Settings ===]
InpRequireAllProfitable=true// All positions must be profitable - [=== Pyramid Settings ===]
InpPyramidLotMultiplier=1.0// Lot multiplier for subsequent legs - [=== Risk Management ===]
InpBaseLotSize=0.01// Base lot size - [=== Risk Management ===]
InpMaxLotSize=0.05// Maximum total lot size - [=== Risk Management ===]
InpStopLossDollars=3.0// Stop loss per position ($) - [=== Risk Management ===]
InpTakeProfitDollars=6.0// Take profit per position ($) - [=== Risk Management ===]
InpMaxDrawdownPercent=30.0// Max trailing drawdown (%) - [=== Risk Management ===]
InpMaxSpreadPoints= 50 // Max allowed spread (points) - [=== Trailing Stop ===]
InpUseTrailingStop=true// Enable trailing stop - [=== Trailing Stop ===]
InpTrailActivationDollars=2.0// Activate after profit ($) - [=== Trailing Stop ===]
InpTrailDistanceDollars=1.0// Trailing distance ($) - [=== Signal Settings ===]
InpMinSignalStrength= 50 // Minimum signal strength (0-100) - [=== Signal Settings ===]
InpRSIPeriod= 14 //RSIperiod - [=== Signal Settings ===]
InpRSIOverbought= 70 //RSIoverboughtlevel - [=== Signal Settings ===]
InpRSIOversold= 30 //RSIoversoldlevel - [=== Signal Settings ===]
InpATRPeriod= 14 //ATRperiod - [=== Signal Settings ===]
InpATRVelocityThreshold=1.2//ATRvelocity multiplier - [=== Timeframe Settings ===]
g_InpScalpTF= 4 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Scalping timeframe - [=== Timeframe Settings ===]
InpMediumTF= 6 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Medium timeframe - [=== Timeframe Settings ===]
InpTrendTF= 7 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Trend timeframe - [=== Session Settings ===]
InpUseSessionFilter=false// Enable session filter - [=== Session Settings ===]
InpLondonStartHour= 8 // London start (GMT) - [=== Session Settings ===]
InpLondonEndHour= 16 // London end (GMT) - [=== Session Settings ===]
InpNYStartHour= 13 // NY start (GMT) - [=== Session Settings ===]
InpNYEndHour= 21 // NY end (GMT) - [=== Market Structure ===]
InpSwingLookback= 15 // Swing detection lookback - [=== Market Structure ===]
InpMinBreakoutPoints= 50 // Min breakout size (points) - [===
DASHBOARD===]InpShowDashboard=true// Show dashboard - [===
DASHBOARD===]InpDashColor=clrWhite// Dashboard color - [===
DASHBOARD===]InpProfitColor=clrLime// Profit color - [===
DASHBOARD===]InpLossColor=clrRed// Loss color
// Pipsgrowth EX03016 Grid — Execution Flow (from source analysis)
// Family: Grid
// Gold breakout scalper with pyramid scaling using multi-TF RSI alignment, break of structure detection, ATR velocity filter and session filter. Adds same-direction legs only when all positions are profitable. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
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 a chart — H1 or H4 is recommended for grid EAs
- 7Set grid step (pips), maximum orders, and lot size in the EA dialog
- 8Enable Allow Algo Trading and click OK
EA Parameters
| Parameter | Default | Description |
|---|---|---|
| InpMagicNumber | 22203016 | Magic number |
| InpInitialBalance | 100.0 | Initial account balance ($) |
| InpMaxPyramidLegs | 3 | Maximum pyramid positions |
| InpMinProfitForNextLeg | 1.50 | Min profit ($) before adding leg |
| InpRequireAllProfitable | true | All positions must be profitable |
| InpPyramidLotMultiplier | 1.0 | Lot multiplier for subsequent legs |
| InpBaseLotSize | 0.01 | Base lot size |
| InpMaxLotSize | 0.05 | Maximum total lot size |
| InpStopLossDollars | 3.0 | Stop loss per position ($) |
| InpTakeProfitDollars | 6.0 | Take profit per position ($) |
| InpMaxDrawdownPercent | 30.0 | Max trailing drawdown (%) |
| InpMaxSpreadPoints | 50 | Max allowed spread (points) |
| InpUseTrailingStop | true | Enable trailing stop |
| InpTrailActivationDollars | 2.0 | Activate after profit ($) |
| InpTrailDistanceDollars | 1.0 | Trailing distance ($) |
| InpMinSignalStrength | 50 | Minimum signal strength (0-100) |
| InpRSIPeriod | 14 | RSI period |
| InpRSIOverbought | 70 | RSI overbought level |
| InpRSIOversold | 30 | RSI oversold level |
| InpATRPeriod | 14 | ATR period |
| InpATRVelocityThreshold | 1.2 | ATR velocity multiplier |
| g_InpScalpTF | 4 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Scalping timeframe |
| InpMediumTF | 6 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Medium timeframe |
| InpTrendTF | 7 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Trend timeframe |
| InpUseSessionFilter | false | Enable session filter |
| InpLondonStartHour | 8 | London start (GMT) |
| InpLondonEndHour | 16 | London end (GMT) |
| InpNYStartHour | 13 | NY start (GMT) |
| InpNYEndHour | 21 | NY end (GMT) |
| InpSwingLookback | 15 | Swing detection lookback |
| InpMinBreakoutPoints | 50 | Min breakout size (points) |
| InpShowDashboard | true | Show dashboard |
| InpDashColor | clrWhite | Dashboard color |
| InpProfitColor | clrLime | Profit color |
| InpLossColor | clrRed | Loss color |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX03016 PipsGrowth_EA_GoldScalpingPyramid — gold breakout scalper with pyramid scaling, full 12-layer stack."
//+------------------------------------------------------------------+
//| Input Parameters |
//+------------------------------------------------------------------+
//--- Core Settings
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)
{
case 1: return PERIOD_M1;
case 2: return PERIOD_M5;
case 3: return PERIOD_M15;
case 4: return PERIOD_M30;
case 5: return PERIOD_H1;
case 6: return PERIOD_H4;
case 7: return PERIOD_D1;
default: return PERIOD_H1;
}
}
ENUM_APPLIED_PRICE MapAppliedPriceInt(int ap)
{
switch(ap)
{
case 1: return PRICE_CLOSE;
case 2: return PRICE_OPEN;
case 3: return PRICE_HIGH;
case 4: return PRICE_LOW;
case 5: return PRICE_MEDIAN;
case 6: return PRICE_TYPICAL;
case 7: return PRICE_WEIGHTED;
default: return PRICE_CLOSE;
}
}
ENUM_TIMEFRAMES g_InpScalpTF = PERIOD_H1;
ENUM_TIMEFRAMES g_InpMediumTF = PERIOD_H1;
ENUM_TIMEFRAMES g_InpTrendTF = PERIOD_H1;
input group "=== Core Settings ===" input int InpMagicNumber =
22203016; // Magic number
input string InpTradeComment = "Psgrowth.com Expert_03016";
input double InpInitialBalance = 100.0; // Initial account balance ($)
//--- Pyramid Settings
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)
{
case 1: return PERIOD_M1;
case 2: return PERIOD_M5;
case 3: return PERIOD_M15;
case 4: return PERIOD_M30;
case 5: return PERIOD_H1;
case 6: return PERIOD_H4;
case 7: return PERIOD_D1;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 Grid strategy EAs from our library
Pipsgrowth EX03022 Grid
Pipsgrowth.com EX03022 HedgingGridEA — hedging + grid recovery, full 12-layer stack.
Pipsgrowth EX03027 Grid
Pipsgrowth.com EX03027 Gold_EMA_SuperTrend — EMA crossover + SuperTrend pyramid scalper, full 12-layer stack.
Pipsgrowth EX03021 Grid
Pipsgrowth.com EX03021 GridXPro — grid with optional martingale for major pairs, full 12-layer stack.
Community
Educational purposes only. Do NOT use with real money. Test on demo accounts only.