Pipsgrowth EX09001 MeanReversion
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX09001 RSI V2 EA — RSI mean-reversion + full 12-layer stack.
Overview
Pipsgrowth EX09001 MeanReversion is a single-instrument RSI mean-reversion EA built around a deliberately conservative posture. The strategy is meant for XAUUSD on M5 or H1, and it ships from the package with InpDryRun = true — meaning it will print what it would do without sending live orders. To go live, the user explicitly sets InpDryRun to false. This is a strong design statement: the EA assumes the operator will validate the strategy on a demo or in the MT5 Strategy Tester first, and treats live trading as an opt-in.
The core idea is straightforward. On every tick, the EA computes an RSI(21) and looks for the bar where RSI has just crossed back inside the overbought or oversold band, defined by InpRSILevel (default 70, so overbought ≥ 70 and oversold ≤ 30). The crossover is checked on the closed bar (shift 1), not the forming one, so a signal cannot fire on noise. RsiSignal() returns +1 for a buy recovery (RSI2 ≤ 30, RSI1 > 30) or -1 for a sell rejection (RSI2 ≥ 70, RSI1 < 70), and stamps a confidence score based on how deep RSI was before the recovery. A 30-confidence floor is added so even shallow re-entries register; deeper dips score higher.
That raw signal is then filtered through a regime classifier. DetectRegime() reads ATR(14), ADX(14), and a 100-bar lookback of Bollinger Band width. From these it produces one of seven states: Choppy, StrongTrend, WeakTrend, Range, Compress, Expand, or Breakout. StrongTrend is identified when ADX ≥ 30 — and if it occurs alongside a compressed ATR percentile, the regime is labeled Breakout rather than StrongTrend. Compress fires when the ATR percentile is below 30 OR the current Bollinger width is below 60% of the rolling average. Expand fires when ATR percentile is ≥ 70. WeakTrend covers 20 ≤ ADX < 30. Range is the default low-volatility residual. The default of InpRequireRangeRegime = true means entries are restricted to Range, Compress, and WeakTrend — strong-trend and breakout regimes are deliberately excluded, on the assumption that a mean-reversion trade is statistically poor when the market is in a one-way move.
ConfirmEntry() then adds three more filters. The first is the HTF-EMA check (InpConfirmHTF = true by default). The EA evaluates a 50-period EMA on H1, regardless of the chart's own timeframe. Counterintuitively, the buy signal requires the H1 close to be below the H1 EMA, and the sell signal requires H1 to be above — i.e. the entry is a pullback into the trend, not a continuation. This is the classic fade-the-retracement setup, and it presupposes that the H1 trend is the dominant force that the M5 RSI has just over-extended against. If the HTF is already on the same side as the signal, the trade is skipped. The second filter is volatility sanity: if the current ATR percentile is at an extreme, the trade is blocked. The third is a hard spread ceiling: spreads above MAX_SLIPPAGE_POINTS (30 points) are rejected outright.
Risk is fixed low: 0.5% of effective capital per trade. Effective capital is the lesser of account equity and an optional hard cap (InpCapitalCapAmount); if neither is set, the full equity is used. CalcLotByRisk() converts the SL distance in price to ticks, looks up the broker's tick_value and tick_size, and rounds the lot size down to the symbol's lot step. Position sizing is therefore mechanical and broker-aware: a 2.0×ATR SL on XAUUSD at 30-pip ATR produces a different lot on a 5-digit gold broker than on a 2-digit one.
Trade management runs every tick. The full SL is 2.0×ATR, the full TP is 1.5×ATR. That produces a 0.75 R:R target — sub-1:1 by design, betting on high win rate rather than large winners. A partial-TP mechanism is layered on top: when price reaches 1.0×ATR in profit, half the position is closed at the partial-TP level. The remainder continues to the full TP. Break-even is set when price reaches +1.0×ATR in favor, moving SL to entry. An ATR-based trailing stop (TRAIL_ATR_MULT = 2.5) ratchets the SL forward, but only if the candidate is ahead of the previous SL and ahead of entry — it never loosens. If the trade is in profit but hasn't hit the partial yet, a time stop fires after MAX_BARS_IN_TRADE (240 bars — 20 hours on M5, 10 days on H1). There is also a per-day realized-loss cap of 3%, a weekly cap of 6%, and a 5-bar cooldown after three consecutive losses. The session filter is 7:00 to 20:00 broker server time, which on a typical ECN broker corresponds to the open of the European session through the close of the US session.
What this EA does NOT do: it does not scale in (InpMaxConcurrent = 1, InpMaxSymbolExp = 1, no martingale, no grid). It does not run news filters or detect broker-side server time vs. UTC drift — the 7-to-20 window is interpreted on whatever TimeCurrent() reports. The OnTester() function returns (net × profit_factor) / (1 + max-DD%), with a 30-trade minimum — this is a quiet but important detail for anyone running the Strategy Tester, because the EA will not optimize well on backtests with fewer than 30 trades per pass.
The 20-input parameter set is split into six groups (Identity, Risk & Sizing, Capital Allocation Cap, Signal & Regime, Exit / Manage, Operational). The most consequential toggles are InpDryRun (default true), InpRequireRangeRegime (default true), InpConfirmHTF (default true), and InpOppositeSignalExit (default false). Flipping the last one to true adds an early exit when the opposite RSI signal fires mid-trade — useful in strong reversals, but the trade-off is more whipsaw closes in trend days.
For backtest expectations: on XAUUSD M5, this strategy trades sparsely — one entry per bar, but a high bar rejection rate. Expect a smooth equity curve with small average winners and small-to-moderate losers, more comparable to a market-making profile than a directional trend system. On H1, the same logic fires far less often, with proportionally larger per-trade swings.
Strategy Deep Dive
Every tick, the EA classifies the market into one of seven regime states by reading ATR(14), ADX(14), and a 100-bar Bollinger Band width — Choppy, StrongTrend, WeakTrend, Range, Compress, Expand, Breakout — and rejects entries outside Range/Compress/WeakTrend. RsiSignal() then checks for a closed-bar RSI(21) cross back inside the overbought/oversold band; if the regime gate passes, ConfirmEntry() adds the H1 EMA(50) pullback filter and the spread/spread-volatility caps. The trade opens at 0.5% risk on a 2.0×ATR SL, runs to a 1.5×ATR full TP with a 50% partial close at 1.0×ATR, and ratchets the SL through break-even and a 2.5×ATR trailing stop. The 7:00–20:00 session filter, 3%/6% daily/weekly loss caps, and 5-bar cooldown after three losses are enforced alongside the regime and capital-floor gates. With InpDryRun = true by default, the EA prints intended orders to the log rather than sending them — flipping it to false is the only setup step required to go live.
The EA enters on a closed-bar RSI(21) cross back inside the overbought/oversold band defined by InpRSILevel (default 70/30), but only when the regime classifier — built from ATR(14) percentile, ADX(14), and Bollinger Band width — labels the market as Range, Compress, or WeakTrend. ConfirmEntry() adds an H1 EMA(50) pullback filter (price must be on the reversal side of the higher-timeframe trend) and a hard 30-point spread cap before sizing at 0.5% of effective capital. One entry per bar is enforced via a gLastEntryBar duplicate gate.
The full target is 1.5×ATR from entry — a 0.75 R:R target by design. The 50% partial-TP fires at 1.0×ATR, locking in half the position; the remainder then runs to the full TP or trails. Break-even moves the SL to entry once price reaches +1.0×ATR, and an ATR(14)×2.5 trailing stop ratchets the SL forward from there. If price stalls, a 240-bar time stop closes the trade, and the optional InpOppositeSignalExit closes the position if the opposite RSI signal fires mid-trade.
The full SL is 2.0×ATR(14) from entry, sized to a stop-out beyond the recent volatility band. Break-even logic moves SL to entry once price moves +1.0×ATR in favor, and the 2.5×ATR trailing stop ratchets the stop forward thereafter. SL distance is also the input to CalcLotByRisk(), which sizes the position so that 0.5% of effective capital is the dollar risk on the stop.
The full TP is 1.5×ATR(14) from entry, producing a deliberate 0.75 R:R target that relies on win-rate rather than payout. Half the position is closed at 1.0×ATR (partial TP) before the full TP fires, and the remainder either hits the full target or rides the 2.5×ATR trailing stop. The trailing stop inherits SL control after the full TP is missed.
Designed for XAUUSD on M5 or H1 with a $100 minimum balance and a MEDIUM risk profile — but the 0.5%-per-trade sizing and the 3% daily / 6% weekly loss caps mean a $500–$1,000 account is more realistic for meaningful run-ups. The 7:00–20:00 broker-server-hour window assumes a MetaTrader server set to EET/EEST or GMT+2/+3; if your broker is on GMT, expect the session to land on the European open through the US close. Low-spread ECN brokers (Exness, IC Markets, Pepperstone) are required — the 30-point spread cap cannot be cleared on a high-spread retail account. Best deployed as a portfolio diversifier alongside a trending strategy: this EA is built to grind out small winners when the market is ranging.
Strategy Logic
Pipsgrowth EX09001 MeanReversion — Strategy Logic Analysis (from .mq5 source)
Family: MeanReversion
Magic: 22209001
Version: 2.00
BRIEF:
RSI mean-reversion — RSI cross of overbought/oversold threshold on closed bar. 12 layers: REGIME (ADX/ATR-pct/BB-wid gate, only Range/Compress/WeakTrend), SIGNAL, ENTRY, CONFIRM (HTF-EMA + RSI), NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE (BE + partial TP + ATR trail), EXIT, SCALING (OFF), OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
DetectRegime()Percentile()AverageBBWidth()RegimeName()RsiSignal()ConfirmEntry()CanTrade()CalcLotByRisk()NormalizeVolume()SendOrder()ManageOpenPositions()RespectStopsLevel()- ...and 9 more
INTERNAL CONSTANTS (13 total):
ATR_PCTILE_COMPRESS= 30 // <= percentile → CompressATR_PCTILE_EXPAND= 70 // >= percentile → ExpandBB_WIDTH_COMPRESS_PCT=0.6// relative to rolling avg → CompressTP_ATR_MULT=1.5// base TP at 1R*1.5TP1_ATR_MULT=1.0// partial TP at1.0*ATRPARTIAL_PCT= 50 // % of position closed atTP1BE_R_MULT=1.0// move SL to entry + 0 once +1RMAX_BARS_IN_TRADE= 240 // time-based exit (bars)RSI_LEVEL_THRESHOLD= 70 // default overbought/oversoldSESSION_START_HOUR= 7 // broker server timeMAX_SPREAD_RATIO=2.0// current/avg > this → no tradeSYMBOL_EXPOSURE_CAP_PCT=25.0// % ofeffective_capitalexposed per symbolCOOLDOWN_BARS_AFTER_LOSS= 5 // ============================INPUTS===============================//
INPUT PARAMETERS (20 total across 6 groups):
- [=== Identity ===]
InpMagic=22209001//EAmagic number (-) - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_09001" // Trade comment (-) - [=== Identity ===]
InpRSIPeriod= 21 //RSIperiod (bars) - [=== Identity ===]
InpRSILevel= 70 //RSIOB/OS threshold (0-100) - [=== Risk & Sizing ===]
InpRiskPercent=0.5// Risk per trade (% ofeffective_capital) - [=== Risk & Sizing ===]
InpDailyLossLimitPct=3.0// Daily loss limit (% ofeffective_capital) - [=== Risk & Sizing ===]
InpWeeklyLossLimitPct=6.0// Weekly loss limit (% ofeffective_capital) - [=== Risk & Sizing ===]
InpMaxConcurrent= 1 // Max concurrent positions (-) - [=== Risk & Sizing ===]
InpMaxSymbolExp= 1 // Max positions on this symbol (-) - [=== Risk & Sizing ===]
InpCooldownLosses= 3 // Consecutive losses → cooldown (-) - [=== Capital Allocation Cap ===]
InpCapitalCapAmount=0.0// Cap amount inREALMONEYequity ($) - [=== Capital Allocation Cap ===]
InpCapitalCapFloor=50.0// Floor below which entries are blocked ($) - [=== Signal & Regime ===]
InpRequireRangeRegime=true// Require Range/Compress/WeakTrendregime (-) - [=== Signal & Regime ===]
InpConfirmHTF=true// RequireHTF-EMAagreement (reversal side) (-) - [=== Signal & Regime ===]
InpConfirmVolatility=true// RequireATRnot in extreme percentile (-) - [=== Exit / Manage ===]
InpUseTrailing=true// EnableATRtrailing (-) - [=== Exit / Manage ===]
InpUseBreakEven=true// Enable break-even (-) - [=== Exit / Manage ===]
InpOppositeSignalExit=false// Close on oppositeRSIsignal (-) - [=== Operational ===]
InpDryRun=true// Dry-run (no live orders) (-) - [=== Operational ===]
InpKillSwitch=false// Kill switch (block all new trades) (-)
// Pipsgrowth EX09001 MeanReversion — Execution Flow (from source analysis)
// Family: MeanReversion
// RSI mean-reversion — RSI cross of overbought/oversold threshold on closed bar. 12 layers: REGIME (ADX/ATR-pct/BB-wid gate, only Range/Compress/WeakTrend), SIGNAL, ENTRY, CONFIRM (HTF-EMA + RSI), NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE (BE + partial TP + ATR trail), EXIT, SCALING (OFF), 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 H1 or H4 chart
- 7Set Bollinger Band period, deviation, RSI levels, and lot size
- 8Enable Allow Algo Trading and click OK
EA Parameters
| Parameter | Default | Description |
|---|---|---|
| InpMagic | 22209001 | EA magic number (-) |
| InpTradeComment | "Psgrowth.com Expert_09001" | Trade comment (-) |
| InpRSIPeriod | 21 | RSI period (bars) |
| InpRSILevel | 70 | RSI OB/OS threshold (0-100) |
| InpRiskPercent | 0.5 | Risk per trade (% of effective_capital) |
| InpDailyLossLimitPct | 3.0 | Daily loss limit (% of effective_capital) |
| InpWeeklyLossLimitPct | 6.0 | Weekly loss limit (% of effective_capital) |
| InpMaxConcurrent | 1 | Max concurrent positions (-) |
| InpMaxSymbolExp | 1 | Max positions on this symbol (-) |
| InpCooldownLosses | 3 | Consecutive losses → cooldown (-) |
| InpCapitalCapAmount | 0.0 | Cap amount in REAL MONEY equity ($) |
| InpCapitalCapFloor | 50.0 | Floor below which entries are blocked ($) |
| InpRequireRangeRegime | true | Require Range/Compress/WeakTrend regime (-) |
| InpConfirmHTF | true | Require HTF-EMA agreement (reversal side) (-) |
| InpConfirmVolatility | true | Require ATR not in extreme percentile (-) |
| InpUseTrailing | true | Enable ATR trailing (-) |
| InpUseBreakEven | true | Enable break-even (-) |
| InpOppositeSignalExit | false | Close on opposite RSI signal (-) |
| InpDryRun | true | Dry-run (no live orders) (-) |
| InpKillSwitch | false | Kill switch (block all new trades) (-) |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX09001 RSI V2 EA — RSI mean-reversion + full 12-layer stack."
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\OrderInfo.mqh>
#include <Trade\DealInfo.mqh>
//============================ CONSTANTS ============================//
#define ATR_PERIOD 14
#define ATR_PCTILE_LOOKBACK 100
#define ATR_PCTILE_COMPRESS 30 // <= percentile → Compress
#define ATR_PCTILE_EXPAND 70 // >= percentile → Expand
#define ADX_PERIOD 14
#define ADX_STRONG_TREND 30.0
#define ADX_WEAK_TREND 20.0
#define BB_PERIOD 20
#define BB_DEVIATION 2.0
#define BB_WIDTH_COMPRESS_PCT 0.6 // relative to rolling avg → Compress
#define HTF_TREND_EMA_PERIOD 50
#define HTF_TIMEFRAME PERIOD_H1
#define SL_ATR_MULT 2.0
#define TP_ATR_MULT 1.5 // base TP at 1R*1.5
#define TP1_ATR_MULT 1.0 // partial TP at 1.0 * ATR
#define PARTIAL_PCT 50 // % of position closed at TP1
#define TRAIL_ATR_MULT 2.5
#define BE_R_MULT 1.0 // move SL to entry + 0 once +1R
#define MAX_BARS_IN_TRADE 240 // time-based exit (bars)
#define MAX_SLIPPAGE_POINTS 30
#define RSI_LEVEL_THRESHOLD 70 // default overbought/oversold
#define SESSION_START_HOUR 7 // broker server time
#define SESSION_END_HOUR 20
#define NEWS_BLOCK_MINUTES 30
#define ROLLING_SPREAD_LOOKBACK 50
#define MAX_SPREAD_RATIO 2.0 // current/avg > this → no trade
#define SYMBOL_EXPOSURE_CAP_PCT 25.0 // % of effective_capital exposed per symbol
#define COOLDOWN_BARS_AFTER_LOSS 5
//============================ INPUTS ===============================//
input group "=== Identity ==="
input long InpMagic = 22209001; // EA magic number (-)
input string InpTradeComment = "Psgrowth.com Expert_09001"; // Trade comment (-)
input int InpRSIPeriod = 21; // RSI period (bars)
input int InpRSILevel = 70; // RSI OB/OS threshold (0-100)
input group "=== Risk & Sizing ==="
input double InpRiskPercent = 0.5; // Risk per trade (% of effective_capital)
input double InpDailyLossLimitPct = 3.0; // Daily loss limit (% of effective_capital)
input double InpWeeklyLossLimitPct = 6.0; // Weekly loss limit (% of effective_capital)
input int InpMaxConcurrent = 1; // Max concurrent positions (-)
input int InpMaxSymbolExp = 1; // Max positions on this symbol (-)
input int InpCooldownLosses = 3; // Consecutive losses → cooldown (-)
input group "=== Capital Allocation Cap ==="
// InpCapitalCapEnabled removed — use InpCapitalCapAmount=0 to disable // Enable capital cap (-)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 Mean Reversion strategy EAs from our library
Pipsgrowth EX09013 MeanReversion
Pipsgrowth.com EX09013 Bollinger_Bands_EA — BB mean reversion with trend filter, full 12-layer stack.
Pipsgrowth EX09009 MeanReversion
Pipsgrowth.com EX09009 HangingManHammer Stoch — candlestick reversal + Stochastic confirm, full 12-layer stack.
Pipsgrowth EX09023 MeanReversion
Pipsgrowth.com EX09023 BollingerMeanReversion — BB outer band fade, full 12-layer stack.
Community
Educational purposes only. Do NOT use with real money. Test on demo accounts only.