P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX16073 Trend

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

Pipsgrowth.com EX16073 Separate trade — dual-MA with ATR/StdDev filters, full 12-layer stack.

Overview

Pipsgrowth EX16073 is a dual-moving-average trend EA that hunts for the first moment a fast exponential average crosses a slow one — and only takes the trade when the market is calm enough to mean it. Two EMAs do the talking (a slow 65-period and a fast 14-period, both on close, both smoothed with the same MODE_EMA method), but the trigger is not the crossing itself. The trigger is the moment the two lines are still hugging each other — within 2 pips of one another — with the fast line on the right side. That narrow corridor is where the EA wants to be, because that is when a new impulse has just nudged a slow trend out of equilibrium and a directional move is most likely to extend.

Two volatility filters sit on top of that crossover zone. The first is a 26-period ATR — both a buy-side and a sell-side handle, with their own thresholds (InpATR_Level_Buy and InpATR_Level_Sell, default 0.0016). The ATR must be below that level for a buy to fire, and the same threshold governs sells. The second is a 54-period StdDev with a default ceiling of 0.0051. The two filters are not redundant: ATR measures range expansion over a fixed window, while StdDev measures the dispersion of closes around their own mean. A market can pass one and fail the other. The EA demands both pass.

The entry logic is symmetrical but the parameters are not. Each side carries its own ATR period, ATR level, StdDev period, StdDev level, MA-distance floor, stop-loss and take-profit. In practice that lets a trader dial buys for, say, a faster MA pair and sells for a slower one without re-compiling. The buy branch in OnTick reads: fast 14-EMA is above the slow 65-EMA, the gap between them is less than InpMAs_Delta_Buy pips, the 26-bar ATR is below 0.0016, and the 54-bar StdDev is below 0.0051. If the count of open positions (filtered by symbol + magic) is already at InpMaxPositions (default 1), nothing fires. The sell branch mirrors the conditions with > and a delta-floor for the opposite side. Note: setting either delta to 0 disables that side's gap filter entirely — useful for traders who want a pure cross without proximity gating.

The bar-gate logic is conservative. OnTick first calls Trailing() on every tick so that the ratchet always runs, but the signal evaluation only happens at the open of a new bar (a static PrevBars variable compared against the current iTime(0)). One decision per bar, no jitter trades. Once a position is open, m_last_deal_IN_buy and m_last_deal_IN_sell (updated by the OnTradeTransaction callback whenever a DEAL_ENTRY_IN with the right magic lands in history) prevent the same-side condition from re-firing on the next bar of the same trend.

Position management is where the strategy earns its keep. The defaults are 50-pip stop, 50-pip take-profit, 5-pip trailing stop, 5-pip trailing step — i.e. a 1:1 R:R on entry, rescued by a tight trail. The Trailing() function only moves the stop in one direction (up for longs, down for shorts) and only when price has moved further than TrailingStop + TrailingStep beyond the entry (default 10 pips). It refuses to lower an existing SL on a long, refuses to raise an existing SL on a short, and leaves a missing SL (i.e. one that has never been installed) untouched. The m_adjusted_point multiplier handles 3- and 5-digit brokers (e.g. gold at 2 decimals or 3, JPY pairs) so that the 50-pip figure stays a true 50 pips on every symbol.

The size is fixed. InpLots is the only sizing input — there is no risk-percentage formula, no balance curve, no progressive lot multiplier. The trade opens with a single call to m_trade.Buy or m_trade.Sell after a m_trade.CheckVolume pass that returns the broker-permitted lot for the requested price. The OpenBuy and OpenSell functions both call m_trade.SetExpertMagicNumber(m_magic) in OnInit, drop the comment Psgrowth.com Expert_16073 on every deal, and tolerate a 10-point slippage. Three retry helpers (TryClose_EX16073, TryClosePartial_EX16073, TryModify_EX16073) each loop up to three times on requote, timeout, price-changed, or price-off errors with a 100–200 ms back-off, but in this build the Trailing() function is the only place where TryModify_EX16073 is actually called — the close helpers are wired in but never invoked from OnTick, so position exits are left to SL, TP, or manual action.

What the EA does not do is worth listing. There is no news filter, no session gate, no time-of-day restriction — it will take a signal at the open of the New York evening or the Asian session open if the four-bar pattern aligns. There is no drawdown cap, no daily-loss circuit breaker, no consecutive-loss cooldown, no equity-floor. There is no spread filter; on a widened-spread candle the trade can still fire. There is no opposite-signal close — once a long is open, an emerging short signal will not flatten it. Those features are deliberate omissions: the EA is built as a pure trend-emergence engine and assumes the operator (or a wrapper EA) is managing account-level risk separately.

For backtesting, the expected behaviour is that most months will print a small handful of trades — the four-bar gate (cross + proximity + ATR + StdDev) is narrow and only fires during specific quiet-then-impulse transitions on the chosen timeframe (M5 or H1 per the family default). The 1:1 R:R means breakeven expectancy requires a win rate above 50%, but the 5+5 trailing converts many of the would-be scratch losses into small wins and many of the would-be 1:1 wins into extended runners, so live equity curves tend to be more profitable than the static backtest would suggest. The asymmetry between InpStopLossBuy and InpStopLossSell, and between the two ATR/StdDev levels, lets a trader who has profiled one symbol tune buys and sells independently — for example, cutting the sell-SL on a market that historically reverses sharply from short setups while leaving the buy-SL wider for trend days.

A reasonable first test plan: run the EA on XAUUSD M5 with the published defaults (0.1 lot, 50/50, 5/5 trail, MA 14/65 EMA, ATR 26 @ 0.0016, StdDev 54 @ 0.0051) over a 12-month window using every tick from a real-history-quality source. Look for two things — frequency of signals (should be sparse, not every day) and the ratio of trailing-stop exits vs TP hits vs SL hits. If trailing-stop exits dominate, the 5-pip step is working; if SL hits dominate, the 50-pip stop is too tight for the symbol's noise floor and should be widened. Because the EA has no internal P&L guard, every test should be wrapped in a parent script that enforces a maximum drawdown and closes the chart on breach.

Strategy Deep Dive

On every tick, Trailing() first sweeps positions matching magic 22216073 on the chart symbol and ratchets each one's SL one-way in 5-pip increments once price has moved 10+ pips beyond entry. The signal engine then waits for a new bar (via the static PrevBars gate) before reading the 14-EMA, 65-EMA, 26-bar ATR, and 54-bar StdDev at the previous bar. Buy fires only when the 14-EMA is above the 65-EMA within a 2-pip corridor, ATR is below 0.0016, and StdDev is below 0.0051; sell fires on the mirror. Order submission goes through m_trade.CheckVolume first, then a single Buy or Sell call with fixed InpLots (default 0.1), fixed SL/TP (default 50/50), and the comment Psgrowth.com Expert_16073. The OnTradeTransaction callback records the bar time of each filled entry so the same-side condition cannot re-fire on the next bar of the same trend. No news filter, no session gate, no drawdown cap, no opposite-signal close — the four-bar gate does the filtering and the trailing stop does the profit-locking.

Entry Signal

Buys when the 14-EMA is above the 65-EMA with separation under 2 pips, 26-bar ATR below 0.0016, and 54-bar StdDev below 0.0051 (low-volatility fresh-cross zone). Sells on the mirror condition: 14-EMA below 65-EMA with separation under 2 pips, ATR below 0.0016, and StdDev below 0.0051. Signals only fire on the open of a new bar and only when current open positions on the symbol are below InpMaxPositions (default 1).

Exit Signal

Positions exit via fixed TP (default 50 pips) or SL (default 50 pips) at the broker level. The Trailing() function ratchets the SL one-way in 5-pip steps once price has moved 10+ pips beyond entry, locking open profits but never tightening an already-set stop. There is no opposite-signal close, no time-based exit, and no basket-level P&L close — the only working close path from OnTick is the trailing-stop modification.

Stop Loss

Fixed stop-loss per side, default 50 pips for both buy and sell (configurable independently via InpStopLossBuy and InpStopLossSell). The pip size is auto-adjusted for 3/5-digit brokers via m_adjusted_point so 50 stays a true 50 pips on XAUUSD. Once price moves 10+ pips in favour, the trailing system ratchets the SL in 5-pip increments.

Take Profit

Fixed take-profit per side, default 50 pips for both buy and sell (1:1 R:R on entry), set on the broker at the moment of order submission. TP is never re-evaluated by the EA — once placed, only the SL moves (via the trailing function), and the original TP stays until the broker fills it.

Best For

Best on XAUUSD M5 or H1, though the indicator set is portable to any liquid pair — the EA reads only MAs, ATR, and StdDev with no symbol-specific assumptions. The default ATR threshold (0.0016) and StdDev ceiling (0.0051) are calibrated for gold at typical 1–3 pip-per-tick volatility, so FX majors on M5 may need both levels adjusted down by an order of magnitude. Minimum recommended balance is $100 with the 0.1-lot default, but only on a low-spread ECN/raw-spread account — the 50-pip fixed SL and the lack of an internal spread filter mean a 2-pip spread on a 50-pip target already eats 4% of the R:R. Suitable for traders who want a pure trend-emergence signal without news filters, session windows, or daily P&L circuit breakers interfering with the four-bar pattern; account-level risk should be enforced by a parent script or the broker's equity stop.

Strategy Logic

Pipsgrowth EX16073 Trend — Strategy Logic Analysis (from .mq5 source)

Family: Trend Magic: 22216073 Version: 2.00

BRIEF: Dual-MA trend EA with ATR and StdDev volatility filters. Buys when fast MA is above slow MA with sufficient separation and low ATR/StdDev; sells on the inverse condition. Separate SL/TP for buy and sell, trailing stop, and max-position limit

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • OnTradeTransaction()
  • RefreshRates()
  • CheckVolumeValue()
  • Trailing()
  • PrintResultModify()
  • CalculateAllPositions()
  • iMAGet()
  • iATRGet()
  • iStdDevGet()
  • OpenBuy()
  • OpenSell()
  • PrintResultTrade()
  • ...and 3 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (23 total across 1 groups):

  • [] m_magic = 22216073 // Magic number
  • [] InpLots = 0.1 // Lots
  • [] InpStopLossBuy = 50 // Stop Loss Buy (in pips)
  • [] InpStopLossSell = 50 // Stop Loss Sell (in pips)
  • [] InpTakeProfitBuy = 50 // Take Profit Buy (in pips)
  • [] InpTakeProfitSell = 50 // Take Profit Sell (in pips)
  • [] InpTrailingStop = 5 // Trailing Stop (in pips)
  • [] InpTrailingStep = 5 // Trailing Step (in pips)
  • [] InpMaxPositions = 1 // Maximum positions
  • [] InpMA_First_ma_period = 65 // MA First: averaging period
  • [] InpMA_Second_ma_period = 14 // MA Second: averaging period
  • [] InpMA_ma_method = MODE_EMA // MA First and Second: smoothing type
  • [] InpMA_applied_price = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // MA First and Second: type of price
  • [] InpMAs_Delta_Buy = 2 // Minimum distance between MA's for Buy ("0" -> off) (in pips)
  • [] InpMAs_Delta_Sell = 2 // Minimum distance between MA's for Sell ("0" -> off) (in pips)
  • [] InpATR_ma_period_Buy = 26 // ATR Buy: averaging period
  • [] InpATR_ma_period_Sell = 26 // ATR Sell: averaging period
  • [] InpATR_Level_Buy = 0.0016 // ATR Buy: Level (if ATR < "ATR Buy" -> BUY)
  • [] InpATR_Level_Sell = 0.0016 // ATR Sell: Level (if ATR > "ATR Sell" -> Sell)
  • [] InpStdDev_ma_period_Buy = 54 // StdDev Buy: averaging period
  • [] InpStdDev_ma_period_Sell = 54 // StdDev Sell: averaging period
  • [] InpStdDev_Level_Buy = 0.0051 // StdDev Buy: Level (if StdDev < "StdDev Buy" -> BUY)
  • [] InpStdDev_Level_Sell = 0.0051 // StdDev Sell: Level (if StdDev > "StdDev Sell" -> Sell)
Pseudocode
// Pipsgrowth EX16073 Trend — Execution Flow (from source analysis)
// Family: Trend
// Dual-MA trend EA with ATR and StdDev volatility filters. Buys when fast MA is above slow MA with sufficient separation and low ATR/StdDev; sells on the inverse condition. Separate SL/TP for buy and sell, trailing stop, and max-position limit

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_magic22216073Magic number
InpLots0.1Lots
InpStopLossBuy50Stop Loss Buy (in pips)
InpStopLossSell50Stop Loss Sell (in pips)
InpTakeProfitBuy50Take Profit Buy (in pips)
InpTakeProfitSell50Take Profit Sell (in pips)
InpTrailingStop5Trailing Stop (in pips)
InpTrailingStep5Trailing Step (in pips)
InpMaxPositions1Maximum positions
InpMA_First_ma_period65MA First: averaging period
InpMA_Second_ma_period14MA Second: averaging period
InpMA_ma_methodMODE_EMAMA First and Second: smoothing type
InpMA_applied_price1Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // MA First and Second: type of price
InpMAs_Delta_Buy2Minimum distance between MA's for Buy ("0" -> off) (in pips)
InpMAs_Delta_Sell2Minimum distance between MA's for Sell ("0" -> off) (in pips)
InpATR_ma_period_Buy26ATR Buy: averaging period
InpATR_ma_period_Sell26ATR Sell: averaging period
InpATR_Level_Buy0.0016ATR Buy: Level (if ATR < "ATR Buy" -> BUY)
InpATR_Level_Sell0.0016ATR Sell: Level (if ATR > "ATR Sell" -> Sell)
InpStdDev_ma_period_Buy54StdDev Buy: averaging period
InpStdDev_ma_period_Sell54StdDev Sell: averaging period
InpStdDev_Level_Buy0.0051StdDev Buy: Level (if StdDev < "StdDev Buy" -> BUY)
InpStdDev_Level_Sell0.0051StdDev Sell: Level (if StdDev > "StdDev Sell" -> Sell)
Source Code (.mq5)Open Source
Pipsgrowth_com_EX16073.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX16073 Separate trade — dual-MA with ATR/StdDev filters, 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 <Trade\OrderInfo.mqh>
#include <Expert\Money\MoneyFixedMargin.mqh>
CPositionInfo  m_position;                   // trade position object
CTrade         m_trade;                      // trading object
CSymbolInfo    m_symbol;                     // symbol info object
CAccountInfo   m_account;                    // account info wrapper
CDealInfo      m_deal;                       // deals object
COrderInfo     m_order;                      // pending orders object
CMoneyFixedMargin *m_money;
//--- input parameters
sinput const string GroupIdentity="";//=== Identity ===
input ulong    m_magic                 = 22216073; // Magic number
input string   InpTradeComment         = "Psgrowth.com Expert_16073";
sinput const string GroupTrading="";//=== Trading ===
input double   InpLots                 = 0.1;      // Lots
input ushort   InpStopLossBuy          = 50;       // Stop Loss Buy (in pips)
input ushort   InpStopLossSell         = 50;       // Stop Loss Sell (in pips)
input ushort   InpTakeProfitBuy        = 50;       // Take Profit Buy (in pips)
input ushort   InpTakeProfitSell       = 50;       // Take Profit Sell (in pips)
input ushort   InpTrailingStop         = 5;        // Trailing Stop (in pips)
input ushort   InpTrailingStep         = 5;        // Trailing Step (in pips)
input int      InpMaxPositions         = 1;        // Maximum positions
sinput const string GroupMA="";//=== MA Settings ===
input int                  InpMA_First_ma_period   = 65;          // MA First: averaging period 
input int                  InpMA_Second_ma_period  = 14;          // MA Second: averaging period 
input ENUM_MA_METHOD       InpMA_ma_method         = MODE_EMA;    // MA First and Second: smoothing type 
input int InpMA_applied_price = 1; // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // MA First and Second: type of price 
input ushort               InpMAs_Delta_Buy        = 2;           // Minimum distance between MA's for Buy ("0" -> off) (in pips)
input ushort               InpMAs_Delta_Sell       = 2;           // Minimum distance between MA's for Sell ("0" -> off) (in pips)
sinput const string GroupATR="";//=== ATR Filter ===
input int      InpATR_ma_period_Buy    = 26;       // ATR Buy: averaging period
input int      InpATR_ma_period_Sell   = 26;       // ATR Sell: averaging period
input double   InpATR_Level_Buy        = 0.0016;   // ATR Buy: Level (if ATR < "ATR Buy" -> BUY)
input double   InpATR_Level_Sell       = 0.0016;   // ATR Sell: Level (if ATR > "ATR Sell" -> Sell)
sinput const string GroupStdDev="";//=== StdDev Filter ===
input int      InpStdDev_ma_period_Buy = 54;       // StdDev Buy: averaging period
input int      InpStdDev_ma_period_Sell= 54;       // StdDev Sell: averaging period
input double   InpStdDev_Level_Buy     = 0.0051;   // StdDev Buy: Level (if StdDev < "StdDev Buy" -> BUY)
input double   InpStdDev_Level_Sell    = 0.0051;   // StdDev Sell: Level (if StdDev > "StdDev Sell" -> Sell)
//---
ulong          m_slippage=10;                // slippage

double         ExtStopLossBuy=0.0;
double         ExtStopLossSell=0.0;
double         ExtTakeProfitBuy=0.0;
double         ExtTakeProfitSell=0.0;
double         ExtTrailingStop=0.0;
double         ExtTrailingStep=0.0;
double         ExtMAs_Delta_Buy=0.0;

Full source code available on download

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

Tags:ex16073trendpipsgrowthfreemt5xauusd

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