Pipsgrowth EX09020 MeanReversion
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX09020 EX9 Multi-Symbol MRBO Scalper — Auto-regime MR/BO scalper, full 12-layer stack.
Overview
Pipsgrowth EX09020 is the most ambitious member of the EX9 family: a multi-symbol scalper that runs two completely different signal stacks side-by-side and lets an in-strategy regime classifier pick which one is live. The two stacks are not blended. On every cycle the EA looks at ADX(14) and assigns the symbol to either Mean Reversion mode (when ADX is below InpADXSwitch = 18) or Breakout mode (when ADX is at or above 18). The MR stack and the BO stack then each produce their own buy/sell flags, and a third optional Liquidity Trap detector can sit on top of either regime to add its own long/short signal. The default symbol list at OnInit reads EURUSD,USDJPY,GBPUSD,EURJPY,AUDUSD, but the CSV is editable and the EA can be pinned to a single symbol by flipping EnableMultiSymbol = false.
When the regime classifier selects Mean Reversion, the entry condition requires the close to sit at or beyond the outer VWAP sigma band — InpVWAP_SigmaOuter = 2.0 standard deviations from the session VWAP — and then demand an RSI(2) recapture through the level InpRSI2_LevelLow = 10 for buys or InpRSI2_LevelHigh = 90 for sells. The VWAP itself is computed on a session-anchored basis (00:00 server time) using typical price times volume, with a 60-bar lookback for the sigma calculation. The KAMA slope-agreement filter runs on top: a long is only valid if the Kaufman Adaptive Moving Average (period 10, fast 2, slow 30) is sloping up; a short needs the slope to be down. The bar-quality filter then drops any candidate bar whose body-to-range ratio is below InpMinBodyToRange = 0.18, so dojis and pin bars with thin bodies are excluded.
When the regime classifier selects Breakout, the logic switches to a Donchian + SuperTrend + KAMA blend. A long is only fired if the close prints above the upper Donchian band (InpDonchianPeriod = 20 bars), the SuperTrend (ATR period 10, multiplier 2.0) is bullish, the KAMA slope is up, and the bar clears the body-quality filter. The optional VWAP distance limiter (InpLimitBO_VWAPDistance = true) blocks breakouts that have stretched too far from VWAP — specifically, if the z-score of the close against VWAP exceeds InpMaxVWAP_Zscore = 1.5, the breakout signal is suppressed to avoid chasing late moves. The short side is the mirror. Both MR and BO scan a small window of recent closed bars — EntrySignalsMustMatchWithinBars = 2 by default — and only fire if at least one qualifying bar appears within that window.
The Liquidity Trap layer sits orthogonal to the regime. With UseLiquidityTrap = true (default), the EA looks back InpTrapLookbackBars = 30 bars for a swing high or low that price has just swept by InpTrapSweepPts = 12 points. If the candle then closes back through that swing level by InpTrapReentryPts = 8 points and the candle wick ratio against the bar range is at least InpTrapWickRatio = 0.30, the trap fires. The trap signal is OR-ed with the regime-derived base signal, so a long trap can fire even when the regime classifier has the symbol in BO mode.
After the base signal is set, the EA requires confirmations. Four confirmation modules can be enabled: volume spike (VolumeSpikeOK, comparing current volume to a 20-bar SMA with multiplier 1.30), KAMA slope agreement (already used inside MR, repeated here as a confirmation), VWAP statistical availability (needs at least 30 valid bars and a non-zero sigma), and an optional Bollinger re-entry check using bands(20, 2.0) — that last one defaults to OFF. The user sets InpNeedConfirmationsK (default 2) and the EA fires only when the count of passing modules meets that threshold, capped at the number of modules actually enabled.
Layered on top of all of that is the safety gate IsSafeToTrade_EX09020 and the per-symbol pre-trade check CanPlaceNew. The safety gate enforces a capital cap (InpCapAmount, InpCapFloor), an initial-balance floor at InpMinEquityPercent = 95%, a daily realized-loss cap of InpDailyLossLimitPct = 3% against effective capital, a max-trades-per-day limit of 50, a market-open check (no Saturday, no Sunday before 22 GMT, no Friday after 21 GMT), a session-active check that only allows London 7-16 GMT and New York 12-21 GMT (with the Asia block 0-7 GMT respected when InpAvoidAsia = true), and an optional news-time filter that blocks entries within ±15 minutes of the London or NY open hour. CanPlaceNew adds the per-symbol state: a one-entry-per-bar gate, a per-symbol pause-until timestamp that latches on three consecutive losses (60-minute pause) or a $100 cumulative loss amount (60-minute pause), a per-symbol daily-drawdown pause of 2% that resets at the next day rollover, a dynamic spread cap computed as median + 3 * MAD over the last 200 spread samples (with an optional absolute cap), and a tick-activity floor of 18 ticks per minute.
Position management centers on ApplyDynamicLockProfitToPosition — the ratchet. Every tick the EA walks open positions, computes how many InpLockProfitEveryXPoints = 120 point steps the price has moved in the position's favor, multiplies that by the step and subtracts InpLockMinusYPointsBuffer = 18 points, and moves the stop to entry plus that distance (for longs) or entry minus that distance (for shorts). The new stop is only ever moved forward — never relaxed — and is checked against the broker's SYMBOL_TRADE_FREEZE_LEVEL before being sent. SL and TP for new entries are ATR-driven: the EA reads ATR(14) in points and multiplies by InpATR_SL_Mult_MR = 1.0 and InpATR_TP_Mult_MR = 1.8 in MR mode, or InpATR_SL_Mult_BO = 1.0 and InpATR_TP_Mult_BO = 2.4 in BO mode. The TP/SL floors in CalcSLTP are 0.8 for MR SL and 1.2 for MR TP, or 1.0 / 2.0 for BO, so the multipliers cannot be dialled down to a sub-1:1 R:R by mistake. The static fallback when InpUseATRforSLTP = false is 250 points SL and 500 points TP.
Sizing uses InpFixedLot = 0.10 — there is no per-trade risk percent in this EA. Lot normalization calls NormalizeVol which clamps to the broker's SYMBOL_VOLUME_MIN, SYMBOL_VOLUME_STEP, and SYMBOL_VOLUME_MAX. Order routing goes through SendOrder_AllFillings, which calls DetermineAllowedFillings to read the broker's SYMBOL_FILLING_MODE bitmask, then iterates preferred filling modes in the order IOC, RETURN, FOK, retrying up to 6 outer attempts with adaptive deviation starting at InpSlippagePoints = 5 and growing by 3 points per attempt up to a ceiling of InpMaxAdaptiveDeviation = 20 points, with 80ms back-off sleeps. The inner TryOrderSend_EX09020 retries 3 times on REQUOTE, TIMEOUT, PRICE_OFF, or PRICE_CHANGED with 200ms sleep. If the broker rejects the trade because of stops (INVALID_STOPS or REQUOTE with SL/TP attached), the EA retries once without stops and then post-modifies via ModifyPositionSLTP.
The utilization cap is a portfolio-level safety: UtilizationCapAllows computes usedPct = (equity - margin_free) / equity and blocks the trade if it exceeds InpUtilizationMaxPct = 50%. By default the cap only gates adds (InpGateAddsOnly = true), so the first entry per symbol is exempt. Adds are also gated by AllowOnlyProfitableAdditions = true: a second position can only be opened in a direction where every existing position in that direction is at least MinProfitPerTradeToAdd = 4.0 points in the green. The directional cooldown of InpCooldownSecondsDir = 20 seconds prevents re-firing on the same side. The maximum positions per symbol is MaxOpenTradesPerSymbol = 2 and the global cap is MaxTotalOpenTrades = 6.
The engine itself runs on a timer (EventSetTimer(1), driven by OnTimer) rather than on every tick — OnTick only pushes the tick-activity counter, updates daily counters, and applies the ratchet to open positions. The OnTester formula is n * pf / (1 + dd) with a 30-trade minimum, so a strategy needs at least 30 closed trades in the optimization window to receive a non-zero fitness and the result is a sharp ratio of net profit times profit factor divided by one plus the equity drawdown percent. The verbose diagnostic logging is off by default; flipping VerboseLogs = true lights up the LOGF macro throughout.
In a backtest, expect this EA to behave like two distinct strategies sharing one account. In low-ADX periods on the major FX pairs, the MR side will trigger from VWAP 2-sigma extremes with the KAMA slope and RSI(2) recapture acting as directional gates, with 1.0 ATR stops and 1.8 ATR targets. When a strong directional move lifts ADX above 18, the BO stack takes over with Donchian 20 breakouts confirmed by SuperTrend and a VWAP-distance cap, with 1.0 ATR stops and 2.4 ATR targets. The dynamic lock profit ratchet is what bridges the two modes — it locks in realized gains on a 120-point step cadence with an 18-point buffer, and it runs on every tick regardless of which regime is currently active, so a position opened in MR mode can have its stop ratcheted into profit while the market transitions to BO mode. Realistic runs on the default FX list will show a mix of quick 100-300 point winners (the MR hits) and longer 200-600 point runners (the BO hits), with the ratchet converting many of them into breakeven-or-better trades even when the TP is missed.
Strategy Deep Dive
OnTimer fires every 1 second and walks the parsed symbol list (CSV-driven, default 5 majors), pushing the current spread into a 200-sample per-symbol ring buffer and calling TryEntriesSymbol on each one. That function pulls ADX(14) on the first closed bar of the window and picks MR or BO. MR mode reads VWAP and its sigma, requires the close to sit at or past the 2.0-sigma outer band, and demands an RSI(2) recapture through 10/90 plus KAMA slope agreement plus a body-quality check. BO mode reads the Donchian 20 levels and a from-scratch SuperTrend (ATR-period 10, multiplier 2.0), and requires close-above-high + SuperTrend-bullish + KAMA-slope-up, all gated by the body filter and an optional VWAP z-score cap. Both modes scan a 2-bar window and OR in the optional liquidity trap. After the base signal, the EA requires 2 of 4 confirmation modules (volume spike, KAMA slope, VWAP availability, optional Bollinger re-entry) to fire within the confirmation window, gates the result on a daily ATR-percentile band, and applies the safety stack: 95% initial-equity floor, 3% daily loss cap, 50 trades/day max, market-open check, London/NY session filter with Asia avoidance, optional time-based news filter, dynamic spread cap as median+3*MAD, 18-tick-per-minute activity floor, 2% daily-DD pause, and a 60-minute consecutive-loss pause. On entry, SendOrder_AllFillings probes the broker's filling-mode mask in IOC>RETURN>FOK order, retrying 6 outer attempts with deviation ramping from 5 to 20 points, and on every tick the ratchet in ApplyDynamicLockProfitToPosition pulls the stop forward in 120-point steps with an 18-point buffer.
Auto-regime switching via ADX(14) at threshold 18: when ADX < 18 the EA is in Mean Reversion mode and looks for a close at or beyond the 2.0-sigma VWAP band combined with an RSI(2) recapture through the 10/90 level and a KAMA(10,2,30) slope agreement; when ADX >= 18 it switches to Breakout mode and fires on a close above the Donchian(20) upper band confirmed by SuperTrend(10,2.0) bullish and KAMA slope up. The optional Liquidity Trap detector (sweep of 12 points past a 30-bar swing plus 8-point re-entry close and a 30% wick ratio) is OR-ed with the regime-derived signal. A minimum of 2 confirmations from a pool of 4 modules (volume spike, KAMA slope, VWAP availability, Bollinger re-entry) must pass within a 2-bar window before the entry is sent.
The primary exit is a fixed take-profit at 1.8 ATR in MR mode and 2.4 ATR in BO mode (or 500 points static when ATR-based sizing is off); the stop-loss is a fixed 1.0 ATR in both modes. Secondary exits come from the dynamic lock-profit ratchet (ApplyDynamicLockProfitToPosition), which runs on every tick and moves the stop to entry + (steps * 120 - 18) points after each 120-point favorable move, only ever tightening, never relaxing. With CloseOnOppSignal = true, an opposite base signal on the regime layer will close the position, but that flag defaults to false so the EA relies on the ratchet + TP/SL for most exits.
Stop-loss is computed in CalcSLTP as 1.0 * ATR(14) points from entry when InpUseATRforSLTP = true, with a static fallback of 250 points when ATR is off. The SL floor of 0.8 in MR mode and 1.0 in BO mode prevents the multiplier from being dialled below a sub-pip value. After entry the dynamic lock-profit ratchet in ApplyDynamicLockProfitToPosition can move the stop forward to lock in unrealized gains, stepping in 120-point increments and subtracting an 18-point buffer, but the ratchet only tightens — it never loosens the original ATR-based stop.
Take-profit is set in CalcSLTP as 1.8 * ATR(14) points in MR mode and 2.4 * ATR(14) in BO mode when InpUseATRforSLTP is on, with floors of 1.2 and 2.0 respectively to prevent the TP from being compressed below the SL. With ATR off, the static TP is 500 points (1:2 R:R against the 250-point SL). The TP is set on the initial order send and is preserved across the dynamic lock-profit ratchet — the ratchet only modifies the SL side, not the TP. Positions that reach the dynamic lock step of 120 points of profit with the 18-point buffer will frequently close at a locked-in level well before the original TP is hit.
Best for traders running a $100+ multi-symbol portfolio on M5-H1 FX majors (the default CSV is EURUSD, USDJPY, GBPUSD, EURJPY, AUDUSD) who want a single EA that adapts between range and trend regimes without manual switching. MEDIUM risk profile suits a broker with low spreads and a 50-trade-per-day cap on a cent or standard account — a 0.10 fixed lot means a $1,000 balance is appropriate for live deployment. Trading is gated to London 7-16 GMT and New York 12-21 GMT, so the schedule is built for a European or US-time trader; the InpAvoidAsia flag defaults to true and blocks the dead Asian session. The optional time-based news filter and the daily-DD pause give this EA the runtime discipline to survive high-impact events, and the multi-symbol scan means the trader can leave it running unattended on a VPS during the active sessions.
Strategy Logic
Pipsgrowth EX09020 MeanReversion — Strategy Logic Analysis (from .mq5 source)
Family: MeanReversion
Magic: 22209020
Version: 2.00
BRIEF:
Multi-symbol MR/BO scalper with auto-regime switching between mean-reversion (VWAP sigma-bands + RSI2 + KAMA slope) and breakout (Donchian + SuperTrend + KAMA). Includes liquidity trap blend, dynamic lock profit, utilization cap, pause guards, and ECN-safe order routing with adaptive filling modes. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
Trim()SplitCSV()FindSymIndex()SymbolEnsureSelect()SymPoint()SymTickSize()NormalizePriceToTick()SymBid()SymAsk()SymbolMinVolume()SymbolVolumeStep()NormalizeVol()- ...and 58 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (94 total across 15 groups):
- [===
CORE===] EA_Prefix = "EX9" //EAname / logging prefix - [===
CORE===]MagicNumber=22209020// Magic number - [===
CORE===]InpTradeComment= "Psgrowth.com Expert_09020" // Trade comment prefix - [===
CORE===]SymbolsCSV= "EURUSD,USDJPY,GBPUSD,EURJPY,AUDUSD" // Symbol list (CSV) - [===
CORE===]InpTF= 1 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Operating timeframe - [===
CORE===]EnableMultiSymbol=true// Enable multi-symbol scanning - [===
DYNAMICLOCKPROFIT===]InpEnableDynamicLockProfit=true// Use dynamic (ratchet) lock profit - [===
DYNAMICLOCKPROFIT===]InpLockProfitEveryXPoints= 120 // Lock step size (points) - [===
DYNAMICLOCKPROFIT===]InpLockMinusYPointsBuffer= 18 // Buffer below step (points) - [===
INITIALvsADDITIONAL===]MaxOpenTradesPerSymbol= 2 // Max positions per single symbol - [===
INITIALvsADDITIONAL===]MaxTotalOpenTrades= 6 // Global max positions - [===
INITIALvsADDITIONAL===]AllowOnlyProfitableAdditions=true// Only add if current direction net profitable - [===
INITIALvsADDITIONAL===]MinProfitPerTradeToAdd=4.0// Min unrealized pts per trade for add - [===
PAUSEGUARDS===]PauseOnConsecutiveLosses=true// Enable pause after N losses - [===
PAUSEGUARDS===]PauseConsecutiveLossesCount= 3 // Loss streak threshold - [===
PAUSEGUARDS===]PauseConsecutiveLossesMinutes= 60 // Pause length (minutes) - [===
PAUSEGUARDS===]PauseOnLossAmount=true// Enable pause on loss amount - [===
PAUSEGUARDS===]PauseLossAmount=100.0// Loss amount threshold (currency) - [===
PAUSEGUARDS===]PauseLossAmountMinutes= 60 // Pause length after loss amount - [===
PAUSEGUARDS===]PauseOnDailyDrawdown=true// Pause if daily drawdown exceeded - [===
PAUSEGUARDS===]DailyDrawdownPct=2.0// Daily drawdown percent threshold - [===
PAUSEGUARDS===]ResetPauseAtNewDay=true// Reset loss pause at new day - [===
TRADE&RISK(Fixed Lot) ===]InpFixedLot=0.10// Fixed lot size - [===
TRADE&RISK(Fixed Lot) ===]InpUseATRforSLTP=true// UseATR-based SL/TP - [===
TRADE&RISK(Fixed Lot) ===]InpATRPeriod= 14 //ATRperiod - [===
TRADE&RISK(Fixed Lot) ===]InpATR_SL_Mult_MR=1.0// MR mode SLATRmultiplier - [===
TRADE&RISK(Fixed Lot) ===]InpATR_TP_Mult_MR=1.8// MR mode TPATRmultiplier - [===
TRADE&RISK(Fixed Lot) ===]InpATR_SL_Mult_BO=1.0// BO mode SLATRmultiplier - [===
TRADE&RISK(Fixed Lot) ===]InpATR_TP_Mult_BO=2.4// BO mode TPATRmultiplier - [===
TRADE&RISK(Fixed Lot) ===]InpSL_Points= 250 // Static SL points (ifATRoff) - [===
TRADE&RISK(Fixed Lot) ===]InpTP_Points= 500 // Static TP points (ifATRoff) - [===
TRADE&RISK(Fixed Lot) ===]InpSlippagePoints= 5 // Initial allowed slippage - [===
TRADE&RISK(Fixed Lot) ===]InpMaxAdaptiveDeviation= 20 // Max adaptive deviation points - [===
TRADE&RISK(Fixed Lot) ===]InpOneEntryPerBar=true// Enforce one entry per bar - [===
TRADE&RISK(Fixed Lot) ===]InpCooldownSecondsDir= 20 // Directional cooldown seconds - [===
TRADE&RISK(Fixed Lot) ===]CloseOnOppSignal=false// Close on opposite base signal - [===
UTILIZATIONCAP(Budget for Adds) ===]InpUtilBase=UTIL_EQUITY// Utilization base (equity/balance) - [===
UTILIZATIONCAP(Budget for Adds) ===]InpUtilizationMaxPct=50.0// Max margin usage percent - [===
UTILIZATIONCAP(Budget for Adds) ===]InpGateAddsOnly=true// Apply cap only to adds (iftrue) - [===
AUTOFILTERS===]InpUseDynamicSpreadCap=true// Enable dynamic spread cap - [===
AUTOFILTERS===]InpSpreadLookbackTicks= 200 // Spread sampling window (ticks) - [===
AUTOFILTERS===]InpSpreadMADMult=3.0// Spread cap multiplier (med+k*MAD) - [===
AUTOFILTERS===]InpSpreadCapAbsPoints= 0 // Absolute spread cap (0=off) - [===
AUTOFILTERS===]InpMinTicksPerMin= 18 // Min tick activity per minute (0=off) - [===
AUTOFILTERS===]InpUseBarQualityFilter=true// Use bar quality filter - [===
AUTOFILTERS===]InpMinBodyToRange=0.18// Min body/range ratio - [===
AUTOFILTERS===]InpUseATRPercentileFilter=true// DailyATRpercentile gating - [===
AUTOFILTERS===]InpATRPctlLow= 30 //ATRpercentile lower bound - [===
AUTOFILTERS===]InpATRPctlHigh= 85 //ATRpercentile upper bound - [===
AUTOFILTERS===]InpUseSessions=false// Use session time filter - [===
AUTOFILTERS===]InpSession1StartHH= 7 // Session 1 start hour - [===
AUTOFILTERS===]InpSession1EndHH= 17 // Session 1 end hour (exclusive) - [===
AUTOFILTERS===]InpSession2StartHH= 13 // Session 2 start hour - [===
AUTOFILTERS===]InpSession2EndHH= 22 // Session 2 end hour (exclusive) - [===
REGIME(Auto MR vs BO) ===]InpADXSwitch= 18 //ADXregime switch threshold - [===
REGIME(Auto MR vs BO) ===]InpADXPeriod= 14 //ADXindicator period - [===
MR(VWAP/KAMA/RSI2) ===]InpVWAP_SigmaInner=1.5//VWAPinner sigma band - [===
MR(VWAP/KAMA/RSI2) ===]InpVWAP_SigmaOuter=2.0//VWAPouter sigma band - [===
MR(VWAP/KAMA/RSI2) ===]InpVWAP_StdLookback= 60 //VWAPsigma lookback (bars) - [===
MR(VWAP/KAMA/RSI2) ===]InpKAMA_Fast= 2 //KAMAfast length - [===
MR(VWAP/KAMA/RSI2) ===]InpKAMA_Slow= 30 //KAMAslow length - [===
MR(VWAP/KAMA/RSI2) ===]InpKAMA_Period= 10 //KAMAefficiency period - [===
MR(VWAP/KAMA/RSI2) ===]InpRSI2_LevelLow= 10 //RSI2lowlevel(BUYrecapture) - [===
MR(VWAP/KAMA/RSI2) ===]InpRSI2_LevelHigh= 90 //RSI2highlevel(SELLrecapture) - [===
BO(Donchian /SuperTrend) ===]InpDonchianPeriod= 20 // Donchian breakout period - [===
BO(Donchian /SuperTrend) ===]InpST_ATR_Period= 10 //SuperTrendATRperiod - [===
BO(Donchian /SuperTrend) ===]InpST_Mult=2.0//SuperTrendATRmultiplier - [===
BO(Donchian /SuperTrend) ===]InpLimitBO_VWAPDistance=true// Limit BO byVWAPz-score - [===
BO(Donchian /SuperTrend) ===]InpMaxVWAP_Zscore=1.5// MaxVWAPdistance z-score - [=== Liquidity
Trap(optional) ===]UseLiquidityTrap=true// Enable liquidity trap blend - [=== Liquidity
Trap(optional) ===]InpTrapLookbackBars= 30 // Trap range lookback (bars) - [=== Liquidity
Trap(optional) ===]InpTrapSweepPts= 12 // Sweep buffer points - [=== Liquidity
Trap(optional) ===]InpTrapReentryPts= 8 // Re-entry buffer points - [=== Liquidity
Trap(optional) ===]InpTrapWickRatio=0.30// Min wick ratio for trap candle - [=== Signal Windows ===]
EntrySignalsMustMatchWithinBars= 2 // Entry signal window width - [=== Signal Windows ===]
ConfirmationsMustMatchWithinBars= 2 // Confirmation window width - [=== Signal Windows ===]
InpNeedConfirmationsK= 2 // Required confirmations K - [===
Confirmations(toggles + knobs) ===]UseVolumeSpike=true// Volume spike confirmation - [===
Confirmations(toggles + knobs) ===]InpVolSMAperiod= 20 // VolumeSMAperiod - [===
Confirmations(toggles + knobs) ===]InpVolSpikeMult=1.30// Volume spike multiplier - [===
Confirmations(toggles + knobs) ===]UseKAMA_SlopeAgree=true// RequireKAMAslope agreement - [===
Confirmations(toggles + knobs) ===]InpKAMA_MinSlopePts=0.0// Min slope magnitude (points) - [===
Confirmations(toggles + knobs) ===]UseVWAP_Availability=true// RequireVWAPstats availability - [===
Confirmations(toggles + knobs) ===]InpVWAP_MinBars= 30 // Min bars forVWAPvalidity - [===
Confirmations(toggles + knobs) ===]InpVWAP_MinSigma=0.0// Min sigma threshold (0=off) - [===
Confirmations(toggles + knobs) ===]UseBB_Reentry_AsConfirm=false// Bollinger re-entry confirmation - [===
Confirmations(toggles + knobs) ===]InpBB_Period= 20 // Bollinger period - [===
Confirmations(toggles + knobs) ===]InpBB_Dev=2.0// Bollinger deviations - [=== Engine & Logging ===]
UseOnTimerEngine=true// Use timer-driven entry loop - [=== Engine & Logging ===]
TimerSeconds= 1 // Timer interval seconds - [=== Engine & Logging ===]
VerboseLogs=false// Verbose diagnostic logging - [=== Engine & Logging ===]
SaveStateOnDeinit=false// Persist state on deinit - [=== Hardening:
GMTSessions & Capital Cap ===]InpDailyLossLimitPct=3.0//InpCapEnabledremoved — useInpCapAmount=0 to disable - [=== Hardening:
GMTSessions & Capital Cap ===]InpCapFloor=50.0// ==================================================================//
// Pipsgrowth EX09020 MeanReversion — Execution Flow (from source analysis)
// Family: MeanReversion
// Multi-symbol MR/BO scalper with auto-regime switching between mean-reversion (VWAP sigma-bands + RSI2 + KAMA slope) and breakout (Donchian + SuperTrend + KAMA). Includes liquidity trap blend, dynamic lock profit, utilization cap, pause guards, and ECN-safe order routing with adaptive filling modes. 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 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 |
|---|---|---|
| EA_Prefix | "EX9" | EA name / logging prefix |
| MagicNumber | 22209020 | Magic number |
| InpTradeComment | "Psgrowth.com Expert_09020" | Trade comment prefix |
| SymbolsCSV | "EURUSD,USDJPY,GBPUSD,EURJPY,AUDUSD" | Symbol list (CSV) |
| InpTF | 1 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Operating timeframe |
| EnableMultiSymbol | true | Enable multi-symbol scanning |
| InpEnableDynamicLockProfit | true | Use dynamic (ratchet) lock profit |
| InpLockProfitEveryXPoints | 120 | Lock step size (points) |
| InpLockMinusYPointsBuffer | 18 | Buffer below step (points) |
| MaxOpenTradesPerSymbol | 2 | Max positions per single symbol |
| MaxTotalOpenTrades | 6 | Global max positions |
| AllowOnlyProfitableAdditions | true | Only add if current direction net profitable |
| MinProfitPerTradeToAdd | 4.0 | Min unrealized pts per trade for add |
| PauseOnConsecutiveLosses | true | Enable pause after N losses |
| PauseConsecutiveLossesCount | 3 | Loss streak threshold |
| PauseConsecutiveLossesMinutes | 60 | Pause length (minutes) |
| PauseOnLossAmount | true | Enable pause on loss amount |
| PauseLossAmount | 100.0 | Loss amount threshold (currency) |
| PauseLossAmountMinutes | 60 | Pause length after loss amount |
| PauseOnDailyDrawdown | true | Pause if daily drawdown exceeded |
| DailyDrawdownPct | 2.0 | Daily drawdown percent threshold |
| ResetPauseAtNewDay | true | Reset loss pause at new day |
| InpFixedLot | 0.10 | Fixed lot size |
| InpUseATRforSLTP | true | Use ATR-based SL/TP |
| InpATRPeriod | 14 | ATR period |
| InpATR_SL_Mult_MR | 1.0 | MR mode SL ATR multiplier |
| InpATR_TP_Mult_MR | 1.8 | MR mode TP ATR multiplier |
| InpATR_SL_Mult_BO | 1.0 | BO mode SL ATR multiplier |
| InpATR_TP_Mult_BO | 2.4 | BO mode TP ATR multiplier |
| InpSL_Points | 250 | Static SL points (if ATR off) |
| InpTP_Points | 500 | Static TP points (if ATR off) |
| InpSlippagePoints | 5 | Initial allowed slippage |
| InpMaxAdaptiveDeviation | 20 | Max adaptive deviation points |
| InpOneEntryPerBar | true | Enforce one entry per bar |
| InpCooldownSecondsDir | 20 | Directional cooldown seconds |
| CloseOnOppSignal | false | Close on opposite base signal |
| InpUtilBase | UTIL_EQUITY | Utilization base (equity/balance) |
| InpUtilizationMaxPct | 50.0 | Max margin usage percent |
| InpGateAddsOnly | true | Apply cap only to adds (if true) |
| InpUseDynamicSpreadCap | true | Enable dynamic spread cap |
| InpSpreadLookbackTicks | 200 | Spread sampling window (ticks) |
| InpSpreadMADMult | 3.0 | Spread cap multiplier (med+k*MAD) |
| InpSpreadCapAbsPoints | 0 | Absolute spread cap (0=off) |
| InpMinTicksPerMin | 18 | Min tick activity per minute (0=off) |
| InpUseBarQualityFilter | true | Use bar quality filter |
| InpMinBodyToRange | 0.18 | Min body/range ratio |
| InpUseATRPercentileFilter | true | Daily ATR percentile gating |
| InpATRPctlLow | 30 | ATR percentile lower bound |
| InpATRPctlHigh | 85 | ATR percentile upper bound |
| InpUseSessions | false | Use session time filter |
| InpSession1StartHH | 7 | Session 1 start hour |
| InpSession1EndHH | 17 | Session 1 end hour (exclusive) |
| InpSession2StartHH | 13 | Session 2 start hour |
| InpSession2EndHH | 22 | Session 2 end hour (exclusive) |
| InpADXSwitch | 18 | ADX regime switch threshold |
| InpADXPeriod | 14 | ADX indicator period |
| InpVWAP_SigmaInner | 1.5 | VWAP inner sigma band |
| InpVWAP_SigmaOuter | 2.0 | VWAP outer sigma band |
| InpVWAP_StdLookback | 60 | VWAP sigma lookback (bars) |
| InpKAMA_Fast | 2 | KAMA fast length |
| InpKAMA_Slow | 30 | KAMA slow length |
| InpKAMA_Period | 10 | KAMA efficiency period |
| InpRSI2_LevelLow | 10 | RSI2 low level (BUY recapture) |
| InpRSI2_LevelHigh | 90 | RSI2 high level (SELL recapture) |
| InpDonchianPeriod | 20 | Donchian breakout period |
| InpST_ATR_Period | 10 | SuperTrend ATR period |
| InpST_Mult | 2.0 | SuperTrend ATR multiplier |
| InpLimitBO_VWAPDistance | true | Limit BO by VWAP z-score |
| InpMaxVWAP_Zscore | 1.5 | Max VWAP distance z-score |
| UseLiquidityTrap | true | Enable liquidity trap blend |
| InpTrapLookbackBars | 30 | Trap range lookback (bars) |
| InpTrapSweepPts | 12 | Sweep buffer points |
| InpTrapReentryPts | 8 | Re-entry buffer points |
| InpTrapWickRatio | 0.30 | Min wick ratio for trap candle |
| EntrySignalsMustMatchWithinBars | 2 | Entry signal window width |
| ConfirmationsMustMatchWithinBars | 2 | Confirmation window width |
| InpNeedConfirmationsK | 2 | Required confirmations K |
| UseVolumeSpike | true | Volume spike confirmation |
| InpVolSMAperiod | 20 | Volume SMA period |
| InpVolSpikeMult | 1.30 | Volume spike multiplier |
| UseKAMA_SlopeAgree | true | Require KAMA slope agreement |
| InpKAMA_MinSlopePts | 0.0 | Min slope magnitude (points) |
| UseVWAP_Availability | true | Require VWAP stats availability |
| InpVWAP_MinBars | 30 | Min bars for VWAP validity |
| InpVWAP_MinSigma | 0.0 | Min sigma threshold (0=off) |
| UseBB_Reentry_AsConfirm | false | Bollinger re-entry confirmation |
| InpBB_Period | 20 | Bollinger period |
| InpBB_Dev | 2.0 | Bollinger deviations |
| UseOnTimerEngine | true | Use timer-driven entry loop |
| TimerSeconds | 1 | Timer interval seconds |
| VerboseLogs | false | Verbose diagnostic logging |
| SaveStateOnDeinit | false | Persist state on deinit |
| InpDailyLossLimitPct | 3.0 | InpCapEnabled removed — use InpCapAmount=0 to disable |
| InpCapFloor | 50.0 | ==================================================================// |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX09020 EX9 Multi-Symbol MRBO Scalper — Auto-regime MR/BO scalper, full 12-layer stack."
//==================================================================//
// INPUTS //
//==================================================================//
// ---------------------------- CORE --------------------------------
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)
{
case 1: return PERIOD_M1;
case 2: return PERIOD_M5;
case 3: return PERIOD_M15;
case 4: return PERIOD_M30;
case 5: return PERIOD_H1;
case 6: return PERIOD_H4;
case 7: return PERIOD_D1;
default: return PERIOD_H1;
}
}
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_TIMEFRAMES g_InpTF = PERIOD_H1;
input group "=== CORE ==="
input string EA_Prefix = "EX9"; // EA name / logging prefix
input long MagicNumber = 22209020; // Magic number
input string InpTradeComment = "Psgrowth.com Expert_09020"; // Trade comment prefix
input string SymbolsCSV = "EURUSD,USDJPY,GBPUSD,EURJPY,AUDUSD"; // Symbol list (CSV)
input int InpTF = 1; // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Operating timeframe
input bool EnableMultiSymbol = true; // Enable multi-symbol scanning
// ------------------- DYNAMIC LOCK PROFIT (Ratchet) ----------------
ENUM_TIMEFRAMES MapTimeframeInt(int tf)
{
switch(tf)
{
case 1: return PERIOD_M1;
case 2: return PERIOD_M5;
case 3: return PERIOD_M15;
case 4: return PERIOD_M30;
case 5: return PERIOD_H1;
case 6: return PERIOD_H4;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.