P
PipsGrowth
OtherOpen Source – Free

Pipsgrowth EX17017 Volatility

MT5 Expert Advisor (Open Source) · XAUUSD · M5

Pipsgrowth.com EX17017 GB1_66 — Volatility Gaussian Bands EA with adaptive breakout, full 12-layer stack.

Overview

Pipsgrowth EX17017 Volatility is a multi-filter breakout EA that drives entries off a Gaussian-smoothed midline and rejects almost everything else. The midline is a 10-period EMA of close (Length=10, MODE_EMA, PRICE_CLOSE) — a low-lag center that the source calls the 'Gaussian' filter — and around it the EA draws a band of ±0.85×ATR(14) (DistanceMultiplier=0.85). Trades fire only when price closes outside the band for the first time after two inside bars, on a candle whose body is at least 60% of the candle range. That is the only entry path: no mean-reversion to the midline, no zone-grading, no score aggregation. Everything that follows is gate logic, not signal logic, and the gates are aggressive.

The OnTick path runs as a strict priority chain. The first check is CheckMaxDrawdown() — if account equity is more than 10% below balance (MaxDrawdownPercent=10.0), every new entry is blocked and only ManagePosition() runs to babysit existing positions. Next, if RSI_Role is true (default), a 14-period RSI on close is read. The EA returns early on the tick if RSI is at or above 70, at or below 30, OR outside the neutral zone of 40-60. That neutral-zone gate is unusual: it means the EA is willing to enter only when momentum is genuinely undecided, not when RSI confirms a trend. After RSI, the Bollinger Bands gate (BB_Role=true, period 20, deviation 2.0) reads the most recent band. It returns early if the current close is closer than 50% of the band width to the middle band (BB_MiddleBandFilter=0.5) — a chop filter. With BB_UseSqueezeDetection=true (default), it also returns early if the current band width is below half of the 20-bar average band width. The squeeze is computed by GetBollingerBands(i,...) for i=1..20, summing and averaging, so a genuinely contracting volatility regime kills the setup before the breakout test even runs.

With both indicator filters passed, the EA samples ATR(14) and rejects the tick if ATR is below MinATR (0.03) or above MaxATR (0.0 means disabled). When UseAutoFilter=true (default), AutoTuneFilters() rewrites minATR, breakDistance, and bandMult using the live spread — averaging the ask/bid gap to set a pip factor (0.0001 if spread < 3 pips, else 0.01), then anchoring minATR at 3× that factor. The breakout test in CheckAndTradeBreakout() reads three closes: price, pricePrev, pricePrev2. For a buy, price must be above the upper band, both pricePrev and pricePrev2 must be below the upper band, price must be above the higher-timeframe EMA(50) on TrendFilterTF (default H4 = 6), the slope must be up (gaussNow > gaussPrev), and (price − gaussNow) must exceed MinBreakDistance × ATR (0.3 × ATR). The sell side mirrors this. strongCandle and CheckWhipsaw() must also both return true for the call to even reach that logic.

The whipsaw check is the EA's quiet workhorse. CheckWhipsaw() looks at the last WhipsawLookback bars (default 5) and runs five sub-tests. It rejects the tick if the ATR range over those bars is compressed below (1 − WhipsawThreshold) × average ATR (Threshold=0.6, so 40% compression trips it), if the flip ratio of bullish/bearish candles across the lookback is at or above 0.6, if the wick ratio (bars with wick-to-body > 1.5) is at or above 0.6, or if the absolute average net move across the lookback is below 15% of average ATR. RequireVolumeBias is an optional fifth check that counts bar-to-bar volume flips over 50% of the prior bar; it defaults off. None of these individually look severe, but chained together they filter most of the 'fake breakout' tape that follows a 5-bar consolidation.

The HTF EMA is the directional veto. The handle (emaHandle) is created from iMA(_Symbol, g_TrendFilterTF, TrendEMA, 0, MODE_EMA, PRICE_CLOSE) where TrendEMA defaults to 50. The default TrendFilterTF of 6 maps to H4, so an M5 buy requires the H4 close to be above the 50-EMA, and an M5 sell requires the H4 close to be below it. That is a slow filter — H4 50-EMA is the kind of level that re-rates over weeks, not hours. On a fast 5-minute gold chart, this single constraint will reject a meaningful fraction of valid intraday breakouts that point the wrong way on the 4-hour chart.

Risk management is layered. Each entry sends a single 0.10 lot (Lots=0.1) at the live ask/bid, with a stop at ATR_MultiplierSL × ATR (1.2 × ATR) below the ask for buys or above the bid for sells, and a take-profit at FixedTP_Points × _Point (160 points). OneTradeOnly defaults to true, so the EA holds at most one position; MaxOpenTrades is set to 5 but is effectively bypassed when OneTradeOnly is on. AllowOnlyProfitableAdditions is true and gates any second position to require MinProfitPerTradeToAdd=5.0 of unrealized profit on the existing trade first. MaxDrawdownPercent=10.0 is the hard cap, checked every tick.

ManagePosition() handles exits across three concurrent tracks. First, the GAUSSIAN-CROSS exit: if a long is open and price dips below gaussNow, or a short is open and price rises above gaussNow, the position is closed via TryClose_EX17017 (3 retries, 200ms sleep on requote/timeout/price-off). This is the primary trend-failure exit. Second, the trailing stop: UseTrailingStop=true, the new stop is bid − 1.2×ATR for buys or ask + 1.2×ATR for sells, applied only if it improves the current stop (TryModify_EX17017, 3 retries, 100ms sleep on requote/timeout). Third, the breakeven: UseBreakeven=true, the stop is moved to the entry price once bid (for buys) or ask (for sells) is more than 1.2×ATR beyond entry. Fourth, the dynamic profit lock: EnableDynamicLockProfit=true converts unrealized P&L into a step count (profit ÷ 2.0 dollars per step), then ratchets the stop to entry + (stepCount × 2.0 − 1.0) dollars / tickValue × tickSize for buys, mirrored for sells. Only forward moves are accepted. The result is a stop that climbs $1 every $2 of floating profit, never moving backward.

Practical expectations: this EA is designed for medium-volatility XAUUSD on M5 with a $100 minimum. The 5-bar whipsaw filter and RSI/BB chop filters cut the trade frequency sharply — expect one to two setups per London or New York session, often zero on quiet Asian hours. The 10% drawdown cap will halt the EA on a single bad day, and the dynamic profit lock plus the ATR trailing give back some of the open profit by the time the trade closes. Backtests will look best on quiet-trend sessions with clearly expanding ATR; sideways days will be blocked by the BB chop and squeeze filters long before the equity curve takes damage.

Strategy Deep Dive

Every tick the EA first checks the 10% equity drawdown cap, then a 14-RSI neutral-band gate (only RSI between 40-60 passes, and only outside the 70/30 OB/OS zones), then a Bollinger Bands(20, 2.0) chop and squeeze filter that blocks if the current close is closer than 50% of the band width to the middle, or if the current band width is below half the 20-bar average. ATR(14) is sampled and a Gaussian-smoothed 10-EMA midline plus ±0.85×ATR bands are drawn. CheckAndTradeBreakout() fires a buy when the current close is above the upper band, the prior two closes are below it, the slope is up, the H4 50-EMA is below price, the candle body is ≥60% of the range, the break is at least 0.3×ATR beyond the band, and the 5-bar whipsaw check (ATR compression, candle flip ratio, wick ratio, net move, optional volume bias) all pass. Sells mirror the conditions. ManagePosition() then runs four exit tracks: a Gaussian-cross close, an ATR(14)×1.2 trailing stop, a one-shot breakeven at 1.2×ATR profit, and a $1-per-$2 dynamic profit lock — all routed through 3-retry TryClose/TryModify scaffolds.

Entry Signal

Buys trigger when the current close prints above the upper Gaussian band (gaussNow + 0.85×ATR) after two consecutive inside-bar closes, on a candle with body ≥60% of the range, with H4 50-EMA below price, an up-slope, and price ≥ 0.3×ATR beyond the band — and only after the 5-bar whipsaw check, the 14-RSI neutral-zone filter, and the BB chop/squeeze filter all pass. Sells mirror the conditions downward.

Exit Signal

Exits run four parallel tracks: a Gaussian-cross close when price dips below (or rises above, for shorts) the midline, an ATR trailing stop at 1.2×ATR, a one-time breakeven move to entry once price clears 1.2×ATR, and a dynamic profit lock that ratchets the stop forward by $1 every $2 of floating profit. All order operations use 3-retry scaffolds with 200ms (close) and 100ms (modify) sleeps on requotes.

Stop Loss

Stop-loss sits at 1.2×ATR(14) below the ask for buys or above the bid for sells at entry. A global 10% drawdown cap (MaxDrawdownPercent) blocks new entries once account equity is more than 10% below balance; the EA also has a HardSL_Points=120 fallback.

Take Profit

Take-profit is a fixed 160 points from entry (FixedTP_Points × _Point), measured from the live ask for buys and bid for sells. With XAUUSD at 2-decimal pricing this is 1.60 in price; on a 5-digit FX pair it would be 16 pips.

Best For

Run on XAUUSD M5 with a $100 minimum balance; H4 50-EMA trend filter and a 5-bar whipsaw gate favor clear-session volatility, so London and New York hours will produce the cleanest setups. Use a low-spread ECN/RAW broker (≤3 pip) — the AutoTuneFilters() spread check rewards tight pricing. MEDIUM risk, fixed 0.10 lot, 10% drawdown hard cap. Not recommended for high-frequency scalping or quiet Asian-hour gold.

Strategy Logic

Pipsgrowth EX17017 Volatility — Strategy Logic Analysis (from .mq5 source)

Family: Volatility Magic: 22217017 Version: 2.00

BRIEF: Volatility Gaussian Bands EA with adaptive breakout entry, RSI and Bollinger Band confirmation, whipsaw filter, trailing stop, breakeven, and dynamic profit locking. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • GetBuffer()
  • GaussianFilter()
  • GetATR()
  • GetEMA_HTF()
  • PositionExists()
  • CloseOpposite()
  • AutoTuneFilters()
  • CheckMaxDrawdown()
  • GetCurrentATR()
  • ManagePosition()
  • CheckAndTradeBreakout()
  • CanTrade()
  • ...and 8 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (29 total across 5 groups):

  • [=== Identity ===] InpMagicNumber = 22217017 // Magic number for orders
  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_17017" // Trade comment for orders
  • [=== General Settings ===] Timeframe = 0 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
  • [=== General Settings ===] TrendFilterTF = 6 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
  • [=== General Settings ===] MaxATR = 0.0 // maximum ATR allowed (0 = no max filter)
  • [=== General Settings ===] MaxDrawdownPercent = 10.0 // Max drawdown % allowed
  • [=== General Settings ===] MaxOpenTrades = 5 // Maximum allowed open trades at the same time
  • [=== General Settings ===] AllowOnlyProfitableAdditions = true // Enable filter
  • [=== General Settings ===] MinProfitPerTradeToAdd = 5.0 // Minimum $ profit required per existing trade
  • [=== General Settings ===] LockProfitEvery_X_Dollars = 2.0 // Step: every $6 profit
  • [=== General Settings ===] LockMinusBuffer = 1.0 // Lock profit minus $1 buffer
  • [=== Volatility Gaussian Bands Settings ===] AvoidWhipsaws = true // enable whipsaw filter
  • [=== Volatility Gaussian Bands Settings ===] WhipsawLookback = 5 // bars to analyze (≥3)
  • [=== Volatility Gaussian Bands Settings ===] WhipsawThreshold = 0.6 // compression/flip ratio threshold
  • [=== Volatility Gaussian Bands Settings ===] DebugMode = false // print debug messages
  • [=== Volatility Gaussian Bands Settings ===] RequireVolumeBias = false // include volume‐based check
  • [=== RSI SYSTEM ===] RSI_Role = true // RSI Role in Trading System
  • [=== RSI SYSTEM ===] RSI_Period = 14 // RSI Period
  • [=== RSI SYSTEM ===] RSI_AppliedPrice = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // Applied Price
  • [=== RSI SYSTEM ===] RSI_OverboughtLevel = 70.0 // Overbought level
  • [=== RSI SYSTEM ===] RSI_OversoldLevel = 30.0 // Oversold level
  • [=== RSI SYSTEM ===] RSI_NeutralUpper = 60.0 // Neutral zone upper bound
  • [=== RSI SYSTEM ===] RSI_NeutralLower = 40.0 // Neutral zone lower bound
  • [=== BOLLINGER BANDS SYSTEM ===] BB_Role = true // BB Role in Trading System
  • [=== BOLLINGER BANDS SYSTEM ===] BB_Period = 20 // BB Period
  • [=== BOLLINGER BANDS SYSTEM ===] BB_Deviation = 2.0 // BB Deviation
  • [=== BOLLINGER BANDS SYSTEM ===] BB_AppliedPrice = 1 // Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // Applied Price
  • [=== BOLLINGER BANDS SYSTEM ===] BB_MiddleBandFilter = 0.5 // Distance from middle band (0.0-1.0)
  • [=== BOLLINGER BANDS SYSTEM ===] BB_UseSqueezeDetection = true // Detect BB squeeze
Pseudocode
// Pipsgrowth EX17017 Volatility — Execution Flow (from source analysis)
// Family: Volatility
// Volatility Gaussian Bands EA with adaptive breakout entry, RSI and Bollinger Band confirmation, whipsaw filter, trailing stop, breakeven, and dynamic profit locking. 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

Optimized Brokers:
ExnessIC Markets
Optimized Symbols:
XAUUSD
Optimized Timeframes:
M5

How to Install This EA on MT5

  1. 1Download the .mq5 file using the button above
  2. 2Open MetaTrader 5 on your computer
  3. 3Click File → Open Data Folder in the top menu
  4. 4Navigate to MQL5 → Experts and paste the .mq5 file there
  5. 5In MT5, right-click Expert Advisors in the Navigator panel → Refresh
  6. 6Drag the EA onto a chart matching the recommended timeframe
  7. 7Configure parameters according to the table on this page
  8. 8Enable Allow Algo Trading and click OK

EA Parameters

ParameterDefaultDescription
InpMagicNumber22217017Magic number for orders
InpTradeComment"Psgrowth.com Expert_17017"Trade comment for orders
Timeframe0Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
TrendFilterTF6Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
MaxATR0.0maximum ATR allowed (0 = no max filter)
MaxDrawdownPercent10.0Max drawdown % allowed
MaxOpenTrades5Maximum allowed open trades at the same time
AllowOnlyProfitableAdditionstrueEnable filter
MinProfitPerTradeToAdd5.0Minimum $ profit required per existing trade
LockProfitEvery_X_Dollars2.0Step: every $6 profit
LockMinusBuffer1.0Lock profit minus $1 buffer
AvoidWhipsawstrueenable whipsaw filter
WhipsawLookback5bars to analyze (≥3)
WhipsawThreshold0.6compression/flip ratio threshold
DebugModefalseprint debug messages
RequireVolumeBiasfalseinclude volume‐based check
RSI_RoletrueRSI Role in Trading System
RSI_Period14RSI Period
RSI_AppliedPrice1Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // Applied Price
RSI_OverboughtLevel70.0Overbought level
RSI_OversoldLevel30.0Oversold level
RSI_NeutralUpper60.0Neutral zone upper bound
RSI_NeutralLower40.0Neutral zone lower bound
BB_RoletrueBB Role in Trading System
BB_Period20BB Period
BB_Deviation2.0BB Deviation
BB_AppliedPrice1Applied price (1=close,2=open,3=high,4=low,5=median,6=typical,7=weighted) // Applied Price
BB_MiddleBandFilter0.5Distance from middle band (0.0-1.0)
BB_UseSqueezeDetectiontrueDetect BB squeeze
Source Code (.mq5)Open Source
Pipsgrowth_com_EX17017.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX17017 GB1_66 — Volatility Gaussian Bands EA with adaptive breakout, full 12-layer stack."

#include <Trade\Trade.mqh>
CTrade trade;

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_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_TrendFilterTF = PERIOD_H1;
ENUM_APPLIED_PRICE g_RSI_AppliedPrice = PRICE_CLOSE;
ENUM_APPLIED_PRICE g_BB_AppliedPrice = PRICE_CLOSE;
input group "=== Identity ==="
input int    InpMagicNumber      = 22217017;             // Magic number for orders
input string InpTradeComment     = "Psgrowth.com Expert_17017"; // Trade comment for orders

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)

Full source code available on download

Educational purposes only. Do NOT use with real money. Test on demo accounts only.

Tags:ex17017volatilitypipsgrowthfreemt5xauusd

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

Community

Sign in to contributeSign In

Educational purposes only. Do NOT use with real money. Test on demo accounts only.

File NamePipsgrowth_com_EX17017.mq5
File Size32.7 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyOther
Risk LevelMedium Risk
Timeframes
M5
Currency Pairs
XAUUSD
Min. Deposit$100