Pipsgrowth EX03005 Grid
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX03005 Asisten_TP_Averaging — TP averaging assistant for basket management, full 12-layer stack.
Overview
Pipsgrowth EX03005 is not a strategy EA in the conventional sense. It is a TP averaging assistant — a small utility that watches an existing basket of open positions on the current chart and rewrites their take-profit levels so that every position in the basket closes together at a single fixed distance from the basket's volume-weighted average entry price. It does not open trades, does not close trades, does not set stop-loss, and does not run any indicator. The role it plays in a portfolio is the role of a basket manager for traders who run a grid, an averaging-down routine, or a martingale-style sequence from another EA or from manual entries, and who want every position in that sequence to share one exit target instead of having each ticket carry an independent TP.
The .mq5 file is correspondingly tiny — three inputs and four functions, no indicator handles, no #define constants, and a 165-line body. The three inputs cover everything a user might want to change: InpMagicNumber (default 22203005) sets the magic that identifies the basket the assistant should manage, InpTradeComment (default "Psgrowth.com Expert_03005") is the comment string written into any order the assistant itself touches, and TakeProfit (default 100, in MT5 points) is the fixed distance the assistant inserts between the basket's break-even price and the modified TP. Everything else is hard-coded because nothing else needs to vary.
The execution path runs on a 5-second timer, not on ticks. OnInit calls EventSetTimer(5), which fires OnTimer five times per second — far more often than is strictly necessary for a position-modification task, but cheap because the body of OnTimer does almost nothing. Each tick of the timer, the assistant calls positionInformation() to recompute the volume-weighted average entry for every open position on the chart's symbol. The function walks PositionsTotal(), filters to positions whose symbol matches the current chart and whose POSITION_TYPE is BUY (or SELL), and accumulates two running sums for each side: tPriceBuy += price * volume and tLotsBuy += volume. After the walk, BEPBuy = tPriceBuy / tLotsBuy and BEPSell = tPriceSell / tLotsSell, normalized to the symbol's Digits(). The result is a true volume-weighted average — positions opened with larger lots pull the basket break-even toward their entry price more than positions opened with smaller lots. This is the price the assistant will use as the anchor for the modified TP.
If BEPBuy is non-zero (i.e., at least one buy position is open on the symbol), OnTimer calls modifyPosition(POSITION_TYPE_BUY, BEPBuy + TakeProfit * Point()). The function walks the open positions again, this time modifying any buy whose existing TP is either zero or not equal to the new target. The condition NormalizeDouble(PositionGetDouble(POSITION_TP), digit) != NormalizeDouble(TP, digit) || NormalizeDouble(PositionGetDouble(POSITION_TP), digit) == 0 is the actual rewrite trigger: it fires on any drift, and it always fires on the first pass if TP is 0 (i.e., the originating EA opened the position without a TP). The modification request is a standard TRADE_ACTION_SLTP — only the TP field is set, the SL field is left at its existing value, and clearStructures() zeros the request/result/check structures before each send. The same path runs for sells with BEPSell - TakeProfit * Point() as the target, so a basket that has both buys and sells gets two independent targets, one for each side.
The order-send wrapper, TryOrderSend_EX03005, retries up to three times on transient errors: TRADE_RETCODE_REQUOTE, TRADE_RETCODE_TIMEOUT, TRADE_RETCODE_PRICE_OFF, and TRADE_RETCODE_PRICE_CHANGED each trigger a 200 ms Sleep and another attempt. A successful fill is recognized by TRADE_RETCODE_DONE, TRADE_RETCODE_PLACED, or TRADE_RETCODE_DONE_PARTIAL. Any other retcode breaks out of the loop and Print("Modify Error") is emitted. The 200 ms gap is conservative for a modification — TP changes rarely compete with other orders on the same ticket, so requotes are uncommon, but the retry covers the case where a position's stop-level or freeze-zone restriction blocks the change for a brief moment during high volatility.
Because EX03005 is a basket utility rather than a strategy, the inputs that other EAs in the corpus expose — InpRiskPercent, InpATRMultSL, InpADXMinTrend, InpFilterNews, InpMaxConsecLosses, the seven-state regime classifier — are intentionally absent. There is no signal to gate, no risk to size, no session to enforce. Whatever the originating EA (or the trader) decides about entry, stop, lot, regime, and timing is left intact. EX03005's only job is to align the take-profit of every position it sees to one shared, volume-weighted target, and to do that every 5 seconds for as long as the assistant is attached to the chart.
The natural deployment pattern is to run EX03005 in a second MT5 instance or on a second chart of the same symbol where the primary grid EA is attached, with the same InpMagicNumber. The primary EA handles entries, sizing, stops, and direction. EX03005 watches the basket and overwrites any drift in the TP. The two programs never talk directly — they coordinate only through the magic number on the open positions. To backtest EX03005, attach it to a chart alongside a strategy EA that produces the positions; running it alone produces no actions because the positionInformation walk finds nothing to modify. Because the assistant does not manage risk, it is appropriate only for traders who are already comfortable with the basket behavior of their primary EA and who specifically want the symmetric exit that a single volume-weighted TP provides.
Strategy Deep Dive
A 5-second timer fires OnTimer, which calls positionInformation() to walk PositionsTotal() and accumulate tPriceBuy += price * volume and tLotsBuy += volume for every buy ticket, and the same for sells. After the walk, BEPBuy = tPriceBuy / tLotsBuy (and the same for sell), normalized to the symbol's Digits() — this is the volume-weighted break-even of each side's basket. If BEPBuy != 0, the timer calls modifyPosition(POSITION_TYPE_BUY, BEPBuy + TakeProfit * Point()); the same runs for sells with BEPSell - TakeProfit * Point(). modifyPosition walks the position list again and, for each matching side whose current TP is zero or not equal to the new target, sends a TRADE_ACTION_SLTP request that only sets the TP field. TryOrderSend_EX03005 retries up to three times at 200 ms on REQUOTE / TIMEOUT / PRICE_OFF / PRICE_CHANGED. There are no indicators, no regime classifier, no news filter, no session gate, no drawdown cap — every gate you'd expect on a strategy EA is intentionally absent because the only job is to keep the basket TP aligned to the volume-weighted average.
EX03005 does not generate entries. The assistant is designed to run alongside another EA (or manual trading) that produces the positions; the assistant then manages only the take-profit of those positions. If no open positions match InpMagicNumber on the current symbol, the assistant has nothing to do.
Exit is by take-profit, not by stop-loss. The assistant rewrites every matching position's TP to BEPBuy + TakeProfit * Point() for buys and BEPSell - TakeProfit * Point() for sells, where BEP is the volume-weighted average entry of the basket. The rewrite runs every 5 seconds via EventSetTimer(5), only when the existing TP differs from the target or is zero. There is no opposite-signal exit, no time-based exit, and no manual close logic in the assistant itself.
EX03005 does not set, modify, or clear stop-loss levels. The TRADE_ACTION_SLTP request leaves the sl field unset, so any SL the originating EA attached to a position remains in place. Risk management is the responsibility of the strategy EA that opened the trade.
The basket TP is anchored to the volume-weighted average entry of all open positions on the same side of the same symbol, with the user's TakeProfit (default 100 points) added to buys or subtracted from sells. The result is one shared exit target for the whole basket rather than independent TPs per ticket. The rewrite fires on any drift, and it always fires on the first pass if a position has no TP set.
Traders who already run a grid, martingale, or averaging-down EA (or who scale into positions manually) and want every position in the basket to share a single volume-weighted TP rather than independent TPs. Suggested symbol: XAUUSD on M5–H1 (works on FX majors and other metals too). Recommended minimum balance is the same as the originating grid EA's, typically $100+ for XAUUSD micro-lots, but the real constraint is the basket's margin requirement, not the assistant's. Use on a low-spread broker because the assistant makes no spread filter of its own; modify-cycle latency is irrelevant to the strategy's P&L, but tight spreads on the underlying EA improve the cost of the entry that produced the basket.
Strategy Logic
Pipsgrowth EX03005 Grid — Strategy Logic Analysis (from .mq5 source)
Family: Grid
Magic: 22203005
Version: 2.00
BRIEF:
TP averaging assistant that calculates the break-even price of all buy and sell positions on the current symbol and automatically modifies TP to a fixed distance from average. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
OnTimer()clearStructures()modifyPosition()positionInformation()TryOrderSend_EX03005()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (3 total across 2 groups):
- [=== Trade Management ===]
InpMagicNumber=22203005// Magic Number - [=== Trade Management ===]
InpTradeComment= "Psgrowth.com Expert_03005" // TradeComment - [=== TP Settings ===]
TakeProfit= 100 // Take Profit in Points
// Pipsgrowth EX03005 Grid — Execution Flow (from source analysis)
// Family: Grid
// TP averaging assistant that calculates the break-even price of all buy and sell positions on the current symbol and automatically modifies TP to a fixed distance from average. 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 | 22203005 | Magic Number |
| InpTradeComment | "Psgrowth.com Expert_03005" | Trade Comment |
| TakeProfit | 100 | Take Profit in Points |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX03005 Asisten_TP_Averaging — TP averaging assistant for basket management, full 12-layer stack."
input group "=== Trade Management ==="
input int InpMagicNumber = 22203005; // Magic Number
input string InpTradeComment = "Psgrowth.com Expert_03005"; // Trade Comment
input group "=== TP Settings ==="
input double TakeProfit = 100; // Take Profit in Points
MqlTradeRequest m_request; // request data
MqlTradeResult m_result; // result data
MqlTradeCheckResult m_check_result; // result check data
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {
//--- create timer
EventSetTimer(5);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer() {
//---
double tPriceBuy = 0,
tPriceSell = 0,
tLotsBuy = 0,
tLotsSell = 0,
BEPBuy = 0,
BEPSell = 0;
positionInformation(tPriceBuy, tPriceSell, tLotsBuy, tLotsSell, BEPBuy, BEPSell);
if(BEPBuy != 0) {
modifyPosition(POSITION_TYPE_BUY, BEPBuy + TakeProfit * Point());
}
if(BEPSell != 0) {
modifyPosition(POSITION_TYPE_SELL, BEPSell - TakeProfit * Point());
}
}
//+------------------------------------------------------------------+
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.