Pipsgrowth EX03017 Grid
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX03017 PipsGrowth_EA_PyramidHullRsiBB — multi-indicator pyramid scalper, full 12-layer stack.
Overview
Pipsgrowth EX03017 Grid is a pyramid scalper built for XAUUSD on the M5 and H1 timeframes, and it does not behave like a classic equal-step grid. The EA opens a single initial position on a confirmed multi-indicator signal, then layers additional same-direction positions on top of it only when every existing position in that direction is in profit and the most recent entry has already moved a minimum distance in the favorable direction. Each pyramid leg is opened with a smaller lot than the previous one, which is the opposite risk profile from a martingale and is what gives the system the name 'Pyramid' in its family tag.
The signal stack has three independent components, and all three must agree before any entry is allowed. The first is a Hull Moving Average built manually inside the EA from two Linear Weighted Moving Averages: an LWMA of the configurable period (InpHullPeriod = 20 by default) and an LWMA of half that period. The Hull value is the difference 2 × LWMA(half) − LWMA(full), then averaged across the square root of the period for smoothing. The Hull line is the trend filter. The second component is a standard 14-period RSI on the user-selected timeframe (InpRSIPeriod = 14, InpRSITF defaulting to H1). The third is Bollinger Bands with a 20-period lookback and 2.0 standard deviations (InpBBPeriod = 20, InpBBDeviation = 2.0). Each of these three indicators can run on its own timeframe via the InpHullTF, InpRSITF, and InpBBTF inputs, which default to 0 in the integer enum but resolve to H1 inside MapTimeframeInt.
A long signal requires four conditions to all be true on a closed bar: the Hull MA must be rising (its current value above the previous bar's value), the bid price must be above the current Hull, the RSI must be in the bullish range above 50 and below InpRSIOverbought (70 by default), and the price must still be below the Bollinger middle band so the trade has room to run before hitting the upper band. The short signal mirrors all four: Hull falling, price below Hull, RSI in the bearish range below 50 and above InpRSIOversold (30 default), and price above the BB middle. There is no ADX, no ATR, and no MACD in the stack. If any one of the four conditions is missing on a new bar, the EA does nothing that bar.
Pyramiding is what defines the strategy. After the initial position is open, every new bar that still produces the same-direction signal calls ProcessPyramidLogic, which performs two gating checks before adding a leg. The first is AllPositionsProfitable, which walks every position of the same type and refuses to pyramid if any one of them has profit ≤ 0 — so a losing trade in the stack blocks further adds. The second is LastPositionAtMinProfit, which measures the distance in points between the most recent position's open price and the current bid or ask, and refuses unless that distance is at least InpMinPyramidDistance (200 points default). When both gates pass, the EA calls OpenPosition with the next pyramid level. The new lot is base_lot × InpPyramidSizeRatio^(level − 1), where InpPyramidSizeRatio is 0.75 by default. So the second leg opens at 0.75 × base, the third at 0.5625 × base, the fourth at 0.4219 × base, and so on up to InpMaxPyramidLevels (3 default, capped at 5 in the input comment).
Trade management runs on every tick. The default stop is InpSlPoints = 300 points below entry for buys and above for sells, and the default target is InpTpPoints = 600 points — a fixed 1:2 risk-reward ratio. After the position moves InpTrailTrigger (150 points) in the favorable direction, ProcessTrailingStops begins ratcheting the stop to bid − InpTrailDistance (100 points) for buys, but only when the new stop is higher than the current stop and above the open price, so the trail can never move backward and never locks in a loss. If InpExitOnHullFlip is enabled (default true), ProcessHullFlipExits closes every buy position the moment the Hull turns bearish and every sell the moment it turns bullish, regardless of where the stop is.
Risk control beyond the per-trade SL is a hard 30 percent trailing drawdown cap measured from the running peak equity. IsDrawdownExceeded tracks the highest equity the account has reached since the EA started, and when equity drops more than InpMaxDDPercent (30 default) below that peak, the EA stops opening new positions entirely. There is no automatic close of existing positions when this triggers — it is a halt, not a flatten. The drawdown percentage is the difference between peak equity and current equity, so a recovered account that later dips again is judged from the new high. Other gates are layered on top: IsSpreadAcceptable blocks entries when the current spread is above InpMaxSpreadPoints (30 default), and IsSafeToTrade_EX03017 enforces the GMT session window, the cooldown timer, the equity floor, the daily and weekly loss limits, the per-day trade cap (InpMaxTradesPerDay = 50), and the consecutive-loss cap (InpMaxConsecLosses = 0 default, which disables the check). The cooldown kicks in after three consecutive losses and blocks new entries for InpCooldownMinutes (30 default).
The session filter uses DetectGMTOffset_EX03017 to estimate the broker's GMT offset by brute-forcing offsets from −12 to +12 and picking the one that best fits weekday and trading-hour heuristics. With InpUseGMTSessions enabled, the EA only allows entries when the computed GMT hour falls inside the London window (7 to 16) or the New York window (12 to 21), and never on Saturday or Sunday. TimeCurrent is converted via ServerToGMT_EX03017, which subtracts the estimated offset. Brokers with non-standard server times can be tuned by editing InpLondonStartGMT, InpLondonEndGMT, InpNewYorkStartGMT, and InpNewYorkEndGMT.
The visual layer is a 220 × 320 black dashboard pinned to the top-left corner. The panel shows the current signal word (BUY, SELL, or NEUTRAL) in lime, red, or yellow, the Hull value with a direction arrow, the RSI value colored lime above 50 and red below 50 and orange at the oversold and overbought thresholds, the three Bollinger band levels, the price's position relative to the bands (Above Upper, Upper Half, Lower Half, Below Lower), the live position count out of InpMaxPyramidLevels, the total P/L with sign, the floating points across all open positions, the current spread with an OK or HIGH tag, and a status line that reads ACTIVE, SPREAD, or DD HALT depending on the current gate state. When InpShowIndicators is enabled, the EA also draws a lime or red trend segment for the Hull line on every new bar, capped at 200 segments, and three horizontal lines for the Bollinger upper, middle, and lower bands.
Order execution goes through TryOpen_EX03017, which normalizes the lot to the broker's volume step, clamps it to the symbol's min and max lot, pre-checks the required margin via OrderCalcMargin against ACCOUNT_MARGIN_FREE, and then submits with CTrade::PositionOpen using ORDER_FILLING_IOC. On REQUOTE, TIMEOUT, PRICE_OFF, or PRICE_CHANGED the function retries up to three times with a 200 ms pause. Position modifications go through TryModify_EX03017 with the same retry policy, and TryClose_EX03017 closes positions the same way when the Hull flip triggers.
The OnTester fitness function is profit divided by max equity drawdown, multiplied by the profit factor when it is above 1 and zero otherwise. Optimization runs that produce fewer than 10 trades or a max drawdown of zero are returned zero, which makes the optimizer favor high-quality, low-drawback parameter sets. The combination of the trailing drawdown cap, the winner-only pyramid gate, the multi-indicator confirmation, and the four-way BUY or SELL filter means the EA is meant for trending intraday XAUUSD rather than ranging conditions — the strategy is biased toward pulling out of ranges with the trend, then layering in on legs that already work, and exiting on the first sign of a trend reversal signaled by the Hull.
Strategy Deep Dive
The OnTick handler calls UpdateIndicators which reads two Linear Weighted Moving Averages (LWMA full and LWMA half of InpHullPeriod), constructs Hull = 2 × LWMA(half) − LWMA(full), and averages across √period bars for smoothing. CheckBuySignal demands Hull rising, price above Hull, RSI in (50, InpRSIOverbought), and price below Bollinger middle; CheckSellSignal is the mirror. On a new bar with a valid signal and no open positions, the EA opens a single market order sized by 1 percent of balance against the 300-point stop. With positions open in the same direction, ProcessPyramidLogic adds a leg only when every same-direction position is profitable and the latest open price is at least InpMinPyramidDistance away, then scales the new lot to 0.75^(level-1) of the base. Every tick, ProcessTrailingStops ratchets the SL to 100 points behind bid or ask once profit exceeds 150 points, and ProcessHullFlipExits force-closes positions the moment the Hull crosses against them. The trailing drawdown gate stops all new entries at 30 percent off peak equity, and the session filter confines entries to London 7-16 GMT and New York 12-21 GMT.
Pyramid-style entry on a four-way confirmation: the Hull MA must be rising (long) or falling (short), the bid must be on the correct side of the Hull, RSI must sit in the bullish 50-70 band (long) or bearish 30-50 band (short), and price must still be below (long) or above (short) the Bollinger middle band. The first leg is opened at market; each subsequent leg is added only when all existing same-direction positions are profitable and the latest entry is at least InpMinPyramidDistance (200 points) away, with lot scaled by 0.75^(level-1).
Exit is the first to occur among three: InpTpPoints = 600 points fixed take-profit, the trailing stop ratchet once profit exceeds 150 points (trail distance 100 points), or a Hull-flip close that fires when the Hull crosses against the position's direction. The trailing stop only moves forward and never returns to breakeven, and the Hull-flip close ignores the stop level entirely.
Per-trade stop is InpSlPoints = 300 points (1:2 RR against the 600-point TP). After profit reaches 150 points the stop is ratcheted to 100 points behind price on every tick, but it only tightens and never widens. There is no global equity stop that flattens existing positions, but a 30 percent trailing drawdown from peak equity halts all new entries until equity recovers.
Fixed InpTpPoints = 600 points (1:2 RR against the 300-point SL). On XAUUSD with 2-decimal points that is roughly $60 per 0.10 lot at the default risk. The TP is set on the order at entry and is the dominant exit when the trend runs cleanly to target.
Best for trending intraday XAUUSD on M5, with the underlying signals computed on H1 by default; works for any single-symbol gold setup where the broker offers tight spreads (under 30 points) and supports ORDER_FILLING_IOC. Minimum recommended balance: $100 (per the EA's listed floor) but expect to need $1,000+ in practice to support a full 3-level pyramid against 300-point stops without hitting the 30 percent drawdown halt. The EA blocks all entries outside London and New York hours in GMT and refuses to open when 30+ point spreads widen.
Strategy Logic
Pipsgrowth EX03017 Grid — Strategy Logic Analysis (from .mq5 source)
Family: Grid
Magic: 22203017
Version: 2.00
BRIEF:
Multi-indicator pyramid scalper combining Hull MA trend direction, RSI momentum filter and Bollinger Bands price context. Adds same-direction legs only to winning positions with decreasing lot size per level. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
UpdateIndicators()CalculateHullMA()GetIndicatorValue()CheckBuySignal()CheckSellSignal()CountPositions()ProcessPyramidLogic()AllPositionsProfitable()LastPositionAtMinProfit()OpenPosition()CalculateLotSize()NormalizeLots()- ...and 17 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (31 total across 8 groups):
- [=== General Settings ===]
InpMagicNumber=22203017// Magic number - [=== General Settings ===]
InpRiskPercent=1.0// Risk % per position (0.1-10) - [=== General Settings ===]
InpSlPoints= 300 // StopLoss(points) - [=== General Settings ===]
InpTpPoints= 600 // TakeProfit(points) - [=== General Settings ===]
InpMaxSpreadPoints= 30 // Max allowed spread (points) - [=== Pyramid Settings ===]
InpEnablePyramid=true// Enable pyramiding - [=== Pyramid Settings ===]
InpMaxPyramidLevels= 3 // Max pyramid positions (1-5) - [=== Pyramid Settings ===]
InpMinPyramidDistance= 200 // Min points before nextlevel - [=== Pyramid Settings ===]
InpPyramidSizeRatio=0.75// Lot multiplier perlevel(0.5-1.0) - [=== Hull MA Settings ===]
InpHullPeriod= 20 // Hull MAPeriod(10-100) - [=== Hull MA Settings ===]
InpHullTF= 0 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Hull Timeframe - [===
RSISettings ===]InpRSIPeriod= 14 //RSIPeriod(5-50) - [===
RSISettings ===]InpRSIOverbought= 70 // Overboughtlevel(60-90) - [===
RSISettings ===]InpRSIOversold= 30 // Oversoldlevel(10-40) - [===
RSISettings ===]InpRSITF= 0 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) //RSITimeframe - [=== Bollinger Bands Settings ===]
InpBBPeriod= 20 //BBPeriod(10-50) - [=== Bollinger Bands Settings ===]
InpBBDeviation=2.0//BBDeviation(1.0-3.0) - [=== Bollinger Bands Settings ===]
InpBBPrice= 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) //BBApplied Price - [=== Bollinger Bands Settings ===]
InpBBTF= 0 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) //BBTimeframe - [=== Exit Settings ===]
InpEnableTrailing=true// Enable Trailing Stop - [=== Exit Settings ===]
InpTrailTrigger= 150 // Trail trigger (points) - [=== Exit Settings ===]
InpTrailDistance= 100 // Trail distance (points) - [=== Exit Settings ===]
InpExitOnHullFlip=true// Exit on Hull reversal - [=== Exit Settings ===]
InpMaxDDPercent=30.0// Max Drawdown % (halt trading) - [=== Dashboard Settings ===]
InpShowDashboard=true// Show Dashboard - [=== Dashboard Settings ===]
InpShowIndicators=true// Draw indicators on chart - [=== Dashboard Settings ===]
InpDashBgColor=clrBlack// Dashboard background - [=== Dashboard Settings ===]
InpDashTextColor=clrWhite// Dashboard text color - [=== Dashboard Settings ===]
InpDashX= 10 // Dashboard X position - [=== Dashboard Settings ===]
InpDashY= 30 // Dashboard Y position - [=== Hardening Trade Safety ===]
InpMaxConsecLosses= 0 // +------------------------------------------------------------------+
// Pipsgrowth EX03017 Grid — Execution Flow (from source analysis)
// Family: Grid
// Multi-indicator pyramid scalper combining Hull MA trend direction, RSI momentum filter and Bollinger Bands price context. Adds same-direction legs only to winning positions with decreasing lot size per level. 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 | 22203017 | Magic number |
| InpRiskPercent | 1.0 | Risk % per position (0.1-10) |
| InpSlPoints | 300 | Stop Loss (points) |
| InpTpPoints | 600 | Take Profit (points) |
| InpMaxSpreadPoints | 30 | Max allowed spread (points) |
| InpEnablePyramid | true | Enable pyramiding |
| InpMaxPyramidLevels | 3 | Max pyramid positions (1-5) |
| InpMinPyramidDistance | 200 | Min points before next level |
| InpPyramidSizeRatio | 0.75 | Lot multiplier per level (0.5-1.0) |
| InpHullPeriod | 20 | Hull MA Period (10-100) |
| InpHullTF | 0 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Hull Timeframe |
| InpRSIPeriod | 14 | RSI Period (5-50) |
| InpRSIOverbought | 70 | Overbought level (60-90) |
| InpRSIOversold | 30 | Oversold level (10-40) |
| InpRSITF | 0 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // RSI Timeframe |
| InpBBPeriod | 20 | BB Period (10-50) |
| InpBBDeviation | 2.0 | BB Deviation (1.0-3.0) |
| InpBBPrice | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // BB Applied Price |
| InpBBTF | 0 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // BB Timeframe |
| InpEnableTrailing | true | Enable Trailing Stop |
| InpTrailTrigger | 150 | Trail trigger (points) |
| InpTrailDistance | 100 | Trail distance (points) |
| InpExitOnHullFlip | true | Exit on Hull reversal |
| InpMaxDDPercent | 30.0 | Max Drawdown % (halt trading) |
| InpShowDashboard | true | Show Dashboard |
| InpShowIndicators | true | Draw indicators on chart |
| InpDashBgColor | clrBlack | Dashboard background |
| InpDashTextColor | clrWhite | Dashboard text color |
| InpDashX | 10 | Dashboard X position |
| InpDashY | 30 | Dashboard Y position |
| InpMaxConsecLosses | 0 | +------------------------------------------------------------------+ |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX03017 PipsGrowth_EA_PyramidHullRsiBB — multi-indicator pyramid scalper, full 12-layer stack."
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
//+------------------------------------------------------------------+
//| Input Parameters |
//+------------------------------------------------------------------+
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_InpHullTF = PERIOD_H1;
ENUM_TIMEFRAMES g_InpRSITF = PERIOD_H1;
ENUM_TIMEFRAMES g_InpBBTF = PERIOD_H1;
ENUM_APPLIED_PRICE g_InpBBPrice = PRICE_CLOSE;
input group "=== General Settings ==="
input ulong InpMagicNumber = 22203017; // Magic number
input string InpTradeComment = "Psgrowth.com Expert_03017";
input double InpRiskPercent = 1.0; // Risk % per position (0.1-10)
input int InpSlPoints = 300; // Stop Loss (points)
input int InpTpPoints = 600; // Take Profit (points)
input int InpMaxSpreadPoints = 30; // Max allowed spread (points)
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)
{
case 1: return PERIOD_M1;
case 2: return PERIOD_M5;
case 3: return PERIOD_M15;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 EX03026 Grid
Pipsgrowth.com EX03026 USDJPY_Aggressive_Pyramid — MTF Hull MA pyramid with regime detection, full 12-layer stack.
Pipsgrowth EX03001 Grid
Pipsgrowth.com EX03001 Thanos Grid Adaptive — bidirectional ATR-spaced stop-order grid, full 12-layer stack.
Pipsgrowth EX03020 Grid
Pipsgrowth.com EX03020 GridScalperMA — dynamic grid with MA trend filter, full 12-layer stack.
Community
Educational purposes only. Do NOT use with real money. Test on demo accounts only.