Pipsgrowth EX08005 MACD
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX08005 MACD_EA - MACD crossover with MA filter, full 12-layer stack.
Overview
EX08005 sits at the slow end of the PipsGrowth MACD family. Where most MACD EAs run the textbook 12/26/9 pair on M5 and react to every wiggle, this one runs a 120/260/90 MACD — the longest standard deviation of the slow EMA period across the corpus — and the goal is to trade only the swings that survive a multi-month filter. The default chart is XAUUSD on M5 (H1 also fits), the magic number is 22208005, and the version is 2.00.
The signal is built from four indicator handles created in OnInit. Three of them are moving averages: a 55-period EMA applied to close (the fast MA), a 69-period SMA applied to close (the slow MA), and a 2-period LWMA applied to close (the filter MA). The fourth is the MACD with a 120-period fast EMA, a 260-period slow EMA, and a 90-period signal-line EMA — a 90-bar smoothing of the difference between two very slow EMAs. On each new bar the EA reads MACD_MAIN and MACD_SIGNAL at bar 1 (the most recent closed bar) and at bar 3 (two bars back). The decision rule in OnTick is plain: a long fires when MACD_MAIN[1] is above MACD_SIGNAL[1] AND MACD_MAIN[3] was below MACD_SIGNAL[3]; a short fires on the mirror image. That second condition is the trick — it requires the crossover to have completed two bars ago, which filters out a single-bar whipsaw and forces the EA to wait for the new relationship to hold.
The MAs are computed on every tick but, in this build, do not gate the entry. MAFast_0, MASlow_0, MAFilter_0, and MAFilter_2 are all read into local doubles, but the entry branch only inspects the four MACD values. Anyone tuning the source who wants a true MA filter has to add the comparison themselves; out of the box, the MAs are declared and unused as signal inputs. This is a deliberate simplification — the long-period MACD already encodes a slow trend filter — but it is worth knowing if you expect the header's wording about "MA Fast/Slow/Filter confirmation" to mean those three MAs veto entries.
Position management runs in priority order on every open ticket. First, the EA checks for an opposite MACD signal — if a long position exists and MACD_MAIN[1] has fallen below MACD_SIGNAL[1] while MACD_MAIN[3] was above MACD_SIGNAL[3], the position is closed via TryClose_EX08005 (3 retries, 200ms backoff on REQUOTE / TIMEOUT / PRICE_OFF / PRICE_CHANGED). Second, the EA applies a partial close: when price moves 70 pips in the position's favour (configurable via InpProfitOne), half the lot is closed through TryClosePartial_EX08005. Third, if InpBreakeven is non-zero (default 0 — disabled), the SL is dragged to the open price once price is InpBreakeven pips in profit. The order of those three checks is continue-stacked in OnTick, so each tick performs at most one management action per position. The hardcoded initial SL is 80 pips and the hardcoded initial TP is 500 pips — a 1:6.25 R:R bracket that lets the long-period MACD play out while keeping the per-trade loss shallow.
Money management is a single switch. With MM=false, every entry uses InpLots=1.0. With MM=true, the EA instantiates a CMoneyFixedMargin object and sizes each entry off the SL distance at 1% of free margin (Risk input). In both cases LotCheck() then normalizes the requested lot to the symbol's step / min / max. Filling mode is auto-detected per symbol — FOK first, then IOC, then RETURN — and m_slippage=10 is the maximum deviation.
The hardening stack is the most defensive of the EX08 series. IsSafeToTrade() runs nine independent gates before any entry: a capital-allocation cap (off by default; set InpCapitalCapAmount to the dollar ceiling and InpCapitalCapFloor=50 to the dollar floor), a 95% equity floor relative to the initial balance, a 3% daily realized-loss limit and a 6% weekly realized-loss limit (both computed against effective capital so the cap interacts cleanly with the loss limits), a 3-consecutive-loss counter that triggers a 30-minute cooldown (InpCooldownMinutes), a 50-trade daily cap, a market-hours check that closes entries on Saturday, before Sunday 22 GMT, and after Friday 22 GMT, a London-or-NY session check (London 7–16 GMT, NY 12–21 GMT, Asia 0–7 GMT explicitly avoided), and an optional 15-minute news filter around the London and NY opens. The trade counters and the realized PnL stream update in OnTradeTransaction, which scans deal history for DEAL_ENTRY_OUT events on this magic and this symbol.
GMT handling is the standard PipsGrowth auto-detect: DetectGMTOffset() walks back through the H1 bars until it finds a weekend gap, then computes the broker's offset from the Friday 22 GMT close. InpServerGMTOffset=0 turns auto-detection on; set it to a positive or negative integer to override. The session check, news check, and weekend guard all run on this offset, so the EA's idea of "London open" follows the broker's clock rather than local time.
OnTester returns (STAT_PROFIT × STAT_PROFIT_FACTOR) / (1 + STAT_BALANCE_DDREL_PERCENT) with a hard minimum of 30 trades. A trade count below 30 zeroes the result, which pushes the optimiser towards parameter combinations that actually trade instead of sitting in cash. There is no upper bound on the formula — a strategy with 2.0 PF and 8% relative drawdown scores roughly 1.85; the same PF with 25% DD scores roughly 1.60, so the drawdown term has real weight.
In practical terms: this is an XAUUSD MACD crossover EA on M5/H1 with a 120/260/90 slow MACD, a 1:6.25 R:R default bracket, half-position partial close at +70 pips, a nine-gate no-trade stack, and a defence-in-depth risk layer. It will trade rarely — long-period MACD signals on a 5-minute chart cluster only around real regime shifts — and when it trades it cuts losers at 80 pips while letting the partial close lock in the first 70 pips of any move. The expected backtest profile is a low-trade-count equity curve with intermittent bursts when the slow MACD finally turns. Anyone running it should size off the 80-pip SL with the assumption that the next signal might be a week away, and that the session filter will close the book before the daily reset.
Strategy Deep Dive
On every new bar the EA reads MACD_MAIN and MACD_SIGNAL from the iMACD(120,260,90) handle at bar 1 and bar 3, then either opens a new position (if none is open for this magic) or runs one of three management actions on the existing position. The MAs are pulled into local variables but the entry branch never reads them. TryClose_EX08005, TryClosePartial_EX08005, and TryModify_EX08005 all use the same 3-retry 200/200/100 ms pattern on REQUOTE / TIMEOUT / PRICE_OFF / PRICE_CHANGED, with CMoneyFixedMargin optionally sizing each entry off the SL distance at 1% of free margin. The hardening layer adds nine pre-trade gates: capital cap, equity floor, daily 3% / weekly 6% loss limits, 3-consecutive-loss cooldown, 50-trade daily cap, market hours, London/NY session, and an optional 15-minute news filter around the major opens. OnTester scores (net × PF) / (1 + DD) with a 30-trade minimum.
A long entry fires when the MACD(120,260,90) main line at bar 1 is above the signal line and was below it two bars back; the same crossover a few bars later is what triggers the position, not the current-bar relationship. A short mirrors the same condition. The MAs are computed but do not actually gate the entry in this build. The new-bar gate (PrevBars static datetime) prevents intra-bar duplicates, and IsSafeToTrade() must return true for any ticket to fire.
Three exit paths run in order on every open position: (1) close on the opposite MACD signal via TryClose_EX08005; (2) close half the position at +70 pips in profit via TryClosePartial_EX08005; (3) if InpBreakeven is non-zero, drag the SL to the open price once the trade is InpBreakeven pips in profit. A 500-pip hardcoded TP bracket also exists on every ticket for the runner half after the partial close fires.
Hardcoded 80-pip stop on every entry (InpStopLoss=80). Optional drag-to-breakeven once the trade is InpBreakeven pips in profit (default 0 = off). No ATR-based trailing and no chandelier — the per-trade risk is fixed at 80 pips regardless of volatility.
Hardcoded 500-pip take-profit on every entry (InpTakeProfit=500) for a 1:6.25 R:R default bracket. The 500-pip TP stays attached to the runner half after the partial close fires at +70 pips, so the typical exit is split: half at +70 pips, the rest either at +500 pips or earlier on the opposite MACD signal.
XAUUSD M5 is the default, H1 also fits for slower swing use. Minimum balance: $100 with InpLots=1.0 and MM off; the MM path with 1% risk requires more headroom for the 80-pip SL plus the partial-close lot rounding. Best with a low-spread ECN broker that quotes XAUUSD tightly enough that the 70-pip partial-close trigger survives the spread and slippage. Run it during the configured London 7-16 GMT and NY 12-21 GMT windows; Asia is explicitly avoided. Risk profile: MEDIUM — the 1:6.25 R:R bracket and the 3% daily / 6% weekly loss caps keep tail risk contained even when the slow MACD cycles through long dormant stretches.
Strategy Logic
Pipsgrowth EX08005 MACD — Strategy Logic Analysis (from .mq5 source)
Family: MACD
Magic: 22208005
Version: 2.00
BRIEF:
MACD crossover EA with MA Fast/Slow/Filter confirmation, partial profit taking, breakeven, and optional money management with 12-layer stack: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
RefreshRates()CheckVolumeValue()IsFillingTypeAllowed()LotCheck()iMAGet()iMACDGet()OpenBuy()OpenSell()CompareDoubles()OnTradeTransaction()GetEffectiveCapital()DetectGMTOffset()- ...and 9 more
INTERNAL CONSTANTS (1 total):
SIGNAL_LINE= 1 // +------------------------------------------------------------------+
INPUT PARAMETERS (42 total across 7 groups):
- [=== Identity ===]
m_magic=22208005// magic number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_08005" // trade comment - [=== Trading ===]
InpLots=1.0//Lots(use only if "Money Management" ==false) - [=== Trading ===]
InpStopLoss= 80 // StopLoss(in pips) - [=== Trading ===]
InpTakeProfit= 500 // TakeProfit(in pips) - [=== Trading ===]
InpProfitOne= 70 // Profit for closing half of the position (in pips) - [=== Trading ===]
InpBreakeven= 0 //Breakeven(in pips) - [=== Money Management ===] MM =
false// Money Management - [=== Money Management ===] Risk =
1.0// Risk in percent for a deal from a free margin - [=== Indicator Parameters ===] MAFast_ma_period = 55 // MA Fast: averaging period
- [=== Indicator Parameters ===] MAFast_ma_shift = 0 // MA Fast: horizontal shift of the indicator
- [=== Indicator Parameters ===] MAFast_ma_method =
MODE_EMA// MA Fast: smoothing type - [=== Indicator Parameters ===] MAFast_applied_price = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Fast: type of price
- [=== Indicator Parameters ===] MASlow_ma_period = 69 // MA Slow: averaging period
- [=== Indicator Parameters ===] MASlow_ma_shift = 0 // MA Slow: horizontal shift of the indicator
- [=== Indicator Parameters ===] MASlow_ma_method =
MODE_SMA// MA Slow: smoothing type - [=== Indicator Parameters ===] MASlow_applied_price = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Slow: type of price
- [=== Indicator Parameters ===] MAFilter_ma_period = 2 // MA Filter: averaging period
- [=== Indicator Parameters ===] MAFilter_ma_shift = 0 // MA Filter: horizontal shift of the indicator
- [=== Indicator Parameters ===] MAFilter_ma_method =
MODE_LWMA// MA Filter: smoothing type - [=== Indicator Parameters ===] MAFilter_applied_price = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Filter: type of price
- [=== Indicator Parameters ===] MACDfast_ema_period = 120 //
MACD: period for Fast average calculation - [=== Indicator Parameters ===] MACDslow_ema_period = 260 //
MACD: period for Slow average calculation - [=== Indicator Parameters ===] MACDsignal_period = 90 //
MACD: period for their difference averaging - [=== Hardening: Risk Management ===]
InpMaxConsecLosses= 3 // Max consecutive losses before cooldown (0=disabled) - [=== Hardening: Risk Management ===]
InpCooldownMinutes= 30 // Cooldown minutes after consec losses (0=disabled) - [=== Hardening: Risk Management ===]
InpMaxTradesPerDay= 50 // Maximum trades per day - [=== Hardening: Risk Management ===]
InpMinEquityPercent=95.0// Stop trading if equity < this % of initial balance - [=== Hardening: Risk Management ===]
InpDailyLossLimitPct=3.0// Daily loss limit (% of effective capital) - [=== Hardening: Risk Management ===]
InpWeeklyLossLimitPct=6.0// Weekly loss limit (% of effective capital) - [=== Hardening: Capital Allocation Cap ===]
InpCapitalCapAmount=0.0// Cap amount ($ real money equity) - [=== Hardening: Capital Allocation Cap ===]
InpCapitalCapFloor=50.0//Floor($); block entries below this - [=== Hardening:
GMTSessions ===]InpServerGMTOffset= 0 // ServerGMToffset hours (0=auto-detect) - [=== Hardening:
GMTSessions ===]InpLondonStartHour= 7 // London session start (GMT) - [=== Hardening:
GMTSessions ===]InpLondonEndHour= 16 // London session end (GMT) - [=== Hardening:
GMTSessions ===]InpNYStartHour= 12 // New York session start (GMT) - [=== Hardening:
GMTSessions ===]InpNYEndHour= 21 // New York session end (GMT) - [=== Hardening:
GMTSessions ===]InpAvoidAsia=true// Avoid Asian session - [=== Hardening:
GMTSessions ===]InpAsiaStartHour= 0 // Asian session start (GMT) - [=== Hardening:
GMTSessions ===]InpAsiaEndHour= 7 // Asian session end (GMT) - [=== Hardening:
GMTSessions ===]InpNewsFilter=false// Avoid trading near news session opens - [=== Hardening:
GMTSessions ===]InpNewsFilterMinutes= 15 // Minutes to avoid around news
// Pipsgrowth EX08005 MACD — Execution Flow (from source analysis)
// Family: MACD
// MACD crossover EA with MA Fast/Slow/Filter confirmation, partial profit taking, breakeven, and optional money management with 12-layer stack: 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 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 |
|---|---|---|
| m_magic | 22208005 | magic number |
| InpTradeComment | "Psgrowth.com Expert_08005" | trade comment |
| InpLots | 1.0 | Lots (use only if "Money Management" == false) |
| InpStopLoss | 80 | Stop Loss (in pips) |
| InpTakeProfit | 500 | Take Profit (in pips) |
| InpProfitOne | 70 | Profit for closing half of the position (in pips) |
| InpBreakeven | 0 | Breakeven (in pips) |
| MM | false | Money Management |
| Risk | 1.0 | Risk in percent for a deal from a free margin |
| MAFast_ma_period | 55 | MA Fast: averaging period |
| MAFast_ma_shift | 0 | MA Fast: horizontal shift of the indicator |
| MAFast_ma_method | MODE_EMA | MA Fast: smoothing type |
| MAFast_applied_price | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Fast: type of price |
| MASlow_ma_period | 69 | MA Slow: averaging period |
| MASlow_ma_shift | 0 | MA Slow: horizontal shift of the indicator |
| MASlow_ma_method | MODE_SMA | MA Slow: smoothing type |
| MASlow_applied_price | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Slow: type of price |
| MAFilter_ma_period | 2 | MA Filter: averaging period |
| MAFilter_ma_shift | 0 | MA Filter: horizontal shift of the indicator |
| MAFilter_ma_method | MODE_LWMA | MA Filter: smoothing type |
| MAFilter_applied_price | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Filter: type of price |
| MACDfast_ema_period | 120 | MACD: period for Fast average calculation |
| MACDslow_ema_period | 260 | MACD: period for Slow average calculation |
| MACDsignal_period | 90 | MACD: period for their difference averaging |
| InpMaxConsecLosses | 3 | Max consecutive losses before cooldown (0=disabled) |
| InpCooldownMinutes | 30 | Cooldown minutes after consec losses (0=disabled) |
| InpMaxTradesPerDay | 50 | Maximum trades per day |
| InpMinEquityPercent | 95.0 | Stop trading if equity < this % of initial balance |
| InpDailyLossLimitPct | 3.0 | Daily loss limit (% of effective capital) |
| InpWeeklyLossLimitPct | 6.0 | Weekly loss limit (% of effective capital) |
| InpCapitalCapAmount | 0.0 | Cap amount ($ real money equity) |
| InpCapitalCapFloor | 50.0 | Floor ($); block entries below this |
| InpServerGMTOffset | 0 | Server GMT offset hours (0=auto-detect) |
| InpLondonStartHour | 7 | London session start (GMT) |
| InpLondonEndHour | 16 | London session end (GMT) |
| InpNYStartHour | 12 | New York session start (GMT) |
| InpNYEndHour | 21 | New York session end (GMT) |
| InpAvoidAsia | true | Avoid Asian session |
| InpAsiaStartHour | 0 | Asian session start (GMT) |
| InpAsiaEndHour | 7 | Asian session end (GMT) |
| InpNewsFilter | false | Avoid trading near news session opens |
| InpNewsFilterMinutes | 15 | Minutes to avoid around news |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX08005 MACD_EA - MACD crossover with MA filter, full 12-layer stack."
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\DealInfo.mqh>
#include <Expert\Money\MoneyFixedMargin.mqh>
CPositionInfo m_position;
CTrade m_trade;
CSymbolInfo m_symbol;
CAccountInfo m_account;
CDealInfo m_deal;
CMoneyFixedMargin *m_money;
//--- input parameters
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_APPLIED_PRICE g_MAFast_applied_price = PRICE_CLOSE;
ENUM_APPLIED_PRICE g_MASlow_applied_price = PRICE_CLOSE;
ENUM_APPLIED_PRICE g_MAFilter_applied_price = PRICE_CLOSE;
input group "=== Identity ==="
input ulong m_magic=22208005; // magic number
input string InpTradeComment="Psgrowth.com Expert_08005"; // trade comment
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_APPLIED_PRICE g_MAFast_applied_price = PRICE_CLOSE;
ENUM_APPLIED_PRICE g_MASlow_applied_price = PRICE_CLOSE;
ENUM_APPLIED_PRICE g_MAFilter_applied_price = PRICE_CLOSE;
input group "=== Trading ==="
input double InpLots = 1.0; // Lots (use only if "Money Management" == false)
input ushort InpStopLoss = 80; // Stop Loss (in pips)
input ushort InpTakeProfit = 500; // Take Profit (in pips)
input ushort InpProfitOne = 70; // Profit for closing half of the position (in pips)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.