P
PipsGrowth
Trend FollowingOpen Source – Free

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.

Entry Signal

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.

Exit Signal

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.

Stop Loss

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.

Take Profit

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.

Best For

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 MT5 indicators

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 // Stop Loss (in pips)
  • [=== Trading ===] InpTakeProfit = 500 // Take Profit (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: GMT Sessions ===] InpServerGMTOffset = 0 // Server GMT offset hours (0=auto-detect)
  • [=== Hardening: GMT Sessions ===] InpLondonStartHour = 7 // London session start (GMT)
  • [=== Hardening: GMT Sessions ===] InpLondonEndHour = 16 // London session end (GMT)
  • [=== Hardening: GMT Sessions ===] InpNYStartHour = 12 // New York session start (GMT)
  • [=== Hardening: GMT Sessions ===] InpNYEndHour = 21 // New York session end (GMT)
  • [=== Hardening: GMT Sessions ===] InpAvoidAsia = true // Avoid Asian session
  • [=== Hardening: GMT Sessions ===] InpAsiaStartHour = 0 // Asian session start (GMT)
  • [=== Hardening: GMT Sessions ===] InpAsiaEndHour = 7 // Asian session end (GMT)
  • [=== Hardening: GMT Sessions ===] InpNewsFilter = false // Avoid trading near news session opens
  • [=== Hardening: GMT Sessions ===] InpNewsFilterMinutes = 15 // Minutes to avoid around news
Pseudocode
// 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

Optimized Brokers:
ExnessIC Markets
Optimized Symbols:
XAUUSD
Optimized Timeframes:
M5H1

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 an H4 or Daily chart for best results
  7. 7Configure EMA periods, ADX threshold, and lot size in the dialog
  8. 8Enable Allow Algo Trading and click OK

EA Parameters

ParameterDefaultDescription
m_magic22208005magic number
InpTradeComment"Psgrowth.com Expert_08005"trade comment
InpLots1.0Lots (use only if "Money Management" == false)
InpStopLoss80Stop Loss (in pips)
InpTakeProfit500Take Profit (in pips)
InpProfitOne70Profit for closing half of the position (in pips)
InpBreakeven0Breakeven (in pips)
MMfalseMoney Management
Risk1.0Risk in percent for a deal from a free margin
MAFast_ma_period55MA Fast: averaging period
MAFast_ma_shift0MA Fast: horizontal shift of the indicator
MAFast_ma_methodMODE_EMAMA Fast: smoothing type
MAFast_applied_price1Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Fast: type of price
MASlow_ma_period69MA Slow: averaging period
MASlow_ma_shift0MA Slow: horizontal shift of the indicator
MASlow_ma_methodMODE_SMAMA Slow: smoothing type
MASlow_applied_price1Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Slow: type of price
MAFilter_ma_period2MA Filter: averaging period
MAFilter_ma_shift0MA Filter: horizontal shift of the indicator
MAFilter_ma_methodMODE_LWMAMA Filter: smoothing type
MAFilter_applied_price1Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted)// MA Filter: type of price
MACDfast_ema_period120MACD: period for Fast average calculation
MACDslow_ema_period260MACD: period for Slow average calculation
MACDsignal_period90MACD: period for their difference averaging
InpMaxConsecLosses3Max consecutive losses before cooldown (0=disabled)
InpCooldownMinutes30Cooldown minutes after consec losses (0=disabled)
InpMaxTradesPerDay50Maximum trades per day
InpMinEquityPercent95.0Stop trading if equity < this % of initial balance
InpDailyLossLimitPct3.0Daily loss limit (% of effective capital)
InpWeeklyLossLimitPct6.0Weekly loss limit (% of effective capital)
InpCapitalCapAmount0.0Cap amount ($ real money equity)
InpCapitalCapFloor50.0Floor ($); block entries below this
InpServerGMTOffset0Server GMT offset hours (0=auto-detect)
InpLondonStartHour7London session start (GMT)
InpLondonEndHour16London session end (GMT)
InpNYStartHour12New York session start (GMT)
InpNYEndHour21New York session end (GMT)
InpAvoidAsiatrueAvoid Asian session
InpAsiaStartHour0Asian session start (GMT)
InpAsiaEndHour7Asian session end (GMT)
InpNewsFilterfalseAvoid trading near news session opens
InpNewsFilterMinutes15Minutes to avoid around news
Source Code (.mq5)Open Source
Pipsgrowth_com_EX08005.mq5
#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.

Tags:ex08005macdpipsgrowthfreemt5xauusd

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_EX08005.mq5
File Size32.8 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyTrend Following
Risk LevelMedium Risk
Timeframes
M5H1
Currency Pairs
XAUUSD
Min. Deposit$100