P
PipsGrowth
GridOpen Source – Free

Pipsgrowth EX03024 Grid

MT5 Expert Advisor (Open Source) · XAUUSD · M5

Pipsgrowth.com EX03024 ControlGrid_XAUUSD_5M — RSI-filtered grid with lot multiplier and basket TP, full 12-layer stack.

Overview

Pipsgrowth EX03024 is a one-direction-at-a-time averaging grid for XAUUSD on the M5 chart. The whole point of the EA is the way it opens its first trade: a single 14-period RSI on close price decides whether the first leg is a buy or a sell, and the EA then commits to averaging into that direction with up to four follow-up entries at fixed 300-point spacing. The grid grows one rung at a time as price moves against the initial entry, and each rung carries its own 500-point take-profit. There is no martingale by default, no hedge grid, no pending-order ladder, no per-trade stop-loss, and no basket profit target — the architecture is closer to a disciplined DCA plus target than a true market-maker grid.

The decision tree starts in OnTick(). Every tick first calls UpdateDailyCounters_EX03024() to roll the realized P&L buckets when the day changes, then refreshes the symbol object with mysymbol.RefreshRates(). Two hard gates fire before any strategy logic: a spread filter at mysymbol.Spread() > InpMaxSpread (250 points) and the consolidated IsSafeToTrade_EX03024() function. The safety function checks the GMT session, the cooldown timer, an optional equity floor (InpEquityFloor), an optional realized-daily loss cap (InpDailyLossLimit), an optional realized-weekly loss cap (InpWeeklyLossLimit), an optional balance cap (InpCapitalCap), the max-trades-per-day limit, and the optional max-consecutive-losses gate. If any of these blocks, the tick returns silently and the EA does nothing — no entries, no adjustments, no grid add-ons.

With the safety gates clear, the EA runs ManageGrid() unconditionally on every tick, then CheckSignal() only on the open of a fresh M5 bar (guarded by a static lastBar == currentBar comparison). CheckSignal() ignores the grid and fires only when PositionsTotal() == 0 — once any position exists, the grid owns the runtime and the RSI entry is dormant. When the position book is empty, CheckSignal() copies the previous-bar RSI value with CopyBuffer(hRSI, 0, 1, 1, bufRSI) and branches on the level: a value below 30 calls OpenBuy(InpStartLot), a value above 70 calls OpenSell(InpStartLot). The InpUseRSIFilter input lets the user disable the filter, but the source still calls the same CheckSignal() function — disabling it just leaves the position book to be filled by the grid logic instead, so the EA will still only ever build from the first RSI-driven anchor.

The grid logic is the heart of the EA. ManageGrid() walks PositionsTotal() from the most recent ticket to the oldest, filtering on position.Symbol() == _Symbol && position.Magic() == InpMagicNumber (the magic default is 22203024). For every buy position it tracks the count and the lowest open price, and for every sell position it tracks the count and the highest open price. Then it compares the current mysymbol.Bid() against the last buy open price: if the bid is at least InpGridStep * mysymbol.Point() (300 points) below the lowest buy, it opens another buy sized at lastBuyLot * InpLotMultiplier. The mirror logic applies to sells — if the ask is at least 300 points above the highest sell, it opens another sell at the multiplied lot. The cap is InpMaxLevels (5 by default), so the grid tops out at 5 buys in a row or 5 sells in a row. With InpLotMultiplier = 1.0 the lot is fixed at InpStartLot (0.01) and every rung is identical, so the EA is a true averaging-in grid rather than a martingale. Setting the multiplier above 1.0 turns it into a soft martingale: 0.01, 0.015, 0.0225, 0.0338, 0.0506 across five rungs at 1.5×.

Each OpenBuy() and OpenSell() call calculates a per-trade take-profit of mysymbol.Ask() + InpTakeProfit * mysymbol.Point() (or Bid - 500 points for sells) and passes a stop-loss of 0 to the trade request. There is no SL anywhere in the system — the only stop is the optional InpEquityFloor and the realized-loss caps in IsSafeToTrade_EX03024(). TryBuy_EX03024() and TrySell_EX03024() both run a pre-trade margin check via OrderCalcMargin() (the trade is refused before the request goes out if marginReq > AccountInfoDouble(ACCOUNT_MARGIN_FREE)), then retry the order three times at 200ms gaps on the transient retcodes REQUOTE, TIMEOUT, PRICE_OFF, and PRICE_CHANGED. ORDER_FILLING_FOK is set in OnInit() and the slippage tolerance is InpSlippage points.

The trailing infrastructure is the rest of the hardening layer. DetectGMTOffset_EX03024() runs a best-of sweep from -12 to +12 on the server clock to guess the broker's GMT offset, scoring each candidate by weekday and trading-hour likelihood — the winner seeds g_gmtOffset and ServerToGMT_EX03024() adjusts every session check. InActiveSession_EX03024() blocks the weekend (Saturday and Sunday return false immediately) and, when InpUseGMTSessions is true, restricts the trading window to the union of InpLondonStartGMT=7 through InpLondonEndGMT=16 and InpNewYorkStartGMT=12 through InpNewYorkEndGMT=21. OnTradeTransaction() listens for TRADE_TRANSACTION_DEAL_ADD events that match the magic and the symbol, adds the profit + swap + commission to the daily and weekly realized buckets, increments the hardcoded g_consecLossesHD on a losing deal, and resets it on a win. Three consecutive losses hardcode a 30-minute cooldown via g_cooldownUntil = TimeCurrent() + InpCooldownMinutes * 60 — this cooldown is independent of InpMaxConsecLosses, which is left at 0 (disabled) in the source.

OnTester() returns a custom fitness score of (profit / maxDD) * (pf > 1 ? pf : 0), gated on maxDD > 0 and a minimum of 10 closed trades. The strategy optimizer therefore rewards high net return relative to the worst peak-to-trough drawdown, and it cancels the score entirely if the profit factor fails to clear 1.0. Because the EA is a one-direction DCA, the optimiser finds different sweet spots from a true market-maker grid: tighter grid steps profit in shallow ranging while wider steps survive deeper pullbacks. Tuning the multiplier toward 1.0 keeps the worst-case lot exposure proportional to the account; pushing it above 1.5 turns EX03024 into a martingale where the loss of a full five-rung basket equals roughly 7.6× the risk of the first leg.

Strategy Deep Dive

On every tick the EA first runs UpdateDailyCounters_EX03024() and IsSafeToTrade_EX03024() to enforce the GMT session (London 7-16, NY 12-21, no weekend), the spread ceiling (250 points), the cooldown timer, the equity floor, the realized daily/weekly loss caps, the balance cap, the max-trades-per-day limit, and the consecutive-loss gate. With the gates clear, ManageGrid() walks every open position whose magic is 22203024 and symbol matches the chart, finds the lowest-priced buy and the highest-priced sell, and arms the next rung when Bid < lastBuyPrice - 300*Point (or the mirror for sells), capped at InpMaxLevels (5) per side with lot scaled by InpLotMultiplier. CheckSignal() runs only on a fresh M5 bar and only when no position is open, calling OpenBuy on RSI(14) < 30 or OpenSell on RSI(14) > 70. Each OpenBuy/OpenSell writes a 500-point take-profit into the order and a 0 stop-loss; TryBuy_EX03024 / TrySell_EX03024 pre-check the margin and retry three times at 200ms on transient retcodes. OnTradeTransaction() updates the realized P&L buckets and the hardcoded g_consecLossesHD counter — three stacked losses trip a 30-minute cooldown regardless of the InpMaxConsecLosses input. OnTester() returns (profit/maxDD)*(pf>1?pf:0), gated on maxDD > 0 and at least 10 trades.

Entry Signal

The first trade is opened by a 14-period RSI on close: a reading below 30 calls OpenBuy(InpStartLot) and a reading above 70 calls OpenSell(InpStartLot). Once any position is open the RSI is dormant and the EA waits for price to move InpGridStep (300 points, 30 pips on XAUUSD) against the entry, then adds a follow-up at lastBuyLot * InpLotMultiplier (or the mirror for sells), up to InpMaxLevels (5) total in the same direction. The InpUseRSIFilter input can disable the RSI gate but does not turn the EA into a market-maker — the grid still builds from the anchor of the first position.

Exit Signal

Exits are strictly per-trade: each individual order carries its own 500-point (50-pip) take-profit and is closed by the broker when the bid/ask crosses that level. There is no basket profit target, no per-trade stop-loss, and no time-based exit — the only thing that flattens the whole position book in one pass is the optional InpEquityFloor or the realized-loss caps in IsSafeToTrade_EX03024().

Stop Loss

No per-trade stop-loss is sent on any order (the SL argument to TryBuy_EX03024 / TrySell_EX03024 is hardcoded to 0). The risk envelope is the optional equity floor (InpEquityFloor), the daily/weekly realized-loss caps, the balance cap (InpCapitalCap), and the 30-minute cooldown that hardcoded-fires after three consecutive losses via g_cooldownUntil.

Take Profit

Each individual order carries a take-profit of InpTakeProfit * mysymbol.Point() (500 points = 50 pips on XAUUSD for both buys and sells, mirrored around the entry price). There is no basket target — a winning cycle closes one rung at a time, not all five together.

Best For

Traders running XAUUSD on a low-spread M5 feed (the 250-point spread ceiling is loose enough to accommodate most ECN quotes) with at least the $100 minimum deposit and a stomach for one-direction averaging. Best run inside the London 7:00-16:00 and New York 12:00-21:00 GMT windows when gold liquidity is deepest, and only on accounts that can survive a worst-case 5-rung basket at the chosen lot multiplier (5×0.01 lots at 1.0×, 7.6×0.01 lots at 1.5×). The hardcoded 3-consecutive-loss 30-minute cooldown and the optional InpEquityFloor make it suitable for prop-style accounts that need an explicit drawdown trip-wire.

Strategy Logic

Pipsgrowth EX03024 Grid — Strategy Logic Analysis (from .mq5 source)

Family: Grid Magic: 22203024 Version: 2.00

BRIEF: Control grid EA for XAUUSD that uses RSI filter for first entry, then adds grid levels at fixed step intervals with lot multiplier, closing basket on global average take profit. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • CheckSignal()
  • ManageGrid()
  • OpenBuy()
  • OpenSell()
  • NormalizeLot()
  • DetectGMTOffset_EX03024()
  • ServerToGMT_EX03024()
  • InActiveSession_EX03024()
  • UpdateDailyCounters_EX03024()
  • IsSafeToTrade_EX03024()
  • OnTradeTransaction()
  • TryBuy_EX03024()
  • ...and 1 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (11 total across 4 groups):

  • [=== Grid Strategy Parameters ===] InpGridStep = 300 // Grid Step (points)
  • [=== Grid Strategy Parameters ===] InpMaxLevels = 5 // Max Grid Levels
  • [=== Grid Strategy Parameters ===] InpLotMultiplier = 1.0 // Lot Multiplier (1.0 = Fixed, >1.0 = Martingale)
  • [=== Money Management ===] InpStartLot = 0.01 // Start Lot
  • [=== Money Management ===] InpTakeProfit = 500 // Take Profit (points) (Global TP)
  • [=== Trade Management ===] InpMagicNumber = 22203024 // Magic Number
  • [=== Trade Management ===] InpTradeComment = "Psgrowth.com Expert_03024" // Trade Comment
  • [=== Trade Management ===] InpMaxSpread = 250 // Max Spread (points)
  • [=== Trade Management ===] InpSlippage = 3 // Slippage
  • [=== Trade Management ===] InpUseRSIFilter = true // RSI Filter for First Entry
  • [=== Hardening Trade Safety ===] InpMaxConsecLosses = 0 // --- Handles
Pseudocode
// Pipsgrowth EX03024 Grid — Execution Flow (from source analysis)
// Family: Grid
// Control grid EA for XAUUSD that uses RSI filter for first entry, then adds grid levels at fixed step intervals with lot multiplier, closing basket on global average take profit. 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

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 a chart — H1 or H4 is recommended for grid EAs
  7. 7Set grid step (pips), maximum orders, and lot size in the EA dialog
  8. 8Enable Allow Algo Trading and click OK

EA Parameters

ParameterDefaultDescription
InpGridStep300Grid Step (points)
InpMaxLevels5Max Grid Levels
InpLotMultiplier1.0Lot Multiplier (1.0 = Fixed, >1.0 = Martingale)
InpStartLot0.01Start Lot
InpTakeProfit500Take Profit (points) (Global TP)
InpMagicNumber22203024Magic Number
InpTradeComment"Psgrowth.com Expert_03024"Trade Comment
InpMaxSpread250Max Spread (points)
InpSlippage3Slippage
InpUseRSIFiltertrueRSI Filter for First Entry
InpMaxConsecLosses0--- Handles
Source Code (.mq5)Open Source
Pipsgrowth_com_EX03024.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX03024 ControlGrid_XAUUSD_5M — RSI-filtered grid with lot multiplier and basket TP, full 12-layer stack."

#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>

CTrade         trade;
CPositionInfo  position;
CSymbolInfo    mysymbol;
CAccountInfo   account;

//--- Input Groups
input group "=== Grid Strategy Parameters ==="
input int      InpGridStep       = 300;      // Grid Step (points)
input int      InpMaxLevels      = 5;        // Max Grid Levels
input double   InpLotMultiplier  = 1.0;      // Lot Multiplier (1.0 = Fixed, >1.0 = Martingale)

input group "=== Money Management ==="
input double   InpStartLot       = 0.01;     // Start Lot
input int      InpTakeProfit     = 500;      // Take Profit (points) (Global TP)

input group "=== Trade Management ==="
input int      InpMagicNumber    = 22203024; // Magic Number
input string   InpTradeComment   = "Psgrowth.com Expert_03024"; // Trade Comment
input int      InpMaxSpread      = 250;      // Max Spread (points)
input int      InpSlippage       = 3;        // Slippage
input bool     InpUseRSIFilter   = true;     // RSI Filter for First Entry

input group "=== Hardening GMT Sessions ==="
input bool     InpUseGMTSessions  = true;
input int      InpLondonStartGMT  = 7;
input int      InpLondonEndGMT    = 16;
input int      InpNewYorkStartGMT = 12;
input int      InpNewYorkEndGMT   = 21;

input group "=== Hardening Capital Protection ==="
input double   InpEquityFloor     = 0.0;
input double   InpDailyLossLimit  = 0.0;
input double   InpWeeklyLossLimit = 0.0;
input double   InpCapitalCap      = 0.0;

input group "=== Hardening Trade Safety ==="
input int      InpMaxTradesPerDay = 50;
input int      InpCooldownMinutes = 30;
input int      InpMaxConsecLosses = 0;

//--- Handles
int hRSI;
double bufRSI[];

//--- Hardening Globals
double   g_realizedToday  = 0;
double   g_realizedWeek   = 0;
datetime g_dayStartTime   = 0;
datetime g_weekStartTime  = 0;

Full source code available on download

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

Tags:ex03024gridpipsgrowthfreemt5xauusd

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_EX03024.mq5
File Size15.7 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyGrid
Risk LevelVery High Risk
Timeframes
M5
Currency Pairs
XAUUSD
Min. Deposit$100