P
PipsGrowth
Trend FollowingOpen Source – Free

Pipsgrowth EX16025 Trend

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

Pipsgrowth.com EX16025 BullishBearish_Engulfing_MFI - Engulfing pattern + MFI confirm + MA trend filter, full 12-layer stack.

Overview

Pipsgrowth EX16025 takes the two-candle bullish/bearish engulfing pattern and refuses to act on it until a slow Money Flow Index has reached an extreme on the opposite side of the trade. The pattern itself is the classic Steve Nison reversal: a small-bodied prior candle fully consumed by a larger-bodied candle moving in the opposite direction, but the EA adds three filters before it will commit capital. The latest candle's body must exceed the twelve-bar average body size (the InpAverBodyPeriod window), which is the EA's own way of demanding that the engulfing actually has conviction rather than being a doji-vs-doji coincidence. The engulfing must also form at the right place in the trend: a bullish engulfing only counts when the prior candle's midpoint sat below the 5-period SMA (the InpMAPeriod trend filter), and a bearish engulfing only counts when the prior candle's midpoint sat above it. Without that trend-context requirement, this EA would interpret every counter-trend pause as a reversal signal; the SMA filter turns the pattern into a directional move that is, in effect, mean-reverting against a short-term trend. The result is that EX16025 trades counter-trend swings inside the larger M5 cadence, expecting the 5-SMA to act as a reversion rail.

The confirmation stage reads the MFI(37) - a deliberately slow period that smooths the standard 14-period reading into something more patient - and gates each direction with a one-sided threshold. A bullish engulfing is only confirmed if MFI on bar 1 is below 40, meaning money flow on the just-closed candle is depressed enough that buyers have begun returning on a flow basis. A bearish engulfing is only confirmed if MFI on bar 1 is above 60, the mirror case where flow has expanded to overbought. The asymmetry - long requires depressed flow, short requires elevated flow - is the standard mean-reversion permission pattern: the EA only takes a reversal when the oscillator agrees that the prior move has gone too far in the wrong direction. The MFI and the MA are both fed from native MT5 handles (iMFI with InpVolume=VOLUME_TICK and iMA at InpMAPeriod=5, MODE_SMA, PRICE_CLOSE), so the indicator stack is exactly two handles - leaner than the four- or five-handle EAs in the same family.

Entries are market orders fired through a CTrade wrapper, with the slippage set from the InpSlippage input (default 10 points) and the magic number fixed at 22216025 so this stream is identifiable on a multi-EA chart. Stop loss and take profit are both 200 points by default, which on XAUUSD M5 is roughly a 1:1 risk-reward geometry (the same as the rest of this family). The PositionOpen() function carries a useful safety: if the current spread is wider than the requested SL or TP distance, the EA falls back to using the spread itself as the protective level, so the order will still be accepted by the broker even on a wide-spread minute. Both the SL and the TP branches carry this guard independently. Lot size is fixed at 0.10 from the InpLot input; there is no risk-percentage scaling, no balance-aware step, and no martingale. The holding time is bounded by InpDuration=10 bars, measured through the BarsHold() helper that copies the rate history from the position's open time to TimeCurrent() and counts how many bars fit in the span - so on M5 the absolute ceiling is fifty minutes, and on H1 it is ten hours.

Exits run in three independent layers. First, the CheckCloseSignal() function watches for a four-case MFI cross: a long position closes if MFI(1) drops below 70 after having been above 70 on bar 2 (overbought exit) OR if MFI(1) drops below 30 after having been above 30 on bar 2 (oversold recovery exit - in this strategy's logic that means the oscillator is rolling back from a low, which often precedes a fresh lower-low and is treated as a reason to give back the long). A short position closes on the mirror. Second, the time stop fires via CloseByTime() which walks PositionsTotal() looking for positions whose BarsHold() reading has reached InpDuration. Third, the static 200/200 SL and TP are always on as the broker-side backstop. The retry helper TryClose_EX16025 is the only one of the three that is actually wired into the live close path - it makes up to three attempts on REQUOTE/TIMEOUT/PRICE_OFF/PRICE_CHANGED with 200 ms between attempts. TryClosePartial_EX16025 and TryModify_EX16025 are defined in the source but never called; they sit in the file as dead code, presumably scaffolding for a future partial-close or trailing-stop feature.

The OnTick() function is a four-phase pipeline. Phase 1 runs only on a new bar (guarded by the static datetime next_bar_open anchor that advances by PeriodSeconds(_Period)) and calls CheckState() - which in turn calls CheckPattern(), CheckConfirmation(), and CheckCloseSignal() in sequence and sets the global ExtSignalOpen, ExtSignalClose, and ExtPatternInfo strings. If the bar check fails, OnTick() returns early and retries on the next tick. Phase 2 opens a position if ExtSignalOpen is non-zero and there is no position in that direction. Phase 3 closes a position if ExtSignalClose is non-zero and a position exists. Phase 4 walks all open positions and time-closes any that have hit InpDuration. There is no partial-close step, no trailing stop, no break-even step, and no pyramiding - the only management logic is the three exit sources above and the broker-side SL/TP. There is also no daily-loss limit, no equity stop, no maximum-drawdown cap, and no session filter; the EA trades whenever a pattern forms during the symbol's trading hours.

The header advertises a 12-layer architecture (REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester), but honest accounting of the code shows that nine of those layers are actually wired: the 5-SMA trend filter (REGIME), the engulfing geometry (SIGNAL), the market-order entry (ENTRY), the MFI<40/>60 confirm (CONFIRM), the new-bar guard plus time exit (NO-TRADE), the 200-point SL with the spread-override guard (RISK), the fixed 0.10 lot (SIZING), the MFI cross plus time plus SL/TP triple-exit (EXIT). The MANAGE layer is empty (no trailing, no break-even, no partial), the CAPITAL CAP layer is empty (no max-DD, no daily loss), the SCALING layer is empty (no pyramiding, no martingale), and the OnTester pass is absent from the source. Anyone evaluating this EA for live deployment should treat the header's 12-layer claim as the design intent, not the current implementation - the gap between the nine wired layers and the advertised twelve is real, and the missing three layers are exactly the safety stack that most retail traders want to see in production.

For deployment, the EA is portable across FX majors and metals through the _Symbol macro, but the .mq5 header and the test environment both target XAUUSD on M5 as the primary chart, with H1 as the documented alternative. Minimum deposit is 100 USD for a single 0.10-lot XAUUSD position, though a 500 USD buffer is more realistic for surviving a streak of stopped-out 200-point trades. Because the SL/TP distances are short and the strategy is pattern-based rather than flow-based, the broker requirement is for tight spreads and reliable execution on metals - ECN or RAW-spread accounts are the right call. Slippage tolerance of 10 points is already in the input, but tight spreads keep the spread-override safety from triggering unnecessarily. The pattern signals are computed once per closed bar, so a low-latency VPS is not strictly required the way it would be for a tick-by-tick scalper.

Strategy Deep Dive

On every tick, the EA advances a static datetime next_bar_open anchor; when the wall clock crosses it, Phase 1 of the OnTick() pipeline runs CheckState() once, which in turn calls CheckPattern() (the 2-candle engulfing geometry with the 12-bar body filter and the 5-SMA trend-context filter), then CheckConfirmation() (MFI<40 for long, MFI>60 for short), then CheckCloseSignal() (the four-case MFI cross on bar 1 vs bar 2). Phases 2 and 3 of OnTick() handle open and close on the next tick after a signal is set. Phase 4 walks PositionsTotal() and time-closes any position whose BarsHold() count has reached InpDuration=10. The two native indicator handles - iMFI(37, VOLUME_TICK) and iMA(5, MODE_SMA, PRICE_CLOSE) - are created in OnInit() and released in OnDeinit(). The CTrade wrapper handles the market-order entry, the SL/TP attach, and the close retries through TryClose_EX16025; TryClosePartial_EX16025 and TryModify_EX16025 are defined but never called.

Entry Signal

Two-candle bullish or bearish engulfing pattern, with the latest candle's body exceeding the 12-bar average body, formed at the right place relative to a 5-period SMA trend filter (bullish requires the prior candle's midpoint below the SMA, bearish requires it above). MFI(37) on bar 1 must confirm the direction: below 40 for long, above 60 for short. Market order, fixed 0.10 lot, magic 22216025.

Exit Signal

Four-case MFI cross-close on bar 1 vs bar 2: long closes if MFI drops below 70 after being above 70, or below 30 after being above 30; short closes on the mirror cases. A 10-bar time stop forces close via BarsHold() regardless of signal. The static 200/200 SL and TP are always on as the broker-side backstop. No trailing, no break-even, no partial close.

Stop Loss

Fixed 200-point stop loss on every order, with a safety in PositionOpen() that substitutes the current spread for the SL level if the spread is wider than the requested SL distance - so the order is never rejected by the broker on a wide-spread minute. No per-trade volatility adjustment, no trailing, no break-even.

Take Profit

Fixed 200-point take profit on every order (1:1 risk-reward with the 200-point SL). The same spread-override safety that guards the SL also guards the TP - if the spread is wider than the TP distance, the spread itself becomes the TP level. No scaling-out, no partial close, no dynamic RR.

Best For

XAUUSD on M5 (H1 as the documented alternative) with $100 minimum deposit for a single 0.10-lot position, $500 buffer recommended for surviving a streak of 200-point stop-outs. ECN or RAW-spread account required for tight spreads on metals - the SL/TP distances are short, the strategy is pattern-driven rather than flow-driven, and the spread-override safety in PositionOpen() will fire often if spreads are wide. Trades 24/5 during symbol hours; no session filter, no daily-loss limit, no equity stop, no max-DD cap. Best deployed as a stand-alone pattern stream or as one stream in a multi-magic portfolio where each engulfing family member runs on its own magic.

Strategy Logic

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

Family: Trend Magic: 22216025 Version: 2.00

BRIEF: Engulfing pattern + MFI confirm, MA trend, time exit 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • CheckState()
  • PositionOpen()
  • CloseBySignal()
  • CloseByTime()
  • PositionExist()
  • PositionExpiredByTimeExist()
  • BarsHold()
  • Open()
  • Close()
  • Low()
  • High()
  • MidPoint()
  • ...and 10 more

INTERNAL CONSTANTS (3 total):

  • SIGNAL_BUY = 1 // Buy signal
  • SIGNAL_NOT = 0 // no trading signal
  • CLOSE_LONG = 2 // signal to close Long

INPUT PARAMETERS (11 total across 4 groups):

  • [=== Pattern Parameters ===] InpAverBodyPeriod = 12 // period for calculating average candlestick size
  • [=== Pattern Parameters ===] InpMAPeriod = 5 // Trend MA period
  • [=== Pattern Parameters ===] InpPeriodMFI = 37 // MFI period
  • [=== Pattern Parameters ===] InpVolume = VOLUME_TICK // volume type
  • [=== Trade Parameters ===] InpDuration = 10 // position holding time in bars
  • [=== Trade Parameters ===] InpSL = 200 // Stop Loss in points
  • [=== Trade Parameters ===] InpTP = 200 // Take Profit in points
  • [=== Trade Parameters ===] InpSlippage = 10 // slippage in points
  • [=== Money Management ===] InpLot = 0.1 // lot
  • [=== Identity ===] InpMagicNumber = 22216025 // Magic Number
  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_16025" // Trade comment
Pseudocode
// Pipsgrowth EX16025 Trend — Execution Flow (from source analysis)
// Family: Trend
// Engulfing pattern + MFI confirm, MA trend, time exit 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
InpAverBodyPeriod12period for calculating average candlestick size
InpMAPeriod5Trend MA period
InpPeriodMFI37MFI period
InpVolumeVOLUME_TICKvolume type
InpDuration10position holding time in bars
InpSL200Stop Loss in points
InpTP200Take Profit in points
InpSlippage10slippage in points
InpLot0.1lot
InpMagicNumber22216025Magic Number
InpTradeComment"Psgrowth.com Expert_16025"Trade comment
Source Code (.mq5)Open Source
Pipsgrowth_com_EX16025.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX16025 BullishBearish_Engulfing_MFI - Engulfing pattern + MFI confirm + MA trend filter, full 12-layer stack."
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>

#define SIGNAL_BUY    1             // Buy signal
#define SIGNAL_NOT    0             // no trading signal
#define SIGNAL_SELL  -1             // Sell signal

#define CLOSE_LONG    2             // signal to close Long
#define CLOSE_SHORT  -2             // signal to close Short

input group "=== Pattern Parameters ==="
input int  InpAverBodyPeriod=12;    // period for calculating average candlestick size
input int  InpMAPeriod      =5;     // Trend MA period
input int  InpPeriodMFI     =37;    // MFI period
input ENUM_APPLIED_VOLUME InpVolume=VOLUME_TICK;   // volume type

input group "=== Trade Parameters ==="
input uint InpDuration=10;          // position holding time in bars
input uint InpSL      =200;         // Stop Loss in points
input uint InpTP      =200;         // Take Profit in points
input uint InpSlippage=10;          // slippage in points
input group "=== Money Management ==="
input double InpLot   =0.1;         // lot
input group "=== Identity ==="
input long InpMagicNumber=22216025;   // Magic Number
input string   InpTradeComment       = "Psgrowth.com Expert_16025"; // Trade comment

//--- global variables
int    ExtAvgBodyPeriod;            // average candlestick calculation period
int    ExtSignalOpen     =0;        // Buy/Sell signal
int    ExtSignalClose    =0;        // signal to close a position
string ExtPatternInfo    ="";       // current pattern information
string ExtDirection      ="";       // position opening direction
bool   ExtPatternDetected=false;    // pattern detected
bool   ExtConfirmed      =false;    // pattern confirmed
bool   ExtCloseByTime    =true;     // requires closing by time 
bool   ExtCheckPassed    =true;     // status checking error

//---  indicator handles
int    ExtIndicatorHandle=INVALID_HANDLE;
int    ExtTrendMAHandle  =INVALID_HANDLE;

//--- service objects
CTrade      ExtTrade;
CSymbolInfo ExtSymbolInfo;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   Print("InpSL=", InpSL);
   Print("InpTP=", InpTP);
//--- set parameters for trading operations
   ExtTrade.SetDeviationInPoints(InpSlippage);    // slippage
   ExtTrade.SetExpertMagicNumber(InpMagicNumber); // Expert Advisor ID

Full source code available on download

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

Tags:ex16025trendpipsgrowthfreemt5xauusd

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