Pipsgrowth EX16047 Trend
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX16047 MorningEvening_StarDoji_CCI — Star-Doji pattern with CCI confirm, full 12-layer stack.
Overview
Pipsgrowth EX16047 is a bar-by-bar Japanese reversal pattern detector with a single momentum filter bolted on top. The EA scans the three most recent closed candles on every new bar and tries to match them against four classical reversal templates — Morning Star, Morning Doji, Evening Star, and Evening Doji — encoded as strict geometric inequalities in the CheckPattern() function. A Morning Star buy is logged when the candle two bars back is a large bearish body (its open-to-close move is bigger than the rolling 12-bar average body), the middle bar is a small body that gaps down against the first bar (a short spinning top whose body is under half the average body), and the most recent closed candle closes back above the midpoint of the first candle. A Morning Doji is the same recipe with the middle bar required to be a near-perfect doji (body under ten percent of the average body) and an explicit price gap between bars two and three. The two sell-side patterns — Evening Star and Evening Doji — are the mirror image. The detection branch that fires first wins, and the EA sets one of three values: SIGNAL_BUY=+1, SIGNAL_SELL=−1, or SIGNAL_NOT=0 if no pattern prints on that bar.
No pattern is acted on directly. The CheckConfirmation() pass pulls a single 37-period CCI reading off bar 1 (the just-closed bar) and gates every pattern signal through a hardcoded momentum check. A Morning pattern only becomes a real buy when CCI(1) is below −50, i.e. the market is in oversold territory and the reversal has at least a mean-reversion tailwind. An Evening pattern only becomes a real sell when CCI(1) is above +50. If the CCI filter rejects the pattern, ExtSignalOpen is overwritten to SIGNAL_NOT and the EA does nothing that bar. This two-stage filter — pattern shape first, then momentum — is what makes the strategy behave as a mean-reversion system at extremes rather than a blind pattern follower; the EA will skip a clean-looking Morning Star if the broader momentum has not pulled the oscillator into oversold.
When a signal survives both stages the OnTick function calls PositionOpen(), which sends a market order through the CTrade wrapper using InpLot=0.1 fixed lot, the broker-side InpSL=200 points stop, the broker-side InpTP=200 points target, and InpSlippage=10 points of slippage tolerance. Two safety nets are baked into PositionOpen(): if the current spread is wider than the SL distance in points, the EA substitutes the spread itself as the SL offset so the position is not opened already inside its stop; the same swap is applied to the TP side. The single-position-per-direction rule is enforced by PositionExist(SIGNAL_BUY) and PositionExist(SIGNAL_SELL) at the start of the open branch — the EA will not stack a second buy while a buy is alive, even if the pattern fires three bars in a row. A phase-based OnTick loop runs four passes per new bar: Phase 1 calls CheckState and arms the next-bar guard, Phase 2 opens positions on unfiltered signals, Phase 3 routes CCI close-cross signals into CloseBySignal, and Phase 4 runs the 10-bar time-based forced exit.
A trade can be closed by one of three mechanisms. The first is the broker hitting SL or TP at the order level. The second is the time-based exit — once a position has been open for InpDuration=10 bars CloseByTime() walks the open positions, calls TryClose_EX16047 on the ticket, and unwinds it regardless of where price sits. The third is the close-signal watcher in CheckCloseSignal(), which fires when CCI(1) crosses back through the +80 or −80 extreme bands: a long is closed on either a drop through +80 from above or a climb through −80 from below, the mirror logic for shorts. The TryClose_EX16047 retry helper is the only one of the three trailing retry functions (TryClose_EX16047, TryClosePartial_EX16047, TryModify_EX16047) that is wired into the live close path; the partial-close and modify helpers sit at the bottom of the file unused.
The header advertises a 12-layer stack — REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester — and the on-disk source backs up six of those: SIGNAL (the four candlestick patterns), CONFIRM (CCI gate), NO-TRADE (new-bar guard plus single-position rule), RISK+SIZING (fixed lot), ENTRY (market order with SL/TP), and EXIT (SL/TP at broker plus the 10-bar time stop). What is absent is just as defining as what is present: there is no regime filter, no H1 or higher timeframe trend gate, no equity stop, no daily loss limit, no drawdown cap, no trailing stop, no break-even ratchet, no partial close, and no OnTester pass — meaning the optimization surface in the MetaEditor strategy tester is whatever the MT5 default is. Capital protection lives entirely inside the 200-point stop, the 10-bar time stop, and the single-position discipline.
In backtest this is a high-trade-frequency mean-reversion EA on M5 XAUUSD — a typical pattern window produces several Morning/Evening Doji or Star matches per week on liquid gold sessions, and the 1:1 reward-to-risk ratio plus the 10-bar hard exit means most weeks have a healthy mix of full wins, full losses, and timed-out scratch trades. Position size is locked at 0.1 lots, so a 200-point stop on XAUUSD at typical broker point sizes is roughly two dollars per ounce of risk per trade. For a $1,000 account that is about a 2% risk per trade before any spread widening or slippage, which is why the EA is rated MEDIUM rather than LOW. Traders who want compounding should look at the in-pattern money management input or wrap this EA inside a separate lot-scaling layer; on its own EX16047 will not pyramid or re-enter.
Strategy Deep Dive
On every tick the EA waits for a fresh bar using a static next_bar_open datetime guard, then runs a four-stage phase loop: CheckState walks the four pattern branches in CheckPattern(), pulls the latest CCI(37) reading through the single iCCI indicator handle, and either promotes the pattern to confirmed or zeros ExtSignalOpen. Phase two opens the position through ExtTrade.Buy or ExtTrade.Sell with the fixed 0.1 lot, the 200-point broker-side SL and TP, and the configured slippage, but only if PositionExist() confirms no position in that direction is already open. Phase three routes a CCI cross through ±80 from CheckCloseSignal into CloseBySignal, which calls TryClose_EX16047 to retry the close three times on requotes, timeouts, or price changes. Phase four is the 10-bar hard exit — CloseByTime walks open positions and force-closes any whose age has crossed InpDuration, and beyond those three mechanisms the EA does no in-trade management, no trailing, no break-even, and no scaling.
The EA scans every new closed bar for one of four classical 3-bar Japanese reversal patterns — Morning Star, Morning Doji, Evening Star, or Evening Doji — defined as strict geometric inequalities between the three most recent candle bodies in CheckPattern(). A pattern that matches shape alone is then gated by a single 37-period CCI confirmation in CheckConfirmation(): Morning patterns only become real buys when CCI(1) is below −50, Evening patterns only become real sells when CCI(1) is above +50. A single position per direction is the hard rule — PositionExist() blocks stacking a second buy or sell while one is open.
Trades close through one of three mechanisms: the broker hitting the InpSL stop or InpTP target, the InpDuration=10-bar time-based forced exit in CloseByTime(), or an opposite-direction CCI cross through ±80 detected by CheckCloseSignal(). A long is closed when CCI(1) drops through +80 from above or climbs through −80 from below, with the mirror for shorts. The only retry helper wired into the close path is TryClose_EX16047 (3 attempts on requote/timeout/price change), while TryClosePartial_EX16047 and TryModify_EX16047 sit at the bottom of the file as dead code.
Stop loss is the fixed InpSL=200 points submitted to the broker with the order, with a spread-aware fallback in PositionOpen(): if the current spread is wider than the SL distance, the EA substitutes the spread itself as the SL offset to prevent the trade from being opened already inside its stop. There is no trailing stop, no break-even ratchet, and no equity or drawdown cap above this level.
Take profit is the fixed InpTP=200 points, producing a 1:1 reward-to-risk ratio when paired with the default 200-point stop, with the same spread-fallback that swaps the spread in for the TP distance when the market is too wide. The InpDuration=10-bar time-based hard exit in CloseByTime() is the more common closure than TP on this RR profile — many winners are scratched flat at the 10-bar deadline before the target is reached.
XAUUSD on M5 (or H1 for slower signals), $100 minimum deposit, MEDIUM risk tolerance — the 0.1-lot fixed sizing plus the 200-point stop on gold puts about 2% of a $1,000 account at risk per trade. The pattern logic is bar-shape dependent and the CCI(37) read is over the same chart timeframe, so the EA works on any standard or ECN broker with reliable OHLC data; no RAW-spread account is required but a low-spread feed helps because PositionOpen's spread-fallback will shrink the SL when spreads widen. Best run during London and New York sessions where the reversal patterns at swing opens tend to print with clean bodies; overnight Asian ranges occasionally fire the patterns with weaker follow-through, so most traders enable from the London open through the New York close and disable over the weekend.
Strategy Logic
Pipsgrowth EX16047 Trend — Strategy Logic Analysis (from .mq5 source)
Family: Trend
Magic: 22216047
Version: 2.00
BRIEF:
Morning/Evening Star-Doji pattern EA confirmed by CCI indicator. Detects candlestick patterns, confirms with CCI, 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 ===]
InpPeriodCCI= 37 //CCIperiod - [=== Indicator Settings ===]
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=22216047// Magic Number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_16047" // TradeComment
// Pipsgrowth EX16047 Trend — Execution Flow (from source analysis)
// Family: Trend
// Morning/Evening Star-Doji pattern EA confirmed by CCI indicator. Detects candlestick patterns, confirms with CCI, 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 |
| InpPeriodCCI | 37 | CCI 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 | 22216047 | Magic Number |
| InpTradeComment | "Psgrowth.com Expert_16047" | Trade Comment |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX16047 MorningEvening_StarDoji_CCI — Star-Doji pattern with CCI 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
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 "=== Indicator Settings ==="
input int InpAverBodyPeriod=12; // period for calculating average candlestick size
input int InpPeriodCCI =37; // CCI period
input int InpPrice = 1; // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // price type
//--- trade parameters
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
//--- money management parameters
ENUM_APPLIED_PRICE MapAppliedPriceInt(int 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.