P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX07007 MA

MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1

Pipsgrowth.com EX07007 sma — Triple SMA crossover with spread separation, full 12-layer stack.

Overview

Pipsgrowth EX07007 MA is a triple-simple-moving-average crossover EA that lives or dies by a single concept: the three SMAs must line up in order, and they must be separated by a minimum pip distance before a trade is allowed. There is no regime filter, no news block, no session gate, no martingale, no grid, and no partial-close. The strategy is intentionally minimal — a pure trend signal with a small amount of anti-whipsaw filtering layered on top — which means the EA is portable across FX majors and metals and stays understandable after one read of the source.

Three iMA handles drive the entire decision. They are created in OnInit with iMA(symbol, period, period_MA, shift, MODE_SMA, PRICE_CLOSE) and bound to MA1 = period 9 shift 0, MA2 = period 14 shift 1, MA3 = period 29 shift 2. The default periods follow a fast/mid/slow cascade so MA1 reacts first, MA2 confirms, and MA3 sets the background direction. The shift values are non-zero on the slower two lines (1 bar back for MA2, 2 bars back for MA3), which delays their turn slightly and tightens the trend definition — the fast line has to outrun lines that are deliberately lagged, so a valid crossover has to be decisive enough to clear the gap. m_adjusted_point is computed from m_symbol.Point() times 1 or 10 depending on the symbol's digits (3- or 5-digit instruments get the ×10 adjustment), and ExtMAspread is then defined as InpMAspread (default 10 pips) multiplied by m_adjusted_point. The internal distance the three SMAs need between each other is therefore a real price gap, not a raw point count, which keeps the threshold consistent on XAUUSD (2-decimal quotes) and on EURUSD (5-decimal quotes).

Entry is mechanical. On every tick, OnTick() copies the current bar-0 value from each of the three iMA handles via iMAGet(), then evaluates two conditions in order. A long is allowed only when ma1_0 > ma2_0 + ExtMAspread AND ma2_0 > ma3_0 + ExtMAspread, with count_buys == 0. A short is the mirror: ma1_0 < ma2_0ExtMAspread AND ma2_0 < ma3_0ExtMAspread, with count_sells == 0. The two conditions together mean the fast line must be cleanly above the middle, the middle must be cleanly above the slow, and there must be no opposing position already open. After OpenBuy(0.0, 0.0) or OpenSell(0.0, 0.0) returns, the function exits immediately so the second side cannot fire on the same tick. Both OpenBuy and OpenSell pass 0.0 for sl and tp, which is intentional: the strategy does not use a hard stop or target on the order itself.

Exit logic is asymmetric against entry and is where the EA's risk control actually lives. The reverse close is triggered on a much smaller spread: an open BUY is closed via TryClose_EX07007 when ma1_0 < ma2_0ExtMAspread/2.0, and an open SELL is closed when ma1_0 > ma2_0 + ExtMAspread/2.0. The entry gate requires a full ExtMAspread between MA1 and MA2, but the exit gate fires at half that distance. The practical effect is that an open position stays in place through minor pullbacks (a fast line drifting back toward the middle, but not crossing it) and is closed the moment the structure actually breaks. There is no trailing stop, no breakeven move, and no time stop — the only path out of a trade is the spread-based MA1/MA2 reversal.

Position sizing is fixed at InpLots (default 0.1). CheckVolumeValue() runs in OnInit to ensure the lot value sits between m_symbol.LotsMin() and m_symbol.LotsMax() and is an exact multiple of m_symbol.LotsStep(); if the test fails, the EA refuses to start with INIT_PARAMETERS_INCORRECT. CTrade's CheckVolume is also called immediately before OrderSend to guard against insufficient margin, and m_trade.SetTypeFillingBySymbol picks the correct FILLING mode for the broker automatically. Slippage is set to 10 points through m_trade.SetDeviationInPoints(10), and the magic number 22207007 is set via SetExpertMagicNumber. The order comment is configurable through InpTradeComment.

Retry logic is built into three wrappers. TryClose_EX07007, TryClosePartial_EX07007, and TryModify_EX07007 each loop up to three times on TRADE_RETCODE_REQUOTE, TRADE_RETCODE_TIMEOUT, TRADE_RETCODE_PRICE_OFF, and TRADE_RETCODE_PRICE_CHANGED with a 200 ms Sleep between attempts (the modify wrapper sleeps 100 ms and only retries on REQUOTE/TIMEOUT). On any other retcode the loop breaks immediately. The wrappers are declared but only TryClose_EX07007 is wired into the live logic — there is no trailing or partial path that calls them in this build. That asymmetry is worth noting for anyone reading the code: the safety net exists for the path the EA actually uses.

The file header claims a twelve-layer architecture (regime, signal, entry, confirm, no-trade, capital cap, risk, sizing, manage, exit, scaling, OnTester) but the implementation is more compact. The actual layers that fire on every tick are: read MAs → scan positions → close any trade whose MA1/MA2 spread has collapsed → otherwise open a new direction if the spread has expanded. There is no session filter, no news blackout, no daily-loss guard, no equity-floor protection, no martingale, and no OnTester formula. Anyone expecting the full twelve-layer framework should be aware that this particular build delivers a stripped-down variant.

In practice, EX07007 is best used by a trader who wants a small, transparent signal source and is willing to handle portfolio-level risk themselves — for example, running it inside a multi-EA setup with an external risk cap, or paper-trading the signal as a screening tool. Because there is no per-trade stop, a market that gaps or trends hard against the entry will keep the position open until the SMA structure finally turns. A user who needs hard stops for prop-firm compliance should layer them externally, or choose a build in this family that wires SL/TP into OpenBuy/OpenSell (those parameters are 0.0 in this file and would need to be set in the source). For its intended use — clean three-line trend following on liquid instruments with a clear crossover definition — the EA is honest about what it does and easy to read.

Strategy Deep Dive

OnInit creates three iMA handles on the chart symbol and timeframe using iMA(symbol, period, period, shift, MODE_SMA, PRICE_CLOSE) and converts InpMAspread (default 10 pips) into a real price distance via m_adjusted_point. On every tick, OnTick() reads bar-0 values from all three handles through iMAGet() and walks the open positions in reverse: any long whose MA1 has dropped to within half-ExtMAspread below MA2 is closed via TryClose_EX07007, and any short whose MA1 has risen above MA2 by half-ExtMAspread is closed the same way. If no closing fired, the function checks for new entries — a long when MA1 sits a full ExtMAspread above both MA2 and MA3 with no open buy, a short on the mirror. Position sizing is fixed at InpLots (0.1 default) with CTrade.CheckVolume as a pre-flight guard. There is no session filter, no regime classifier, no news blackout, no equity-floor protection, no daily-loss cap, no martingale, and no OnTester formula — the file header's twelve-layer list is aspirational; the actual live logic is the three-line crossover with a half-spread exit threshold.

Entry Signal

A long fires when the fast SMA (period 9) sits above the middle SMA (period 14, shift 1) by at least InpMAspread (default 10 pips) AND the middle SMA sits above the slow SMA (period 29, shift 2) by the same gap, with no existing buy open. A short is the mirror. Both OpenBuy and OpenSell pass 0.0 for SL and TP — the order has no hard stop on the server.

Exit Signal

An open buy is closed when the fast SMA drops below the middle SMA by half the InpMAspread distance (5 pips with defaults), and an open sell is closed on the mirror condition. There is no trailing stop, no breakeven, and no time stop — the only exit path is the MA1/MA2 reversal. The reverse close runs through TryClose_EX07007, which retries up to three times on requote, timeout, price-off, and price-changed retcodes with a 200 ms sleep between attempts.

Stop Loss

No stop-loss is attached to the order — OpenBuy and OpenSell both call m_trade.Buy/Sell with sl = 0.0. Position risk is managed entirely by the MA1/MA2 reversal exit, so a position can stay open through significant adverse movement until the spread-based signal collapses.

Take Profit

No take-profit is attached to the order — OpenBuy and OpenSell both call m_trade.Buy/Sell with tp = 0.0. Exits happen only via the MA1/MA2 reversal signal. TryModify_EX07007 is declared in the source but is not wired into any live path in this build, so no SL/TP modification happens after entry.

Best For

Minimum recommended balance: $100. Best suited to traders who want a transparent three-line trend signal and are willing to manage portfolio-level risk themselves — the EA carries no per-trade stop, so a user with prop-firm compliance requirements should layer stops externally or pick a different build. Run on liquid FX majors or XAUUSD on M5H1; the slippage tolerance is 10 points, so a standard or ECN account with typical retail spreads is sufficient. Session choice is not gated by the EA, so the trader picks the window — for a clean crossover signal on metals, London and New York hours give the most decisive MA separation.

Strategy Logic

Pipsgrowth EX07007 MA — Strategy Logic Analysis (from .mq5 source)

Family: MA Magic: 22207007 Version: 2.00

BRIEF: Triple SMA crossover EA using three moving averages with configurable spread separation. Entry: MA1 > MA2 > MA3 with minimum spread = BUY; MA1 < MA2 < MA3 = SELL. Exits on MA1/MA2 reversal. Fixed lot sizing. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • OnTradeTransaction()
  • RefreshRates()
  • CheckVolumeValue()
  • iMAGet()
  • OpenBuy()
  • OpenSell()
  • PrintResultTrade()
  • TryClose_EX07007()
  • TryClosePartial_EX07007()
  • TryModify_EX07007()

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (10 total across 3 groups):

  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_07007" // Trade Comment
  • [=== Identity ===] m_magic = 22207007 // Magic Number
  • [=== Trading ===] InpLots = 0.1 // Lots
  • [=== Trading ===] InpMAspread = 10 // MA's spread (in pips)
  • [=== Indicators ===] Inp_ma_period_MA1 = 9 // MA 1: averaging period
  • [=== Indicators ===] Inp_ma_shift_MA1 = 0 // MA 1: horizontal shift
  • [=== Indicators ===] Inp_ma_period_MA2 = 14 // MA 2: averaging period
  • [=== Indicators ===] Inp_ma_shift_MA2 = 1 // MA 2: horizontal shift
  • [=== Indicators ===] Inp_ma_period_MA3 = 29 // MA 3: averaging period
  • [=== Indicators ===] Inp_ma_shift_MA3 = 2 // MA 3: horizontal shift
Pseudocode
// Pipsgrowth EX07007 MA — Execution Flow (from source analysis)
// Family: MA
// Triple SMA crossover EA using three moving averages with configurable spread separation. Entry: MA1 > MA2 > MA3 with minimum spread = BUY; MA1 < MA2 < MA3 = SELL. Exits on MA1/MA2 reversal. Fixed lot sizing. 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:
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
InpTradeComment"Psgrowth.com Expert_07007"Trade Comment
m_magic22207007Magic Number
InpLots0.1Lots
InpMAspread10MA's spread (in pips)
Inp_ma_period_MA19MA 1: averaging period
Inp_ma_shift_MA10MA 1: horizontal shift
Inp_ma_period_MA214MA 2: averaging period
Inp_ma_shift_MA21MA 2: horizontal shift
Inp_ma_period_MA329MA 3: averaging period
Inp_ma_shift_MA32MA 3: horizontal shift
Source Code (.mq5)Open Source
Pipsgrowth_com_EX07007.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX07007 sma — Triple SMA crossover with spread separation, full 12-layer stack."
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>  
CPositionInfo  m_position;                   // trade position object
CTrade         m_trade;                      // trading object
CSymbolInfo    m_symbol;                     // symbol info object
//--- input parameters
input group "=== Identity ==="
input string   InpTradeComment   = "Psgrowth.com Expert_07007"; // Trade Comment
input ulong    m_magic           = 22207007; // Magic Number

input group "=== Trading ==="
input double   InpLots           = 0.1;      // Lots
input ushort   InpMAspread       = 10;       // MA's spread (in pips)

input group "=== Indicators ==="
input int      Inp_ma_period_MA1 = 9;        // MA 1: averaging period
input int      Inp_ma_shift_MA1  = 0;        // MA 1: horizontal shift
input int      Inp_ma_period_MA2 = 14;       // MA 2: averaging period
input int      Inp_ma_shift_MA2  = 1;        // MA 2: horizontal shift
input int      Inp_ma_period_MA3 = 29;       // MA 3: averaging period
input int      Inp_ma_shift_MA3  = 2;        // MA 3: horizontal shift
//---
ulong          m_slippage=10;                // slippage

double ExtMAspread=0;

int    handle_iMA1;                          // variable for storing the handle of the iMA indicator
int    handle_iMA2;                          // variable for storing the handle of the iMA indicator
int    handle_iMA3;                          // variable for storing the handle of the iMA indicator

double m_adjusted_point;                     // point value adjusted for 3 or 5 points
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(!m_symbol.Name(Symbol())) // sets symbol name
      return(INIT_FAILED);
   RefreshRates();

   string err_text="";
   if(!CheckVolumeValue(InpLots,err_text))
     {
      Print(__FUNCTION__,", ERROR: ",err_text);
      return(INIT_PARAMETERS_INCORRECT);
     }
//---
   m_trade.SetExpertMagicNumber(m_magic);
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(m_symbol.Name());
   m_trade.SetDeviationInPoints(m_slippage);
//--- tuning for 3 or 5 digits
   int digits_adjust=1;

Full source code available on download

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

Tags:ex07007mapipsgrowthfreemt5xauusd

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