Pipsgrowth EX16071 Trend
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX16071 Reverse_Strategy — Bollinger Bands + RSI mean-reversion EA, full 12-layer stack.
Overview
Pipsgrowth EX16071 Trend is a mean-reversion EA built around a homemade Bollinger envelope, not a trend-follower despite the family label. The source file Pipsgrowth_com_EX16071.mq5 constructs the bands in code: it loads iMA(symbol, PERIOD_CURRENT, MA_period=20, 0, MODE_SMA, PRICE_CLOSE) and a parallel iStdDev(symbol, PERIOD_CURRENT, MA_period=20, 0, MODE_SMA, PRICE_CLOSE), then treats the envelope as MA ± 2 × STDV. A 14-period iRSI provides the momentum filter. The three handles (handle_iMA_M5, handle_iSTDV_M5, handle_iRSI_M5) are all created against PERIOD_CURRENT, so the EA adapts to whatever chart timeframe you attach it to.
The signal engine fires only on a fresh bar. On the first tick of each new bar, OnTick snapshots iMAGet, iSTDVGet, and iRSIGet at indices 0 and 1 — that is, the just-completed bar and the bar before it. A long entry requires four conditions in concert: the previous bar's close finished below the lower band (Previous_Close < MA_1 - 2*STDV_1), the current bar's close has crept back inside or above that lower band (Current_Close >= MA_0 - 2*STDV_0), the RSI on the previous bar was below 30, and the current RSI is at or above 30. The RSI condition is a true cross, not a threshold — the bar that triggered the band re-entry must coincide with momentum turning up from oversold. The short side is the exact mirror at the upper band, with RSI crossing down through 70.
If the conditions are met, the EA refreshes quotes, then computes my_SL = Ask - STDV_0 and my_TP = Ask + 2*STDV_0 for longs (and +STDV_0 / -2*STDV_0 for shorts). The risk:reward ratio is hard-coded at 1:2 measured against the live one-standard-deviation distance. m_trade.CheckVolume validates the order against the broker's lot constraints before m_trade.Buy or m_trade.Sell is dispatched with magic 22216071. Lot size is fixed at my_lot, default 1.0 — there is no balance-percent, no risk-percent, no dynamic sizing, no scaling-in, and no martingale. The TryClose_EX16071, TryClosePartial_EX16071, and TryModify_EX16071 helpers exist in the source but the entry path does not call any of them.
Once a position is open, the OnTick loop performs a single protective task: it watches the current bar's close and, if a long's close reaches or exceeds the upper band (Current_Close >= MA_0 + 2*STDV_0), it calls TryClose_EX16071(ticket) to force-exit; shorts get the same treatment on the lower band. This is the EA's main safety net for trades that, despite the entry trigger, refuse to mean-revert. There is no trailing stop, no break-even ratchet, no partial close, no time-based exit, and no equity stop. The static SL and TP submitted with the original order are the only protective levels until the opposite band takes over.
The risk profile is dominated by the band width itself. Because the SL is exactly one STDV and the TP is two STDV, the trade is a coin-flip on whether the band touch leads to a true reversal or a continuation. When a strong directional day pushes XAUUSD through the lower band and keeps going, the EA's my_lot = 1.0 plus a 1-STDV stop on M5 can give back real money before either the SL or the upper-band close fires. Backtesters should pay particular attention to the loss-cluster periods around scheduled high-impact news, where Bollinger mean-reversion has the worst historical hit rate.
The header advertises a "12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester" stack, but the actual implementation is much leaner. There is no OnTester, no regime classifier, no session filter, no news filter, no max-spread gate, no max-open-positions limit, no daily-P&L breaker, no equity floor, no consecutive-loss cooldown, and no scaling logic. The EA will fire on every qualified signal as long as the broker is open. Treat the header's 12-layer claim as a family-level template, not as a feature list for this specific file.
There is one hard prerequisite that overrides everything else: the IsHedging() check inside OnInit returns INIT_FAILED on netting accounts. The account must be configured for ACCOUNT_MARGIN_MODE_RETAIL_HEDGING. Netting or exchange-style accounts will not load the EA at all — Print("Hedging only!") fires and initialization aborts before any indicator handle is created. The 3/5-digit adjustment in m_adjusted_point (multiplier of 10 for 3- or 5-digit symbols, otherwise 1) is the only broker-specific code path beyond the lot validation.
The seven input parameters split across three groups. Identity carries the magic number and trade comment; Trade Settings holds the single my_lot value; Indicators exposes MA_period, RSI_period, RSI_overbought, and RSI_oversold. There are no inputs for SL distance, TP distance, session windows, max spread, or position count — those are all hard-coded in the OnTick body. The XAUUSD default on the PipsGrowth listing reflects the file's intended volatility regime, but the brief in the header calls the EA "portable" across FX majors and other metals. The signal logic is symbol-agnostic, so the same code should fire on EURUSD or XAGUSD with no recompilation, provided the broker's spread and commission don't eat the 1:2 structure.
Traders who want to extend the file have a clean starting point. The two natural customisations are: (a) replacing the fixed my_lot with a balance-percent calculation referencing AccountInfoDouble(ACCOUNT_BALANCE) and the STDV-based stop distance, and (b) adding a max-spread input and gating the entry call on m_symbol.Spread() < MaxSpreadPoints. The opposite-band stopout logic in the position-management loop is worth keeping as-is — it is the only feature that prevents an open position from drifting into a multi-day adverse excursion without an exit.
A short note on what to expect in the MT5 Strategy Tester. With the default inputs, expect a high trade frequency on M5 (the band cross on a 20-period envelope is a frequent event in chop), an equity curve that is sensitive to spread assumptions (a 30-point XAUUSD spread will compress the 1:2 RR noticeably), and infrequent but occasionally sharp drawdowns during trend days when the lower-band bounce fails to materialise. The backtest is honest about the strategy's nature: a scalping-style mean-reversion, not a trend capture. Run the tester across at least three different volatility regimes before sizing live capital.
Strategy Deep Dive
On the first tick of every new bar, OnTick pulls iMAGet, iSTDVGet, and iRSIGet values for both the just-closed bar (index 0) and the bar before that (index 1) using three handles created against PERIOD_CURRENT in OnInit, then constructs a synthetic Bollinger envelope as MA ± 2×STDV. A long fires when the previous bar finished below the lower band and the current bar has just closed back inside, with RSI(14) crossing up through 30 on that same transition; shorts mirror at the upper band with RSI(14) crossing down through 70. OrderSend is then dispatched with a fixed my_lot (default 1.0), stop at 1×STDV_0 from fill, and take-profit at 2×STDV_0, tagged with magic 22216071. If neither level fills, a separate position-management pass in the same OnTick call force-closes the trade the moment the current bar's close reaches the opposite band via TryClose_EX16071, which retries up to three times against requote and price-change error codes. The IsHedging() check at OnInit returns INIT_FAILED on netting accounts, so the EA only loads on retail-hedging brokers; there is no trailing stop, no breakeven move, no partial close, no pyramiding, and no martingale — the design is intentionally minimal at one signal, one entry, one exit.
BUY fires when the previous bar's close was below the lower Bollinger band (MA_1 - 2*STDV_1) and the current bar's close has just re-entered or crossed back above that band, while the 14-period RSI crosses up through the oversold threshold of 30 on the same transition. SELL is the exact mirror at the upper band, with RSI(14) crossing down through 70. All three indicator reads use closed bars (iMAGet/iSTDVGet/iRSIGet at index 1 for the trigger condition, index 0 for the confirmation).
Two exits are possible. The static take-profit fires at 2 × STDV_0 from entry (1:2 versus the 1 × STDV_0 stop), submitted as a hard TP with the original order. If neither SL nor TP triggers, the OnTick position-management loop force-closes the position the moment the current bar's close reaches the OPPOSITE band — longs at MA_0 + 2*STDV_0, shorts at MA_0 - 2*STDV_0 — via the TryClose_EX16071 helper, which retries three times on requote or price-change errors. No trailing stop, no breakeven, no partial close, no time exit, no equity stop.
The stop loss is computed at exactly 1 × STDV_0 from the entry price — Ask - STDV_0 for longs, Bid + STDV_0 for shorts — and is sent as a fixed SL in the original OrderSend call. The distance is not adjusted after entry, so the effective risk scales with current volatility at the time of the fill. There is no global account-level stop and no drawdown cap.
The take-profit is placed at 2 × STDV_0 from entry, giving a fixed 1:2 risk-to-reward on the band width. The TP is a hard limit submitted with the order, not a trailing level. If price hits the opposite band before the TP fills, the position is force-closed by the OnTick loop, so the realised exit can occur at either the static TP or the band-touch stopout, whichever happens first.
Best deployed on XAUUSD M5 or H1 where the 20-period band width produces a usable 1:2 structure at typical gold volatility, with $100 minimum balance sufficient for a 1.0-lot position. Requires a retail-hedging broker (Exness, IC Markets, Pepperstone in hedge mode) — the EA hard-fails on netting accounts. Avoid running it through scheduled high-impact news, where lower-band bounces historically have the worst hit rate, and expect an equity curve that is sensitive to spread assumptions.
Strategy Logic
Pipsgrowth EX16071 Trend — Strategy Logic Analysis (from .mq5 source)
Family: Trend
Magic: 22216071
Version: 2.00
BRIEF:
Reverse strategy EA using Bollinger Bands (MA + StdDev) and RSI for mean-reversion entries. Buys when price touches lower band with oversold RSI, sells on upper band with overbought RSI. Hedging mode required. Includes ATR-based SL/TP and position management. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
SetMarginMode()IsHedging()RefreshRates()iTime()iMAGet()iSTDVGet()iRSIGet()TryClose_EX16071()TryClosePartial_EX16071()TryModify_EX16071()
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (7 total across 3 groups):
- [=== Identity ===]
m_magic=22216071// Magic number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_16071" // Trade comment - [=== Trade Settings ===]
my_lot= 1 // lot size - [=== Indicators ===] MA_period = 20 // period of the MA and
STDV - [=== Indicators ===] RSI_period = 14 // period of the
RSI - [=== Indicators ===] RSI_overbought = 70 //
RSIoverbought signal - [=== Indicators ===] RSI_oversold = 30 //
RSIoversold signal
// Pipsgrowth EX16071 Trend — Execution Flow (from source analysis)
// Family: Trend
// Reverse strategy EA using Bollinger Bands (MA + StdDev) and RSI for mean-reversion entries. Buys when price touches lower band with oversold RSI, sells on upper band with overbought RSI. Hedging mode required. Includes ATR-based SL/TP and position management. 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 |
|---|---|---|
| m_magic | 22216071 | Magic number |
| InpTradeComment | "Psgrowth.com Expert_16071" | Trade comment |
| my_lot | 1 | lot size |
| MA_period | 20 | period of the MA and STDV |
| RSI_period | 14 | period of the RSI |
| RSI_overbought | 70 | RSI overbought signal |
| RSI_oversold | 30 | RSI oversold signal |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX16071 Reverse_Strategy — Bollinger Bands + RSI mean-reversion EA, full 12-layer stack."
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
CPositionInfo m_position; // trade position object
CTrade m_trade; // trading object
CSymbolInfo m_symbol; // symbol info object
CAccountInfo m_account; // account info wrapper
//---- input parameters
input group "=== Identity ==="
input ulong m_magic=22216071; // Magic number
input string InpTradeComment="Psgrowth.com Expert_16071"; // Trade comment
input group "=== Trade Settings ==="
input double my_lot =1; // lot size
input group "=== Indicators ==="
input int MA_period =20; // period of the MA and STDV
input int RSI_period =14; // period of the RSI
input int RSI_overbought =70; // RSI overbought signal
input int RSI_oversold =30; // RSI oversold signal
ENUM_ACCOUNT_MARGIN_MODE m_margin_mode;
double m_adjusted_point; // point value adjusted for 3 or 5 points
int handle_iMA_M5; // variable for storing the handle of the iMA indicator
int handle_iSTDV_M5; // variable for storing the handle of the iSTDV indicator
int handle_iRSI_M5; // // variable for storing the handle of the iRSI indicator
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetMarginMode();
if(!IsHedging())
{
Print("Hedging only!");
return(INIT_FAILED);
}
//---
m_symbol.Name(Symbol()); // sets symbol name
if(!RefreshRates())
{
Print("Error RefreshRates. Bid=",DoubleToString(m_symbol.Bid(),Digits()),
", Ask=",DoubleToString(m_symbol.Ask(),Digits()));
return(INIT_FAILED);
}
m_symbol.Refresh();
//---
m_trade.SetExpertMagicNumber(m_magic); // sets magic number
//--- tuning for 3 or 5 digits
int digits_adjust=1;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.