Pipsgrowth EX16048 Trend
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX16048 MorningEvening_StarDoji_MFI — Star-Doji pattern with MFI confirm, full 12-layer stack.
Overview
Pipsgrowth EX16048 sits at the intersection of classical Japanese reversal patterns and a single-oscillator money-flow filter. Each new bar the EA inspects the most recent three candles through CheckPattern() and looks for one of four shapes: Evening Doji, Evening Star, Morning Doji, or Morning Star. The geometry of each is identical to the textbook definition — a tall bull or bear bar (body larger than the 12-bar average body, InpAverBodyPeriod=12), a doji or near-doji in the middle (body less than 10% of the average body for Doji patterns, less than 50% for Star patterns), a price gap that flips direction, and a confirmation bar closing beyond the middle candle on the reversal side. Where the morning/evening star framework ends, the MFI takes over. The indicator handle is built in OnInit() with iMFI(_Symbol, _Period, 37, VOLUME_TICK) and stored in ExtIndicatorHandle. The 37-period MFI uses tick volume as its raw input, so the oscillator blends price movement with participation data rather than pure price deltas. A 12-bar body average is the only candle-side reference value the EA computes through AvgBody().
CheckPattern() returns the pattern and an ExtSignalOpen (SIGNAL_BUY or SIGNAL_SELL) without committing to a trade. CheckConfirmation() is the gate: it pulls MFI(1), the most recent completed bar's MFI value, and only marks ExtConfirmed=true if MFI(1) sits below 40 for a buy (oversold zone) or above 60 for a sell (overbought zone). If the pattern is detected but the MFI is on the wrong side of the threshold, the EA deliberately downgrades ExtSignalOpen to SIGNAL_NOT and skips the trade for that bar. The pattern's geometric setup is necessary but not sufficient — a Morning Doji in a tape where money is still flowing into the rally is treated as a pattern, but not a signal. The strategy is therefore a four-pattern detection engine wrapped in a single-oscillator vote, and the indicator's role is asymmetric confirmation: it doesn't have to agree with the pattern's direction, but it has to agree with the bar's exhaustion level.
The exit side mirrors the entry philosophy. When no entry signal is present, CheckCloseSignal() reads two MFI bars and watches for a cross of the 70 or 30 line from the opposite side. A long position is closed on a downward MFI cross of 70 (MFI(1)<70 AND MFI(2)>70) or an upward MFI cross of 30 (MFI(1)<30 AND MFI(2)>30). A short position closes on the mirror. These thresholds are tighter than the entry thresholds (60/40) by 10 points, which is a deliberate reinforcement — the EA exits on a less extreme oscillator move than it required for entry, so a position can close out before the oscillator fully reverts to neutral. A 10-bar time-based stop (InpDuration=10) closes any position that has neither been stopped out, taken profit, nor flipped by the MFI cross signal. BarsHold() counts completed bars since the position's open_time by reading the MqlRates history and is the only function that touches the time dimension beyond the static datetime next_bar_open guard at the top of OnTick.
Risk control on the open side is unusually defensive. PositionOpen() in EX16048 implements a spread-fallback safety net that the broker's stops would not normally offer. If the current spread, measured as ExtSymbolInfo.Ask() − ExtSymbolInfo.Bid() and expressed in points, is greater than or equal to InpSL (default 200 points) for the buy side, the EA bypasses the configured stop distance and sets the stoploss to price − spread. The same logic applies symmetrically to the take-profit side: if the spread is wider than InpTP, the TP is collapsed to a one-spread distance from the entry. The reasoning is to prevent the position from being stopped out by the spread the instant it opens on a wide market. A buy order uses ExtSymbolInfo.Ask() and a sell order uses ExtSymbolInfo.Bid(); both are NormalizeDouble'd to the symbol's digits. There is no trailing stop, no break-even logic, and no partial-close path: positions go from open to either SL, TP, MFI cross, or 10-bar time exit. The EA only ever holds one position at a time in any direction (PositionExist() is checked before every open), so there is no scaling-in or grid logic.
On the risk side, EX16048 ships with a fixed 0.1 lot (InpLot=0.1) and no percentage-of-equity or risk-per-trade calculation. Risk per trade on a 200-point stop at 0.1 lot is therefore fixed in dollar terms against whatever symbol it is attached to — on XAUUSD at typical point size this is in the single-digit-dollar range; on FX majors at the same 200 points it is roughly 20 USD per pip times the lot's per-pip value. The magic 22216048 (InpMagicNumber) and the comment string Psgrowth.com Expert_16048 (InpTradeComment) tag every ticket so the EA only ever reacts to its own positions during the close sweep in CloseBySignal() and the time sweep in CloseByTime(). Slippage tolerance is 10 points (InpSlippage), set through ExtTrade.SetDeviationInPoints() at init. There is no equity stop, no daily loss cap, and no maximum drawdown gate at the EA level; account-level protection is the responsibility of the platform.
The indicator stack is deliberately minimal. MFI is the only native handle, and its period 37 is on the slower side of the typical MFI 10-20 default, which dampens noise on M5 bars at the cost of a few more bars of confirmation lag. The 12-bar body average (InpAverBodyPeriod) for the pattern geometry is also on the slower end — most star/doji references in MQL books use 5-10 bars. The combination means the EA is conservative on both axes: it asks for a well-formed reversal pattern against a longer body baseline, and then asks the MFI to agree that the bar in question is in an exhaustion zone. Backtest expectations: this is a low-frequency, low-drawdown system. XAUUSD M5 will produce single-digit signals per week on quiet tape and a couple of clusters when volatility expands. The 1:1 risk/reward (200/200) means a 50% win rate is breakeven after spread, and the time stop will close marginal trades that drift. Run it on FX majors on H1 as a sanity check — the M5/H1 timeframe pairing in the EA's published symbol list points to FX Majors, Gold/Metals as the portable target. The 12-layer claim in the file header is aspirational: the actually-wired layers are SIGNAL (the four pattern checks), CONFIRM (MFI threshold), NO-TRADE (new-bar guard + single-position), RISK+SIZING (fixed lot), ENTRY (market order), EXIT (SL/TP/10-bar time/MFI cross). OnTester, REGIME detection, capital cap, partial-close, scaling, and trailing are declared in the header but not implemented in this build.
What to expect in a live session: the EA prints "Pattern not detected" on most new bars and only logs a signal line when a confirmation bar is also present. The trade comment makes it easy to filter the strategy's own history in the terminal's trade tab. Because PositionExist() blocks new entries while a position in that direction is open, the EA can sit in cash for long stretches. Time-based exits mean an old position cannot hold through a weekend unless the broker's rollover or expiration rules permit it; the 10-bar time stop is the upper bound on duration regardless of broker.
Strategy Deep Dive
EX16048 reads one indicator handle, iMFI(37, VOLUME_TICK), and a single 12-bar body average computed locally from the Open/Close arrays. Each new bar the static datetime next_bar_open guard fires CheckState(), which calls CheckPattern() to evaluate the four Morning/Evening Star-Doji shapes from the most recent three bars, then CheckConfirmation() to gate the signal on MFI(1) being below 40 (buy) or above 60 (sell). Phase 2 of OnTick opens the market order if ExtSignalOpen is set and no position in that direction exists; Phase 3 closes any open position when CheckCloseSignal() detects a 30/70 MFI cross from the opposite side; Phase 4 closes any position whose BarsHold() count has reached InpDuration=10. The 200/200 SL/TP are set on the open order, with a spread-fallback that collapses the SL or TP to a one-spread distance whenever the live spread is wider than the configured distance.
Detects one of four Japanese reversal patterns across the most recent three bars — Evening Doji, Evening Star, Morning Doji, or Morning Star — where the middle candle is a doji (body < 10% of the 12-bar average body) or a small body (body < 50% of average) and the third bar closes beyond the middle of the first candle. A detected pattern is only committed to a trade when MFI(1) on a 37-period MFI with tick-volume input sits below 40 (buy) or above 60 (sell); otherwise the signal is suppressed. The EA holds at most one position per direction, so a second entry in the same direction is blocked while the first is open.
Three independent exits fire in OnTick. The broker-side SL/TP at 200/200 points (1:1) is the primary exit. CheckCloseSignal() closes a long position when MFI(1) drops below 70 after MFI(2) was above 70, or when MFI(1) rises above 30 after MFI(2) was below 30; the short side mirrors this on the 30/70 cross. A 10-bar time-based stop (InpDuration) force-closes any position still open via BarsHold() reading MqlRates history between the open_time and the current time.
Each position opens with a 200-point broker-side stop loss (InpSL=200), unless the current spread is wider than 200 points in which case the EA collapses the stop to a one-spread distance from the entry (price − spread on a buy, price + spread on a sell) to avoid being stopped out by the spread itself. There is no trailing stop, no break-even, and no equity-level or daily-loss cap.
Each position opens with a 200-point broker-side take profit (InpTP=200), with the same spread-fallback safety net: if the spread is wider than 200 points, the TP is collapsed to a one-spread distance from the entry. The 200/200 default gives a fixed 1:1 risk/reward profile, with the EA's MFI cross close and 10-bar time stop acting as earlier exits when the oscillator or duration dictates.
Best run on XAUUSD M5 for the highest signal density, or on FX majors (EURUSD, GBPUSD, USDJPY) on H1 for a slower tape with the same geometry. Recommended balance is $300 or more for the fixed 0.1-lot sizing at the 200-point SL; the EA does not size to balance so sub-$300 accounts will see a higher relative risk per trade. Use a low-spread standard or ECN broker, since the spread-fallback safety net in PositionOpen() only kicks in when spread ≥ 200 points and most retail gold spreads sit well below that. The London and New York sessions provide the cleanest M5 reversal bars, but the EA does not filter by session, so it will run 24/5 if left attached.
Strategy Logic
Pipsgrowth EX16048 Trend — Strategy Logic Analysis (from .mq5 source)
Family: Trend
Magic: 22216048
Version: 2.00
BRIEF:
Morning/Evening Star-Doji pattern EA confirmed by MFI indicator. Detects candlestick patterns, confirms with MFI, opens positions with SL/TP and time-based exit. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
CheckState()PositionOpen()CloseBySignal()CloseByTime()PositionExist()PositionExpiredByTimeExist()BarsHold()Open()Close()Low()High()MidPoint()- ...and 9 more
INTERNAL CONSTANTS (3 total):
SIGNAL_BUY= 1 // Buy signalSIGNAL_NOT= 0 // no trading signalCLOSE_LONG= 2 // signal to close Long
INPUT PARAMETERS (10 total across 4 groups):
- [=== Indicator Settings ===]
InpAverBodyPeriod= 12 // period for calculating average candlestick size - [=== Indicator Settings ===]
InpPeriodMFI= 37 //MFIperiod - [=== Indicator Settings ===]
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=22216048// Magic Number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_16048" // TradeComment
// Pipsgrowth EX16048 Trend — Execution Flow (from source analysis)
// Family: Trend
// Morning/Evening Star-Doji pattern EA confirmed by MFI indicator. Detects candlestick patterns, confirms with MFI, opens positions with SL/TP and time-based 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
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 |
|---|---|---|
| InpAverBodyPeriod | 12 | period for calculating average candlestick size |
| InpPeriodMFI | 37 | MFI period |
| InpVolume | VOLUME_TICK | volume type |
| InpDuration | 10 | position holding time in bars |
| InpSL | 200 | Stop Loss in points |
| InpTP | 200 | Take Profit in points |
| InpSlippage | 10 | slippage in points |
| InpLot | 0.1 | lot |
| InpMagicNumber | 22216048 | Magic Number |
| InpTradeComment | "Psgrowth.com Expert_16048" | Trade Comment |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX16048 MorningEvening_StarDoji_MFI — Star-Doji pattern with MFI confirm, 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 parameters
input group "=== Indicator Settings ==="
input int InpAverBodyPeriod=12; // period for calculating average candlestick size
input int InpPeriodMFI =37; // MFI period
input ENUM_APPLIED_VOLUME InpVolume=VOLUME_TICK; // volume type
//--- trade parameters
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
//--- money management parameters
input group "=== Money Management ==="
input double InpLot=0.1; // lot
//--- Expert ID
input group "=== Identity ==="
input long InpMagicNumber=22216048; // Magic Number
input string InpTradeComment="Psgrowth.com Expert_16048"; // 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 handle
int ExtIndicatorHandle=INVALID_HANDLE;
//--- service objects
CTrade ExtTrade;
CSymbolInfo ExtSymbolInfo;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
Print("InpSL=", InpSL);
Print("InpTP=", InpTP);
//--- set parameters for trading operations
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.