Pipsgrowth EX17001 Volatility
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX17001 Volatility Navigator EA — BB extreme + RSI extreme mean-reversion, full 12-layer stack.
Overview
Pipsgrowth EX17001 Volatility Navigator is a mean-reversion EA built around the idea that sharp pushes beyond a 20-period Bollinger Band (2.0 standard deviation) rarely extend further when the 14-period RSI is simultaneously stretched. The strategy is delivered as a single-direction trade: a long fires when the last fully-closed candle closed below the lower Bollinger Band while RSI(14) printed under the 30 oversold threshold, and a short fires on the mirror setup — close above the upper band with RSI(14) above 70. The decision is anchored on the closed bar (shift = 1), so live ticks never re-arm an entry that has already printed. The 12-layer scaffold that wraps the signal consists of REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, and OnTester — each implemented as a separate function in the source so a reviewer can audit any layer in isolation.
The regime gate is the part that defines this EA's character. DetectRegime() builds ATR and Bollinger-width percentile ranks over a 50-bar lookback and reads ADX(14) at the current bar, then returns one of seven states: STRONGTREND, WEAKTREND, RANGE, BREAKOUT, COMPRESS, EXPAND, or CHOPPY. The mean-reversion entry is only allowed when the regime is RANGE, COMPRESS, or WEAKTREND — regimes where stretched oscillators tend to snap back. STRONGTREND and CHOPPY are explicitly rejected by NoTradeReason() before the signal is even read, and a secondary ADX hard-cap (InpRegimeADXMax = 35) blocks entry when directional strength becomes hostile to mean-reversion. The HTF confirm (a 50-period EMA on a higher timeframe, default H1) only has to agree with the signal direction to be marked true; if it disagrees, the confirm fails and the trade is dropped — that is why a long on M5 against a clean H1 downtrend will not fire.
Risk is sized off the effective capital. EffectiveCapital() returns the account equity but floors it at InpCapitalCapAmount if a positive cap is configured, and entry is blocked entirely when equity falls below InpCapitalCapFloor (50 dollars). InpRiskPercent defaults to 0.5 percent of effective capital per trade. The stop distance is ATR(14) multiplied by InpATRMultiplier (default 1.5), and the take-profit is the same distance multiplied by InpRR (default 2.0) — a 1:2 reward-to-risk structure. Lot size is computed in CalcLots() using the symbol's tick value and tick size so that a 0.5 percent risk per trade corresponds to a stop at exactly ATR×1.5 on XAUUSD. The size is then rounded to the broker's lot step and clamped between the symbol's lot min and lot max. Two real-money loss caps sit on top of this sizing: a 3 percent daily loss limit and a 6 percent weekly loss limit, both checked from realized PnL since midnight and Monday 00:00 server time respectively, and both feed the NoTradeReason() gate.
The management layer is the part that tends to do most of the work in live conditions. ManagePosition() runs on every tick, not just on new bars. It tracks the position's R-multiple — current price distance from entry divided by the original stop distance — and applies four distinct protections in sequence. The first is a momentum-decay exit: if the trade goes against the position by 0.5R or more, the position is closed immediately. The second is a break-even move: once the trade reaches InpBETriggerR (default 1.0R), the stop is ratcheted to entry + 0.10 × ATR, locking in scratch-plus. The third is an ATR trailing stop that activates at 0.80R and trails at 2.0 × ATR behind the bid/ask. The fourth is a partial take-profit: at 1.0R, 50 percent of the position is closed, leaving half the size to run under the trailing stop. All four moves respect the symbol's SYMBOL_TRADE_STOPS_LEVEL and use TryModify_EX17001 / TryClosePartial_EX17001, each a 3-retry scaffold that sleeps 200ms on requotes or price-changed returns. A hard time stop closes any trade older than 240 bars in the same function.
The confirm and no-trade stack adds a session window and spread cap. ConfirmFilters() reads the server hour and only passes between hour 7 and hour 20 (London to New York close) by default — the code defines DEF_SESSION_START_HR and DEF_SESSION_END_HR as tunable constants but leaves the inputs unexposed, so the session is hard-coded unless a developer recycles the source. The spread gate is configurable: InpMaxSpreadPoints defaults to 30 points and is also fed into the trade request's deviation parameter. A weekend gate blocks entries on Saturday, Sunday, and on Friday after 21:00 server time. A 12-bar cooldown is triggered after any closed losing deal — its bar timestamp is recorded in g_lastLossBarT and checked on every new-bar attempt via iBarShift. The InpDryRun input defaults to true, which means new installs will only print [DRYRUN] log lines until the operator explicitly flips it.
OnTester is the optimization objective: it returns (STAT_PROFIT × STAT_PROFIT_FACTOR) / (1 + STAT_BALANCE_DD), only after at least 30 trades. This multiplies raw profit and profit factor and divides by drawdown — a strategy that has a high profit factor and modest drawdown scores well, while a high-profit but high-DD combination gets penalized. Magic 22217001, comment Psgrowth.com Expert_17001. The five indicator handles (RSI, BB, ATR, ADX, EMA-HTF) are released in OnDeinit.
This EA works best on XAUUSD M5 where the ATR provides enough room to avoid the minimum-stop rejection and the Bollinger extremes are frequent enough to trade. M15 and H1 work as well, but the cadence drops sharply. Because the strategy is a pure mean-reversion, it should be paired with an ECN or low-spread account — the 30-point spread cap is the boundary. Do not run it during NFP, FOMC, or rate-decision events; the regime filter cannot react fast enough to a volatility expansion. Backtesting in the Strategy Tester should use 'Every tick based on real ticks' with a quality of 99 percent data to capture the spread behavior accurately. The capital-cap input should be set to roughly twice the planned max drawdown — that prevents the EA from over-sizing after a winning streak.
Strategy Deep Dive
On every tick the EA refreshes symbol rates, scans for a new closed bar, and then asks DetectRegime() to classify the current state from the 50-bar ATR and Bollinger-width percentiles plus the 14-period ADX. Only RANGE, COMPRESS, and WEAKTREND regimes proceed; STRONGTREND and CHOPPY are blocked at the NoTradeReason gate. If a valid regime is found, CoreSignal() reads the last closed bar's close, the BB(20, 2.0) upper/lower bands, and the 14-period RSI — a long prints when the close is below the lower band and RSI is under 30, a short when the close is above the upper band and RSI is over 70, with a confidence score weighted by how far the bar traveled past the band. ConfirmFilters() then checks four conditions: the 50-EMA on the higher timeframe (default H1) must agree with direction, the server hour must be inside 7-20, the spread must be at or below 30 points, and the implied R-multiple must reach 1.0. If all four pass, CalcLots() sizes the trade to risk 0.5 percent of effective capital against an ATR(14) × 1.5 stop, and SendOrder() submits it. While the trade is open, ManagePosition() handles the trailing, break-even, partial, momentum-decay, and time-based exits. Two realized-PnL gates — 3 percent daily and 6 percent weekly — stop fresh entries when triggered.
Long entry fires when the last fully-closed bar's close is below the lower Bollinger Band (20, 2.0) and the 14-period RSI is below the oversold threshold of 30. Short entry is the mirror: close above the upper band and RSI above 70. The signal is only acted on when the regime classifier returns RANGE, COMPRESS, or WEAKTREND, the current ADX is at or below 35, the higher-timeframe 50-EMA agrees with the direction, the server hour is inside 7-20, and the spread is within InpMaxSpreadPoints. New-bar detection ensures one signal per closed candle.
Exits are driven by ManagePosition() and layered: a momentum-decay exit closes the trade if it moves 0.5R against the entry; a break-even move ratchets the stop to entry + 0.10 × ATR once the trade reaches 1.0R; an ATR trailing stop activates at 0.80R and trails at 2.0 × ATR; a partial take-profit closes 50 percent of the position at 1.0R; and a hard time stop closes any trade that has been open for 240 bars or more. The InpKillSwitch flag forces a market-close on all open positions for the magic on the next tick.
Stop loss is placed at the entry price minus ATR(14) × InpATRMultiplier (default 1.5) for longs, and entry plus the same distance for shorts. The distance is recomputed on every entry using the ATR of the last closed bar. After the trade moves 1.0R in favor, ManagePosition() ratchets the stop to entry + 0.10 × ATR, locking in scratch-plus. The stop is then widened progressively by the ATR trailing arm once the trade is past 0.80R.
Take profit is set to entry plus ATR(14) × InpATRMultiplier × InpRR (defaults: 1.5 × 2.0 = 3.0 × ATR(14)) for longs, and entry minus the same distance for shorts — a 1:2 reward-to-risk structure. The position is also reduced by 50 percent via TryClosePartial_EX17001 once the trade reaches 1.0R, letting the residual half continue under the ATR trailing stop.
Minimum recommended balance: $100 (the EA will not enter below the $50 capital-cap floor). Best deployed on XAUUSD M5 on an ECN or low-spread account with sub-30-point typical spreads, because the 30-point spread gate is the binding constraint. The London-New York session window (server hours 7-20) is hard-coded into ConfirmFilters, so the broker's server clock should match GMT+0 to GMT+2 for natural alignment. Suited for traders who want a single-direction, single-position mean-reversion strategy that fades Bollinger extremes and gives back the position to a trailing stop rather than a fixed target.
Strategy Logic
Pipsgrowth EX17001 Volatility — Strategy Logic Analysis (from .mq5 source)
Family: Volatility
Magic: 22217001
Version: 2.00
BRIEF:
Closed-bar Bollinger Band extreme + RSI extreme mean- reversion (close<BBlower & RSI<oversold => LONG; close>BBupper & RSI>OB => SHORT). 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
RegimeToString()NormPrice()NormVol()NewBarFormed()EffectiveCapital()RealizedPnLToday()RealizedPnLThisWeek()MaybeResetWeeklyBaseline()CountMyPositions()CountMySymbolPositions()RespectStops()CoreSignal()- ...and 9 more
INTERNAL CONSTANTS (19 total):
DEF_RSI_PERIOD= 14 //RSIcalculation periodDEF_BB_PERIOD= 20 // Bollinger Bands periodDEF_BB_DEVIATION=2.0// Bollinger Bands deviationDEF_ATR_PERIOD= 14 //ATRperiodDEF_ATR_PCT_LOOKBACK= 50 //ATR-percentile lookback barsDEF_BBW_LOOKBACK= 50 //BB-width percentile lookback barsDEF_HTF_EMA_PERIOD= 50 //HTFEMAperiodDEF_BE_OFFSET_ATR=0.10// Lock-in offset (ATR) above BEDEF_PARTIAL_TP_R=1.0// Partial TP trigger (R multiple)DEF_PARTIAL_PCT= 50 // Partial close percentDEF_TRAIL_START_R=0.80// Trail starts after R multipleDEF_TRAIL_ATR_MULT=2.0// Trail distanceATRmultiplierDEF_MAX_BARS_IN_TRADE= 240 // Time-based exit (bars)DEF_SESSION_START_HR= 7 // London session start (server hr)DEF_SESSION_END_HR= 20 // NY close (server hr)- ...and 4 more
INPUT PARAMETERS (20 total across 6 groups):
- [=== Identity ===]
InpMagicNumber=22217001// Magic number - [=== Identity ===]
InpTradeComment= "Psgrowth.com Expert_17001" // Trade comment - [=== Identity ===]
InpDryRun=true// Dry-run mode (no live sends) - [=== Identity ===]
InpKillSwitch=false// Kill switch (halts everything) - [=== Risk & Sizing ===]
InpRiskPercent=0.5// Risk % of effective capital per trade - [=== Risk & Sizing ===]
InpDailyLossLimitPct=3.0// Daily loss limit % of effective capital - [=== Risk & Sizing ===]
InpWeeklyLossLimitPct=6.0// Weekly loss limit % of effective capital - [=== Risk & Sizing ===]
InpMaxConcurrent= 1 // Max concurrent positions - [=== Risk & Sizing ===]
InpMaxSymbolExposure= 1 // Max positions per symbol - [=== Risk & Sizing ===]
InpCooldownLossBars= 12 // Cooldown bars after consecutive losses - [=== Capital Allocation Cap ===]
InpCapitalCapAmount=0.0// Capital cap (real money $, not notional) - [=== Capital Allocation Cap ===]
InpCapitalCapFloor=50.0// Floor below which no entries occur - [=== Signal ===]
InpRSIOverbought=70.0//RSIoverbought threshold - [=== Signal ===]
InpRSIOversold=30.0//RSIoversold threshold - [=== Regime & Confirm ===]
InpRegimeADXMax=35.0// MaxADX(avoid strong trends; mean-revert) - [=== Regime & Confirm ===]
InpHTF= 8 //Timeframe(1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) //HTFtimeframe for trend confirm - [=== Regime & Confirm ===]
InpMaxSpreadPoints=30.0// Max spread (points) for entry - [=== Exit & Manage ===]
InpATRMultiplier=1.5//ATRmultiple for SL distance - [=== Exit & Manage ===]
InpRR=2.0// Reward-to-risk ratio for TP - [=== Exit & Manage ===]
InpBETriggerR=1.0// Break-even trigger (R multiple)
// Pipsgrowth EX17001 Volatility — Execution Flow (from source analysis)
// Family: Volatility
// Closed-bar Bollinger Band extreme + RSI extreme mean- reversion (close<BBlower & RSI<oversold => LONG; close>BBupper & RSI>OB => SHORT). 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 a chart matching the recommended timeframe
- 7Configure parameters according to the table on this page
- 8Enable Allow Algo Trading and click OK
EA Parameters
| Parameter | Default | Description |
|---|---|---|
| InpMagicNumber | 22217001 | Magic number |
| InpTradeComment | "Psgrowth.com Expert_17001" | Trade comment |
| InpDryRun | true | Dry-run mode (no live sends) |
| InpKillSwitch | false | Kill switch (halts everything) |
| InpRiskPercent | 0.5 | Risk % of effective capital per trade |
| InpDailyLossLimitPct | 3.0 | Daily loss limit % of effective capital |
| InpWeeklyLossLimitPct | 6.0 | Weekly loss limit % of effective capital |
| InpMaxConcurrent | 1 | Max concurrent positions |
| InpMaxSymbolExposure | 1 | Max positions per symbol |
| InpCooldownLossBars | 12 | Cooldown bars after consecutive losses |
| InpCapitalCapAmount | 0.0 | Capital cap (real money $, not notional) |
| InpCapitalCapFloor | 50.0 | Floor below which no entries occur |
| InpRSIOverbought | 70.0 | RSI overbought threshold |
| InpRSIOversold | 30.0 | RSI oversold threshold |
| InpRegimeADXMax | 35.0 | Max ADX (avoid strong trends; mean-revert) |
| InpHTF | 8 | Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // HTF timeframe for trend confirm |
| InpMaxSpreadPoints | 30.0 | Max spread (points) for entry |
| InpATRMultiplier | 1.5 | ATR multiple for SL distance |
| InpRR | 2.0 | Reward-to-risk ratio for TP |
| InpBETriggerR | 1.0 | Break-even trigger (R multiple) |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX17001 Volatility Navigator EA — BB extreme + RSI extreme 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>
//==================== REGIME ENUM ====================
enum ENUM_REGIME
{
REGIME_STRONGTREND, // 0
REGIME_WEAKTREND, // 1
REGIME_RANGE, // 2
REGIME_BREAKOUT, // 3
REGIME_COMPRESS, // 4
REGIME_EXPAND, // 5
REGIME_CHOPPY // 6
};
string RegimeToString(ENUM_REGIME r)
{
switch(r)
{
case REGIME_STRONGTREND: return "StrongTrend";
case REGIME_WEAKTREND: return "WeakTrend";
case REGIME_RANGE: return "Range";
case REGIME_BREAKOUT: return "Breakout";
case REGIME_COMPRESS: return "Compress";
case REGIME_EXPAND: return "Expand";
case REGIME_CHOPPY: return "Choppy";
}
return "Unknown";
}
//==================== TUNABLE CONSTANTS (not inputs) ====================
#define DEF_RSI_PERIOD 14 // RSI calculation period
#define DEF_BB_PERIOD 20 // Bollinger Bands period
#define DEF_BB_DEVIATION 2.0 // Bollinger Bands deviation
#define DEF_ATR_PERIOD 14 // ATR period
#define DEF_ATR_PCT_LOOKBACK 50 // ATR-percentile lookback bars
#define DEF_BBW_LOOKBACK 50 // BB-width percentile lookback bars
#define DEF_HTF_EMA_PERIOD 50 // HTF EMA period
#define DEF_BE_OFFSET_ATR 0.10 // Lock-in offset (ATR) above BE
#define DEF_PARTIAL_TP_R 1.0 // Partial TP trigger (R multiple)
#define DEF_PARTIAL_PCT 50 // Partial close percent
#define DEF_TRAIL_START_R 0.80 // Trail starts after R multiple
#define DEF_TRAIL_ATR_MULT 2.0 // Trail distance ATR multiplier
#define DEF_MOMENTUM_EXIT_R -0.50 // Momentum-decay exit (R)
#define DEF_MAX_BARS_IN_TRADE 240 // Time-based exit (bars)
#define DEF_SESSION_START_HR 7 // London session start (server hr)
#define DEF_SESSION_END_HR 20 // NY close (server hr)
#define DEF_NEWS_BLOCK_MIN 0 // Manual news window minutes (0=off)
#define DEF_SLOPE_BARS 3 // Slope/ROC bars
#define DEF_MAX_RETRIES 1 // Retry on requote/timeoutFull 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 Other strategy EAs from our library
Pipsgrowth EX01007 Adaptive
Pipsgrowth.com EX01007 Adaptive XAUUSD 5M — multi-indicator signal scorer with regime filter, full 12-layer stack, configurable timeframe, trailing/BE/profit-lock toggles, pyramid gate, spread filter, new-bar gate, filling mode detection.
Pipsgrowth EX01019 Adaptive
Pipsgrowth.com EX01019 Self-Adaptive Market EA Fixed — multi-regime adaptive EA, full 12-layer stack.
Pipsgrowth EX15029 SMC-OrderBlock
Pipsgrowth.com EX15029 SMCBreakoutEA — SMC breakout CHOCH/liquidity sweep EA, full 12-layer stack.
Community
Educational purposes only. Do NOT use with real money. Test on demo accounts only.