Pipsgrowth EX16096 Trend
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX16096 DarkCloud_PiercingLine_MFI — candlestick pattern + MFI confirmation, full 12-layer stack.
Overview
Pipsgrowth EX16096 Trend is a MetaTrader 5 Expert Advisor that trades the two-day reversal patterns known as Dark Cloud Cover and Piercing Line. It does not look for breakouts, grid layering, or trend-following across dozens of indicators. The whole strategy reduces to: spot a two-bar reversal at the open of a new M5 or H1 candle, ask the MFI oscillator whether the reversal is supported by a volume-flow extreme, and then place a fixed-distance stop and target. If neither the target nor the stop hits within ten bars, the EA closes the position by force.
The pattern detection sits in the CheckPattern() function and inspects the previous two fully-closed candles. For Dark Cloud Cover — a bearish reversal — the function requires a tall white candle two bars ago (body larger than the 12-bar average), a black candle on bar 1 whose close ends inside the white candle's body, an opening on bar 1 that gaps above the previous high (a new high in the uptrend), and a MidOpenClose(2) value that sits above the close of bar 2's moving-average line, confirming the prior trend was up. The Piercing Line mirror follows the same skeleton: a tall black bar two bars ago, a tall white bar one bar ago whose close penetrates the prior body but does not exceed the prior open, an opening that gaps beneath the previous low (a new low in the downtrend), and a MidOpenClose(2) that sits below the trend MA, confirming the prior trend was down. Bar 0 is ignored — the EA only acts on closed bars so the signal cannot repaint.
The MFI (Money Flow Index) is the only confirmation filter. MFI is a volume-weighted RSI, and the EA uses it at a 37-period lookback with VOLUME_TICK as the volume source, which means the calculation runs on every tick rather than on real exchange volume — a sensible default on MT5 because real volume is unavailable for most retail FX and gold feeds. The thresholds are deliberately gentle: a buy only fires when MFI(1) sits below 40, a sell only fires when MFI(1) sits above 60. That is roughly one-fifth of the way out of the overbought/oversold zones, so most reversals still pass — the MFI gate exists to filter out the patterns that occur in the middle of an already-impulsive move where a volume extreme is unlikely.
A close-on-signal routine (CheckCloseSignal()) handles exits triggered by oscillator state. If MFI(1) drops below 70 while MFI(2) was above 70, or if MFI(1) drops below 30 while MFI(2) was above 30, the EA closes any open long. The mirror handles shorts: MFI(1) crossing above 30 from below, or crossing above 70 from below, closes shorts. These are not overbought/oversold triggers in the classical sense; they are designed to close as soon as the volume flow returns to neutral, capturing a partial mean-reversion after the reversal. A second exit path runs through CloseByTime() and forces a flat position once the holding time exceeds InpDuration = 10 bars on the working timeframe.
Risk management is the simplest part of the EA. The PositionOpen() function takes a market order at the next available price with a fixed lot of 0.1 — there is no risk-percentage calculation, no equity curve scaler, no Kelly-style sizing. Stop loss sits InpSL = 200 points behind the entry, take profit sits InpTP = 200 points in front of it. That delivers an exact 1:1 reward-to-risk ratio on every trade, which is unusual for a candlestick-pattern EA. Most candlestick traders run asymmetrical targets, so the symmetric 1:1 here is a deliberate design choice — it tells the EA to take small, frequent wins and let the stop cap the loss.
A spread-guard safety in the same PositionOpen() function prevents the EA from placing the protective stop or the target inside the spread. If the current spread is wider than 200 points, the EA replaces the SL or TP distance with the spread itself. On a 5-digit XAUUSD broker, that means the protective distance is at minimum equal to the spread — the stop will not be placed above the entry on a buy, and the target will not be placed below the entry on a sell. This guard fires with a PrintFormat log entry so you can see when the spread is forcing the layout.
The EA reads everything at the open of a new bar and then acts on a single tick per phase. The OnTick() function is split into four phases: Phase 1 calls CheckState() on the new bar and updates the global signal flags; Phase 2 fires PositionOpen() if a buy or sell signal is set and no position in that direction exists; Phase 3 calls CloseBySignal() if a close signal is set; Phase 4 calls CloseByTime() for any position that has crossed the 10-bar holding threshold. The bar-gate is implemented with a static next_bar_open variable so all the work happens once per candle, not on every tick.
The codebase is small. There are 22 functions — CheckState, PositionOpen, CloseBySignal, CloseByTime, PositionExist, PositionExpiredByTimeExist, BarsHold, Open, Close, Low, High, MidPoint, MidOpenClose, AvgBody, CheckPattern, CheckConfirmation, CheckCloseSignal, MFI, CloseAvg, plus three retry helpers. Two indicator handles are created in OnInit(): an iMFI(_Symbol, _Period, 37, VOLUME_TICK) handle and an iMA(_Symbol, _Period, 5, 0, MODE_SMA, PRICE_CLOSE) handle. Three retry helpers are defined — TryClose_EX16096, TryClosePartial_EX16096, and TryModify_EX16096 — with three retries on requote, timeout, price-off, and price-changed responses and a 200-millisecond sleep between attempts. Only TryClose_EX16096 is wired into the live close paths; the other two are present in the source as scaffolding for future use.
What this EA does not do is just as informative. There is no news filter, no session filter, no daily loss limit, no equity kill switch, no maximum drawdown hard cap, no partial close, no breakeven, no trailing stop, no scaling into winners. The exit decision rests entirely on the MFI cross or the time expiry. If you run it on a quiet weekend candle or a wide-spread market-open candle, the spread guard will keep the stop outside the spread but the signal itself will still fire. Position sizing is fixed at 0.1 lot regardless of account size, so the percentage risk per trade scales with your balance. At a $100 minimum deposit, that is effectively 1% risk per pip-clump of stop distance on XAUUSD M5; on a $10,000 account, the same 0.1 lot becomes a much smaller percentage. Pick the lot with the account in mind.
Magic 22216096 is stamped on every order. Trade comment Psgrowth.com Expert_16096 lets the EA coexist with other instances on the same symbol. The 4-phase OnTick structure means there are no surprises on the execution side — when a pattern fires, the EA tries to open exactly one position in that direction. If the open fails, no second attempt is made inside the same bar; the EA waits for the next bar's CheckState() to re-evaluate. For a backtest, expect a steady stream of 1:1 trades on the M5 timeframe, a sparser set on H1, and a long tail of bars that exit by time rather than by target or stop.
Strategy Deep Dive
A static next_bar_open variable inside OnTick() lets all the heavy lifting happen once per candle. When TimeCurrent crosses that boundary, CheckState() is invoked and runs CheckPattern() followed by CheckConfirmation(). CheckPattern() compares the body sizes of the previous two closed candles against a 12-bar average body and reads the slope of a 5-period SMA on close to decide which reversal pattern — Dark Cloud Cover or Piercing Line — has printed. CheckConfirmation() then queries the MFI(37) at bar 1 and demands MFI(1) < 40 for a buy or MFI(1) > 60 for a sell. The same CheckState() pass evaluates CheckCloseSignal(), which looks for MFI(1)/MFI(2) cross conditions at the 30 and 70 boundaries and writes a CLOSE_LONG or CLOSE_SHORT signal if the conditions are met. After the state has been resolved, Phases 2, 3, and 4 of OnTick fire one position-management action each: a market order with a 200/200-point SL/TP if a new signal exists, a close if a close signal exists, or a time-based close if BarsHold returns >= InpDuration = 10.
Entries are evaluated only at the open of a new bar. A Dark Cloud Cover requires a long white body two bars ago, a black candle one bar ago that closes inside the white body while opening above the previous high, and a MidOpenClose(2) value that sits above the 5-period SMA to confirm the prior uptrend. A Piercing Line is the mirror: long black body two bars ago, long white body one bar ago closing inside but not exceeding the prior open, opening below the previous low, and a MidOpenClose(2) below the SMA. The MFI(37) gate then requires MFI(1) < 40 to confirm a buy and MFI(1) > 60 to confirm a sell.
The EA closes on one of three triggers. First, an MFI cross: MFI(1) dropping below 70 from above 70 (or below 30 from above 30) closes longs; MFI(1) crossing above 30 from below 30, or above 70 from below 70, closes shorts. Second, a fixed take-profit at InpTP = 200 points. Third, a hard time expiry at InpDuration = 10 bars on the working timeframe, evaluated by the BarsHold() function which counts the bars between open_time and TimeCurrent().
A fixed InpSL = 200 points stop sits behind the entry. The PositionOpen() function replaces the SL distance with the current spread whenever spread >= InpSL × Point, so the stop is never placed above the entry price on a buy or below the entry on a sell. There is no breakeven, no trailing stop, and no partial close.
A fixed InpTP = 200 points target sits in front of the entry, delivering a strict 1:1 reward-to-risk ratio. As with the stop, the target distance collapses to the spread if spread >= InpTP × Point, so the target is never placed inside the spread. The EA does not trail the target or move it to break-even after entry.
Minimum recommended balance $100 on XAUUSD M5 or H1; the fixed 0.1 lot and 200-point SL means 1% balance-per-pip on a $100 account, scaling down as balance grows. Run on a low-spread ECN or raw-spread account so the 200/200 distance is not constantly collapsed by the spread guard. The strategy is meant for trending-but-exhausting sessions where reversals have a 1:1 follow-through; London and the New York morning overlap are the most productive windows on M5, while H1 produces a sparser signal stream that pairs well with patience-based position management.
Strategy Logic
Pipsgrowth EX16096 Trend — Strategy Logic Analysis (from .mq5 source)
Family: Trend
Magic: 22216096
Version: 2.00
BRIEF:
Detects Dark Cloud Cover / Piercing Line candlestick patterns, confirmed by MFI oscillator levels and trend MA, then enters with fixed 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 10 more
INTERNAL CONSTANTS (3 total):
SIGNAL_BUY= 1 // Buy signalSIGNAL_NOT= 0 // no trading signalCLOSE_LONG= 2 // signal to close Long
INPUT PARAMETERS (11 total across 4 groups):
- [=== Indicator Parameters ===]
InpAverBodyPeriod= 12 // period for calculating average candlestick size - [=== Indicator Parameters ===]
InpMAPeriod= 5 // Trend MA period - [=== Indicator Parameters ===]
InpPeriodMFI= 37 //MFIperiod - [=== Indicator 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=22216096// Magic Number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_16096" // TradeComment
// Pipsgrowth EX16096 Trend — Execution Flow (from source analysis)
// Family: Trend
// Detects Dark Cloud Cover / Piercing Line candlestick patterns, confirmed by MFI oscillator levels and trend MA, then enters with fixed 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 |
| InpMAPeriod | 5 | Trend MA period |
| 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 | 22216096 | Magic Number |
| InpTradeComment | "Psgrowth.com Expert_16096" | Trade Comment |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX16096 DarkCloud_PiercingLine_MFI — candlestick pattern + MFI confirmation, 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 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=22216096; // Magic Number
input string InpTradeComment="Psgrowth.com Expert_16096"; // 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
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.