Pipsgrowth EX07008 MA
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX07008 MACrossover_XAUUSD_5M — Fast/Slow EMA crossover with trailing and pyramiding, full 12-layer stack.
Overview
Pipsgrowth EX07008 is a deliberate exercise in restraint. Where other EAs in the MA family stack a regime classifier, a higher-timeframe bias filter, a dashboard, a partial-TP ladder, and a news blackout on top of a simple moving-average cross, this one takes the cross and only the cross. The file is 334 lines, 18 inputs, ten custom functions, and exactly two indicator handles — one fast moving average and one slow moving average. The header advertises a '12-layer architecture' but the actual code is honest about what it does: detect a single crossover, send a market order, and let a fixed stop, fixed target, and a stepped trailing stop do the rest. That simplicity is the point. If you want a filter-heavy system, EX07001 or EX07003 in the same family cover that ground. EX07008 is for the trader who already has a higher-timeframe view and just needs a clean crossover execution layer to operate inside it.
The two inputs that define the engine are InpMAFast (default 20) and InpMASlow (default 50). The MA method is selectable via InpMAMethod (default MODE_EMA), so you can switch to SMA, SMMA, or LWMA without recompiling. The two MA handles are created in OnInit against the current chart symbol and period using PRICE_CLOSE, then CheckSignal() runs on every new bar — not every tick — to pull the last two closed values from each buffer and look for a cross. A buy fires when fast[2] <= slow[2] and fast[1] > slow[1]. A sell fires on the mirror condition. That's the entire signal. There is no ADX gate, no ATR filter, no Bollinger band, no higher-timeframe trend alignment. If you want to add one, the inputs aren't there — you'd have to modify the source.
Risk is set through the standard InpRiskPercent (default 1.0% of balance per trade) with InpFixedLot (default 0.01) as the fallback when risk-percent calc returns zero or a negative lot. The CalculateLotSize() function pulls account.Balance(), looks up the symbol's tick value, tick size, point, and lot step, then computes lot = (balance * riskPct / 100) / (stopLossPoints * tickValue / (tickSize / point)), floors the result to the lot step, and clamps it to the broker's LotsMin and LotsMax. The stop used in this calc is InpStopLoss (default 400 points), so a 1% risk on a 400-point stop on a typical XAUUSD account lands somewhere around 0.05–0.10 lots depending on contract specs. If your broker quotes XAUUSD to two decimals, 400 points is $4.00 per ounce — meaningful, not catastrophic, on a $1,000 account.
The stop and target are placed by OpenBuy() and OpenSell() as hard server-side orders. OpenBuy does Ask - InpStopLoss * Point and Ask + InpTakeProfit * Point. OpenSell does the mirror from Bid. With the defaults, that gives a 400-point stop and a 1,200-point target — a 1:3 reward-to-risk on every entry. There is no partial close. There is no break-even ratchet. There is no time-based exit. A trade runs until price hits the stop, the target, or an opposite crossover fires another entry that is blocked because a position in that direction is already open.
The trailing stop, when InpEnableTrail is true (default), is invoked from OnTick via ManageProfitLock() and runs as a stepped ratchet, not a continuous ATR chandelier. The logic compares current price against position open price: for a buy, once Bid - PriceOpen > InpTrailStart * Point (default 300 points), the new stop is set to Bid - InpTrailDistance * Point (default 150 points behind), and the modification only goes through TryModify_EX07008() if the new stop is higher than the current one. The InpTrailStep (default 100 points) parameter is declared in the input block but is not actually read by the trailing function in the current source — only the start distance and the distance-behind-price are used. So the trail essentially ratchets upward (for longs) in 100-point increments every time price advances by another 100 points beyond the trail start. This is a classic stepped trail, the same idea you'll find in older MT4 grid EAs.
Pyramiding is on by default (InpEnablePyramid = true) and capped at InpMaxPositions (default 3) per direction. The IsGridSafe() function walks all open positions of the same magic and direction and refuses to add a new layer unless the most recent position in that direction is at least InpMinProfitPoints (default 300 points) in profit. This is the safety valve that turns what could be a martingale-style adder into a profit-locked scale-in: you only ever add to a winner. With three positions per direction, the worst case is six open tickets on the same gold chart — three longs and three shorts — each 400 points from entry with a 1,200-point target.
The risk gates are sparse. The only entry-time filter is the spread check at the top of OnTick: if mysymbol.Spread() > InpMaxSpread (default 250 points on XAUUSD = 2.5 dollars), the tick is skipped entirely and nothing else runs that tick. There is no session filter, no time-of-day exclusion, no news blackout, no drawdown kill switch, no daily-loss limit, no equity-floor check, no consecutive-losses cooldown, and no market-open weekend guard. The EA will fire a cross signal on a Sunday open or a Friday close. This is the single biggest difference between EX07008 and the other 560 EAs on the site: the file trusts you, the operator, to attach it to a chart only during conditions you have already decided are valid. If you attach it to a 24-hour XAUUSD chart and let it run, it will fire crosses overnight in the Asian session against a 250-point spread that some brokers widen to 400+ during rollover.
The execution layer is standard PipsGrowth plumbing. trade.SetExpertMagicNumber(22207008), trade.SetDeviationInPoints(InpSlippage) (default 3 points), trade.SetTypeFilling(ORDER_FILLING_FOK). Order send, modify, and close are wrapped in three small retry helpers: TryClose_EX07008, TryClosePartial_EX07008, and TryModify_EX07008. Each does three attempts with a 200ms Sleep on REQUOTE, TIMEOUT, PRICE_OFF, or PRICE_CHANGED; the modify helper uses 100ms instead and only retries on the first two codes. There is no OnTester block in the source — strategy fitness is left to the framework.
In practical terms: drop EX07008 on an XAUUSD M5 chart during a session you have already decided is tradeable (the European open and the New York morning tend to produce the cleanest EMA-20/EMA-50 crosses on gold), confirm your broker's typical spread is below 250 points, and let it trade. Expect a trade roughly every few hours during active sessions and almost nothing overnight. The 1:3 reward-to-risk and the stepped trail are designed so that a small number of large winners pays for a larger number of small losers; that is the only edge the system is built to capture, and it requires the user to provide everything else — session choice, instrument choice, broker selection, and capital sizing — externally.
If you want a chart-attached dashboard, a kill switch, a regime filter, or a news blackout, you will need to layer those in yourself or pick a different EA from this family. EX07008 is intentionally the minimal version: two moving averages, one cross, one hard stop, one hard target, one stepped trail, and a profit-locked pyramid. Nothing more.
Strategy Deep Dive
Pulls two single-symbol moving averages — InpMAFast (default 20) and InpMASlow (default 50), method selectable via InpMAMethod — and fires a market order on the closed-bar cross. ManageProfitLock() runs every tick to step a trailing stop into profit once price clears InpTrailStart, and TryModify_EX07008 wraps the modify call in three retries on requote and timeout. CheckSignal() runs once per new bar and gates pyramid adds through IsGridSafe(), which refuses to stack a new position unless the most recent one in the same direction is at least InpMinProfitPoints in profit. OnTick begins with a single spread gate — the only filter in the entire file — and the rest of the logic is the cross, the stop, the target, and the trail.
Buy when the fast MA (default EMA-20) closes above the slow MA (default EMA-50) on bar 1 after being at or below on bar 2. Sell fires on the mirror cross. A new entry in the same direction is allowed only if pyramid mode is on and either (a) no position is open in that direction, or (b) the most recent position in that direction is in profit of at least InpMinProfitPoints (default 300 points) and total positions in that direction are below InpMaxPositions (default 3). The entry tick is skipped if the symbol spread exceeds InpMaxSpread (default 250 points).
Positions exit at the hard stop (default 400 points) or the hard target (default 1,200 points), both set server-side at entry. After price moves InpTrailStart (default 300 points) in profit, ManageProfitLock ratchets the stop to InpTrailDistance (default 150 points) behind price using TryModify_EX07008. The trail only moves forward — it never loosens. A new opposite cross does not auto-close the existing position; it just opens the new trade if no opposing position is already open.
Initial stop is a fixed InpStopLoss (default 400 points) placed server-side at entry — 4.00 dollars per ounce on a 2-decimal XAUUSD quote. Once price advances InpTrailStart (default 300 points) in profit, the stop ratchets to Bid/Task minus InpTrailDistance (default 150 points) behind price, and only moves forward from there. There is no break-even step and no time stop.
Fixed take profit at InpTakeProfit (default 1,200 points) — 12.00 dollars per ounce on XAUUSD, set server-side at entry. With the 400-point stop, that is a hard 1:3 reward-to-risk on every entry. There is no partial close, no scaled exit, and no time-based close — the trade runs to either the stop or the target.
XAUUSD on M5 during the London and early-New-York overlap (08:00–14:00 server time on most brokers) gives the cleanest EMA-20/EMA-50 crosses and the tightest spreads under the 250-point InpMaxSpread gate. Recommended balance: $300–$1,000 at 1% risk per trade (default InpRiskPercent) keeps a 400-point stop to a manageable loss on a micro account. Broker requirement: any MT5 account that quotes XAUUSD with a typical spread below 2.5 dollars — ECN/RAW preferred but not strictly required since the spread filter is permissive. Risk profile: MEDIUM because the 1:3 reward-to-risk compensates for the lack of a regime filter, but a run of consecutive losses in a choppy market is possible since there is no ADX or session gate beyond the spread check.
Strategy Logic
Pipsgrowth EX07008 MA — Strategy Logic Analysis (from .mq5 source)
Family: MA
Magic: 22207008
Version: 2.00
BRIEF:
MA crossover EA using Fast/Slow EMA crossover for entry
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
CheckSignal()OpenBuy()OpenSell()ManageProfitLock()IsGridSafe()CalculateLotSize()CountPositions()TryClose_EX07008()TryClosePartial_EX07008()TryModify_EX07008()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (18 total across 5 groups):
- [=== Indicator Settings ===]
InpMAFast= 20 // Fast MA Period - [=== Indicator Settings ===]
InpMASlow= 50 // Slow MA Period - [=== Indicator Settings ===]
InpMAMethod=MODE_EMA// MA Method - [=== Money Management ===]
InpRiskPercent=1.0// Risk Percent per Trade - [=== Money Management ===]
InpFixedLot=0.01// FixedLot(if Risk=0) - [=== Money Management ===]
InpStopLoss= 400 // StopLoss(points) - [=== Money Management ===]
InpTakeProfit= 1200 // TakeProfit(points) - [=== Trade Management ===]
InpMagicNumber=22207008// Magic Number - [=== Trade Management ===]
InpTradeComment= "Psgrowth.com Expert_07008" // TradeComment - [=== Trade Management ===]
InpMaxSpread= 250 // MaxSpread(points) - [=== Trade Management ===]
InpSlippage= 3 // Slippage - [=== Profit Lock / Trailing ===]
InpEnableTrail=true// Enable Trailing Stop - [=== Profit Lock / Trailing ===]
InpTrailStart= 300 // Trail StartDistance(points) - [=== Profit Lock / Trailing ===]
InpTrailStep= 100 // TrailStep(points) - [=== Profit Lock / Trailing ===]
InpTrailDistance= 150 // Distance behind price (points) - [=== Pyramiding / Scaling ===]
InpEnablePyramid=true// Enable Pyramiding - [=== Pyramiding / Scaling ===]
InpMaxPositions= 3 // Max Open Positions - [=== Pyramiding / Scaling ===]
InpMinProfitPoints= 300 // MinProfit(points) to Add Next
// Pipsgrowth EX07008 MA — Execution Flow (from source analysis)
// Family: MA
// MA crossover EA using Fast/Slow EMA crossover for entry
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 H4 or Daily chart for best results
- 7Configure EMA periods, ADX threshold, and lot size in the dialog
- 8Enable Allow Algo Trading and click OK
EA Parameters
| Parameter | Default | Description |
|---|---|---|
| InpMAFast | 20 | Fast MA Period |
| InpMASlow | 50 | Slow MA Period |
| InpMAMethod | MODE_EMA | MA Method |
| InpRiskPercent | 1.0 | Risk Percent per Trade |
| InpFixedLot | 0.01 | Fixed Lot (if Risk=0) |
| InpStopLoss | 400 | Stop Loss (points) |
| InpTakeProfit | 1200 | Take Profit (points) |
| InpMagicNumber | 22207008 | Magic Number |
| InpTradeComment | "Psgrowth.com Expert_07008" | Trade Comment |
| InpMaxSpread | 250 | Max Spread (points) |
| InpSlippage | 3 | Slippage |
| InpEnableTrail | true | Enable Trailing Stop |
| InpTrailStart | 300 | Trail Start Distance (points) |
| InpTrailStep | 100 | Trail Step (points) |
| InpTrailDistance | 150 | Distance behind price (points) |
| InpEnablePyramid | true | Enable Pyramiding |
| InpMaxPositions | 3 | Max Open Positions |
| InpMinProfitPoints | 300 | Min Profit (points) to Add Next |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX07008 MACrossover_XAUUSD_5M — Fast/Slow EMA crossover with trailing and pyramiding, 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 "=== Indicator Settings ==="
input int InpMAFast = 20; // Fast MA Period
input int InpMASlow = 50; // Slow MA Period
input ENUM_MA_METHOD InpMAMethod = MODE_EMA; // MA Method
input group "=== Money Management ==="
input double InpRiskPercent = 1.0; // Risk Percent per Trade
input double InpFixedLot = 0.01; // Fixed Lot (if Risk=0)
input int InpStopLoss = 400; // Stop Loss (points)
input int InpTakeProfit = 1200; // Take Profit (points)
input group "=== Trade Management ==="
input int InpMagicNumber = 22207008; // Magic Number
input string InpTradeComment = "Psgrowth.com Expert_07008"; // Trade Comment
input int InpMaxSpread = 250; // Max Spread (points)
input int InpSlippage = 3; // Slippage
input group "=== Profit Lock / Trailing ==="
input bool InpEnableTrail = true; // Enable Trailing Stop
input int InpTrailStart = 300; // Trail Start Distance (points)
input int InpTrailStep = 100; // Trail Step (points)
input int InpTrailDistance = 150; // Distance behind price (points)
input group "=== Pyramiding / Scaling ==="
input bool InpEnablePyramid = true; // Enable Pyramiding
input int InpMaxPositions = 3; // Max Open Positions
input int InpMinProfitPoints= 300; // Min Profit (points) to Add Next
//--- Handles
int hMAFast;
int hMASlow;
//--- Global Buffers
double bufMAFast[];
double bufMASlow[];
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
trade.SetExpertMagicNumber(InpMagicNumber);
trade.SetDeviationInPoints(InpSlippage);
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 Trend Following strategy EAs from our library
Pipsgrowth EX16080 Trend
Pipsgrowth.com EX16080 EURUSDTrendFollower — triple-EMA H4 trend follower, full 12-layer stack.
Pipsgrowth EX16081 Trend
Pipsgrowth.com EX16081 GoldTrendEA — XAUUSD H4 EMA cross with Fib targets, full 12-layer stack.
Pipsgrowth EX16033 Trend
Pipsgrowth.com EX16033 EA_Price_Action — price-action grid scalper, full 12-layer stack.
Community
Educational purposes only. Do NOT use with real money. Test on demo accounts only.