Pipsgrowth EX16030 Trend
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX16030 BullishBearish_Harami_RSI - Harami pattern + RSI confirm + MA trend filter, full 12-layer stack.
Overview
Pipsgrowth EX16030 Trend is a 2-bar Harami continuation pattern trader that adds a Relative Strength Index confirmation gate and a 5-period simple moving average trend filter on top. The class is the inside-bar / containment branch of the BullishBearish family, paired here specifically with the iRSI(37) oscillator for confirmation. Harami — Japanese for 'pregnant' — is the geometry where the second candle's body sits fully inside the first candle's body. Where a Bullish Engulfing pattern requires the second body to swallow the first from outside, Harami is the inverted relationship: after a long, dominant candle in the prior direction, the next bar is small and the market has effectively paused or rejected the prior move inside its body. EX16030 looks for that exact stillness, then asks the RSI and the 5-SMA whether the pause is a real reversal or a one-bar pause before continuation.
The pattern detection in CheckPattern() enforces five conditions for each side. For a Bullish Harami on a downtrend: bar 1 must be bullish (Close(1) > Open(1)), bar 2 — the prior bar — must be a long bearish candle with body size larger than the 12-bar rolling average body size AvgBody(1), the bullish bar's close must be below the prior bearish bar's open, the bullish bar's open must be above the prior bearish bar's close (containment), and MidPoint(2) = (High(2)+Low(2))/2 must be below the 5-SMA CloseAvg(2) — confirming the broader trend is still down. The bearish mirror flips every comparison. That trend filter pulls wicks: a long lower wick on the prior bar softens the downtrend read even if the prior body is well above the SMA. This is the distinctive choice versus the body-midpoint MidOpenClose(2) filter used in the engulfing siblings, and it changes the actual setups that qualify.
Confirmation runs through CheckConfirmation() reading the iRSI handle at bar 1. A Bullish Harami only fires if RSI(1) < 40 — the prior momentum oscillator must still be in the lower half of its range, confirming that the prior bearish leg was strong and the inside-bar pause is a real exhaustion, not just a routine pullback inside an uptrend. A Bearish Harami only fires if RSI(1) > 60. Those 40/60 bands are deliberately inside the standard 30/70 oversold/overbought zone — they require the pattern to do most of the directional work, with RSI only validating that the prior move actually stretched the oscillator into the meaningful region. This is the same band layout the MFI confirmation uses in the Harami-MFI sibling, but RSI brings a pure price-momentum read with no volume weighting and no unbounded deviation like CCI.
Entry is a market order via ExtTrade.Buy() or ExtTrade.Sell() at the next available ask or bid, with both stop-loss and take-profit set inline. PositionOpen() builds the stop with a spread-override guard: if the current spread is wider than the configured InpSL or InpTP (in points), the EA falls back to a spread-priced exit instead of submitting an obviously-doomed order. That guard runs on both legs — a deliberate choice to keep the EA from sending the broker a position with negative expected distance to SL or TP at the moment of entry. Lot is fixed at 0.10 from InpLot. The OnInit() function routes the order object through ExtTrade.SetDeviationInPoints(InpSlippage) = 10 and SetExpertMagicNumber(22216030), so any orphan orders from a different instance or magic are ignored by the position-existence check.
Trade management follows the two-leg framework the family uses everywhere: a reversal-pattern close via CheckCloseSignal() reading RSI crosses at 70/30 (four combinations: long-overbought exit, long-oversold-plunge, short-oversold exit, short-overbought-recovery), plus a time stop via CloseByTime() checking BarsHold(open_time) >= InpDuration (10 bars). There is no trailing stop, no break-even step, and no martingale or grid layer — the EA exits either on pattern invalidation, on the 200-point SL, on the 200-point TP, or after 10 bars, whichever comes first. Every close path uses the 3-attempt TryClose_EX16030() retry wrapper, which re-submits on REQUOTE, TIMEOUT, PRICE_OFF, and PRICE_CHANGED with a 200ms backoff. TryClosePartial_EX16030() and TryModify_EX16030() are defined but never wired into the live call sites — they are residual scaffolding from the template.
The header claims a 12-layer architecture (REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester), but the actual code wires only the operational subset: REGIME via the MidPoint-vs-SMA trend filter, SIGNAL via the 5-condition Harami detection, ENTRY via market order, CONFIRM via the RSI<40 / RSI>60 band check, NO-TRADE via the next-bar-open guard in OnTick(), RISK via the 200-point SL with the spread-override guard, SIZING via the fixed 0.10 lot, EXIT via the RSI cross + 10-bar time stop + SL/TP. CAPITAL CAP is not a balance-aware risk cap; it is just a per-trade lot input. MANAGE has no trailing/BE layer. SCALING and OnTester are not present in the file. Counting only the wired layers, this is closer to a 9-layer build dressed in the family template's 12-layer jacket.
Several template-sibling defects have been carried over. MapAppliedPriceInt() is defined four times in the source (lines 37-50, 58-71, 78-91, 95-108) with the matching g_InpPrice declarations also duplicated four times — the compiler accepts the redefinition but the redundancy is wasted source. The RSI init error message on line 151 still reads 'Error creating CCI indicator' despite the actual call being iRSI — a stale string from the CCI-template sibling. The MA init on line 157 validates ExtIndicatorHandle instead of ExtTrendMAHandle, so the MA's INVALID_HANDLE is never actually caught by its own check (it is only caught by accident if the RSI handle fails first). The OnDeinit release on line 172 only frees ExtIndicatorHandle and forgets ExtTrendMAHandle — the SMA handle leaks on EA unload. The two debug Print('InpSL=', InpSL) and Print('InpTP=', InpTP) lines on 139-140 fire on every EA init. These are real code-hygiene issues, not marketing defects, and any of them is worth a one-line patch.
This is the RSI leg of the Harami + oscillator family. The MFI leg is EX16029 (with the 40/60 confirmation bands shared). EX16024 through EX16027 form the parallel engulfing + oscillator cousins (CCI, MFI, RSI, Stoch), so EX16030 is the first Harami-RSI cross and the second Harami-family variant overall. Each runs on its own magic (22216030 here) and is intended to be deployed as one independent unit — different magics, different order books, different on-chart footprints, so an operator can run several siblings on the same symbol and compare setups without position-book interference. The RSI(37) period is deliberately slow for M5: a 37-period RSI on a 5-minute chart covers roughly 3 hours of tape, which makes the oscillator slow enough that a single spike cannot invalidate the read. The 200/200 SL/TP pair is a flat 1:1 risk-reward, so the EA is essentially a higher-probability-reversal scalper with time discipline — the inside-bar geometry is the higher-probability claim, the 1:1 R:R is the math, and the 10-bar cap is the discipline that keeps losing streaks from running away.
Strategy Deep Dive
On every new M5 bar, OnTick calls CheckState, which runs CheckPattern for the 5-condition Harami containment geometry against the 12-bar average body size, with the 5-period SMA trend filter via MidPoint(2). If a pattern lands, CheckConfirmation reads iRSI(37) at bar 1 and only arms the signal if RSI < 40 (bullish) or RSI > 60 (bearish). The 5-condition Harami is the structural read, the RSI band is the momentum cross-check, the SMA is the regime gate — three independent screens must agree before the EA queues a market order. OnTick then submits a market entry on the next tick via ExtTrade.Buy / ExtTrade.Sell with both SL and TP set inline. Position management runs three exits: CheckCloseSignal on a 4-case RSI cross at 70/30, CloseByTime after BarsHold >= 10 bars, or the 200/200 SL/TP — whichever closes first, with TryClose_EX16030 retrying on transient retcodes.
Long entry on a Bullish Harami: last bar bullish, prior bar a long bearish candle with body larger than the 12-bar rolling-average body, the current bar's body fully contained inside the prior bar's body (closeprior close), and the prior bar's range midpoint sits below the 5-period SMA — only confirmed when RSI(1) < 40. Short entry is the strict mirror using a Bearish Harami, an uptrend context, and RSI(1) > 60.
Exits run on three paths: a reversal RSI cross in CheckCloseSignal (long close on RSI(1)<70 with prior RSI(2)>70, or on RSI(1)<30 with prior RSI(2)>30; short mirror), a 10-bar time stop in CloseByTime via BarsHold(), or the 200-point SL / 200-point TP whichever hits first. No trailing stop, no break-even, no martingale — the position is surrendered on whichever signal fires first.
Per-trade fixed stop of 200 points (InpSL) on every entry, with a spread-override guard in PositionOpen that falls back to a spread-priced exit if the current spread equals or exceeds the configured SL — prevents submitting orders whose distance to SL is already negative. SL is placed inline at entry; no trailing or break-even logic is wired.
Per-trade fixed take-profit of 200 points (InpTP), with the same spread-override guard applied at entry — if the current spread matches or exceeds InpTP, the TP collapses to a spread-priced exit. Combined with the equal 200-point SL, the EA targets a flat 1:1 risk-reward on every trade.
Suited to XAUUSD M5 with H1 as a higher-frame context check; minimum recommended balance $100 with $500+ for the 0.10 fixed-lot sizing to absorb the 200-point SL without margin stress. Best on a low-spread ECN or RAW-spread broker — the spread-override guard will fire on retail brokers during news windows. The 10-bar time cap and 1:1 R:R profile make it a mean-reversion scalper that needs the early-London or NY-open volatility bursts to be productive; expect flat performance during the Asian range when the inside-bar geometry rarely produces meaningful breakouts.
Strategy Logic
Pipsgrowth EX16030 Trend — Strategy Logic Analysis (from .mq5 source)
Family: Trend
Magic: 22216030
Version: 2.00
BRIEF:
Harami pattern + RSI confirm, MA trend, time 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):
- [=== Pattern Parameters ===]
InpAverBodyPeriod= 12 // period for calculating average candlestick size - [=== Pattern Parameters ===]
InpMAPeriod= 5 // Trend MA period - [=== Pattern Parameters ===]
InpPeriodRSI= 37 //RSIperiod - [=== Pattern Parameters ===]
InpPrice= 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // price 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=22216030// Magic Number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_16030" // Trade comment
// Pipsgrowth EX16030 Trend — Execution Flow (from source analysis)
// Family: Trend
// Harami pattern + RSI 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
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 |
| InpPeriodRSI | 37 | RSI period |
| InpPrice | 1 | Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // price 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 | 22216030 | Magic Number |
| InpTradeComment | "Psgrowth.com Expert_16030" | Trade comment |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX16030 BullishBearish_Harami_RSI - Harami pattern + RSI 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
ENUM_APPLIED_PRICE MapAppliedPriceInt(int ap)
{
switch(ap)
{
case 1: return PRICE_CLOSE;
case 2: return PRICE_OPEN;
case 3: return PRICE_HIGH;
case 4: return PRICE_LOW;
case 5: return PRICE_MEDIAN;
case 6: return PRICE_TYPICAL;
case 7: return PRICE_WEIGHTED;
default: return PRICE_CLOSE;
}
}
ENUM_APPLIED_PRICE g_InpPrice = PRICE_CLOSE;
input group "=== Pattern Parameters ==="
input int InpAverBodyPeriod=12; // period for calculating average candlestick size
input int InpMAPeriod =5; // Trend MA period
input int InpPeriodRSI =37; // RSI period
input int InpPrice = 1; // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // price type
ENUM_APPLIED_PRICE MapAppliedPriceInt(int ap)
{
switch(ap)
{
case 1: return PRICE_CLOSE;
case 2: return PRICE_OPEN;
case 3: return PRICE_HIGH;
case 4: return PRICE_LOW;
case 5: return PRICE_MEDIAN;
case 6: return PRICE_TYPICAL;
case 7: return PRICE_WEIGHTED;
default: return PRICE_CLOSE;
}
}
ENUM_APPLIED_PRICE g_InpPrice = PRICE_CLOSE;
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
ENUM_APPLIED_PRICE MapAppliedPriceInt(int ap)
{
switch(ap)
{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.