P
PipsGrowth
OtherOpen Source – Free

Pipsgrowth EX17022 Volatility

MT5 Expert Advisor (Open Source) · XAUUSD · M5

Pipsgrowth.com EX17022 GB10_5_2 — Gaussian Band breakout with auto-tuning filters and trailing/breakeven, full 12-layer stack.

Overview

Pipsgrowth EX17022 sits in the middle of the GB10_5_2 family — a stripped-down, single-purpose version of the Gaussian-band breakout framework. Where the heavier EX17020 ships with a 4-MA slope stack, an inline Heiken Ashi check, an eight-stage auto-filter, anti-intervention gates, a 3-phase market-close, and Fibonacci confluence scoring, EX17022 keeps only the core breakout engine plus three layers of trade management and one safety gate. The file itself is just under 400 lines, the entire strategy input set is ten parameters, and the EA touches three indicator handles in OnInit. That compactness is the design point: this is the EA you reach for when you want the Gaussian-band thesis — a smooth central line wrapped in a volatility-scaled envelope, broken only when candle structure agrees — without the multi-stage filtering, regime classification, or time-based session controls of its siblings.

The breakout core is unchanged from the rest of the family. In OnTick() the EA reads a 10-period EMA of close (maHandle = iMA(_Symbol, g_Timeframe, 10, 0, MODE_EMA, PRICE_CLOSE)) which acts as the Gaussian midline. It then reads a 14-period ATR (atrHandle = iATR(_Symbol, g_Timeframe, 14)) and computes an upper and lower band as gaussNow ± DistanceMultiplier × ATR. With the default DistanceMultiplier = 0.85, the band sits 85% of one ATR away from the smoothed midline on each side. A long signal requires price > upperBand while both pricePrev and pricePrev2 were still inside the band on the previous two M5 bars — a two-bar inside-then-outside break that prevents the EA from firing on the same bar that punches through. A short signal is the mirror: price < lowerBand with the two prior closes above the lower band.

Two filters gate the breakout before the order goes out. First, the HTF trend filter (emaHandle = iMA(_Symbol, g_TrendFilterTF, 50, 0, MODE_EMA, PRICE_CLOSE), default H4) — longs only fire if price > emaHTF, shorts only if price < emaHTF. This is a directional gate, not a slope check: the EA simply refuses to take long breakouts below the H4 50-EMA and short breakouts above it. Second, the slope of the Gaussian line itself — gaussNow > gaussPrev for longs, gaussNow < gaussPrev for shorts — ensures the midline is moving in the direction of the break, ruling out flat-EMA false breaks. A minimum break-distance of MinBreakDistance × ATR (default 0.3) means the close has to be at least 0.3 ATR beyond the band, not just barely on the wrong side. A 60% body gate (body / candleSize ≥ 0.6) rejects breakouts on dojis or pin bars where the close crosses the band but the candle is mostly wick.

The two refinements that distinguish EX17022 from a vanilla band-breakout bot are the auto-tuner and the dynamic lock-profit. AutoTuneFilters() looks at the current spread ((ask − bid) / _Point) and decides whether the symbol is a 4-decimal forex pair (spread < 3 points) or a 2-decimal metal pair like XAUUSD. For a 4-decimal symbol it sets pipFactor = 0.0001 and minATR = 0.0003; for a 2-decimal symbol pipFactor = 0.01 and minATR = 0.03. The effect is that the EA refuses to trade when ATR is smaller than three pips of the symbol's quote precision, which kills off a chunk of low-volatility chop on both XAUUSD and on EURUSD-style majors without you having to hand-tune the threshold. The UseAutoFilter input lets you turn this off and fall back to the static MinATR input instead.

The dynamic lock-profit (EnableDynamicLockProfit = true by default) is the most configurable money-management feature in the EA. Every tick, the EA reads PositionGetDouble(POSITION_PROFIT) and divides it by LockProfitEvery_X_Dollars (default $2). It then sets a new stop loss to entry ± (stepCount × LockProfitEvery_X_Dollars − LockMinusBuffer) / tickValue × tickSize. With defaults that means: at $2 of profit the stop locks at +$1, at $4 it locks at +$3, at $6 it locks at +$5, and so on. The stop is forward-only — it never moves against the position — and the $1 buffer keeps the trade from being closed by a one-tick drawdown back to entry. On XAUUSD at 0.1 lot each $2 of profit is roughly 20 cents of price, so the stop steps up in 10-point increments as the trade moves in your favour.

Position management runs in three modes that can be toggled independently. UseTrailingStop = true ratchets the stop to bid − 1.2×ATR for longs and ask + 1.2×ATR for shorts on every tick where the new stop is better than the current one. UseBreakeven = true moves the stop to entry once the position is more than 1.2×ATR in profit, removing the loss scenario from the trade. And the open-trade mid-line exit: if the position is a long and price closes back below gaussNow, or a short with price above gaussNow, the position is closed via TryClose_EX17022() — the Gaussian line is the invalidation level. All three layers stack, so a typical long trade has its stop ratcheting up via the ATR trail, hits breakeven around the first $0.50 of profit, and then starts locking profit in $2 increments via the dynamic lock — each layer tightening the risk envelope without ever loosening it.

Risk and safety are intentionally minimal. CheckMaxDrawdown() reads the live equity-to-balance percentage on every tick and refuses to evaluate any new entry once drawdown exceeds MaxDrawdownPercent (default 10.0%). The canTrade gate adds three more conditions: OneTradeOnly = true means at most one position per symbol (flip this off for grid-style accumulation), CountOpenTrades() < MaxOpenTrades (default 5) caps the per-symbol count, and AllowOnlyProfitableAdditions = true with MinProfitPerTradeToAdd = 5.0 means new positions in the same direction are only allowed when every existing position on the symbol is showing at least $5 of profit. That last rule effectively turns pyramiding into a trend-confirmation feature: you can only add to a position that is already working.

Order execution goes through TryClose_EX17022() and TryModify_EX17022() retry wrappers that attempt the close or modify three times with 200ms / 100ms sleeps on requote, timeout, price-off, and price-changed retcodes. Filling is auto-detected per symbol via trade.SetTypeFillingBySymbol(_Symbol). There is no partial-close path in the live code path, no news filter, no session filter, no day-of-week filter — if the spread is sane, the ATR is above the floor, and the candle passes the 60% body gate, the trade goes in. That makes the EA predictable to backtest but also means you are responsible for running it on a low-spread ECN or RAW account and being aware that the GAussian band thesis can be whipsawed in low-volatility regimes where the price keeps tapping the band but never breaks it cleanly. The default timeframe input is 0 (which maps to H1 via the MapTimeframeInt helper), although the EA was registered as M5 in the catalog and the source header recommends M5-M5 to M5-H1. Pair it with a $100 minimum balance, a low-spread broker, and you have the entire configuration surface.

In backtest, expect the equity curve to look like a stair-step rather than a smooth trend: the EA takes relatively few trades (a clean Gaussian-band break only happens a handful of times per session on M5 XAUUSD), but most of them either reach the 160-point fixed TP or get stopped at the 1.2×ATR stop with the dynamic lock taking a chunk out of the loss. The win rate tends to be above 50% in trending conditions and the average winner slightly larger than the average loser once the lock-profit steps start engaging. In chop, the 60% body gate and the MinBreakDistance filter do most of the heavy lifting by suppressing the entries that would otherwise pile up against the band. As with any band-breakout strategy, the worst regime for this EA is a slow, compressing range that resolves in a false break followed by a snap-back — the EA will fire on the break, get stopped at the ATR-based SL, and then watch price reverse the other way.

Strategy Deep Dive

The EA runs OnTick() against a stack of three handles created in OnInit: a 10-period EMA of close that acts as the Gaussian midline, a 14-period ATR for the band width, and an H4 EMA(50) for directional confirmation. AutoTuneFilters() decides the per-symbol pip factor from the live spread, then the entry code requires the previous two closes to sit inside the band and the current close to break out by more than MinBreakDistance × ATR, with a 60% body gate and a Gaussian-slope check before any order goes out. Once in a trade, TryClose_EX17022 and TryModify_EX17022 retry wrappers handle execution with 3 attempts on requote/timeout/price-changed retcodes, and the position is managed by an ATR trail, a 1×ATR breakeven, a forward-only dynamic lock-profit that steps the stop in $2 increments minus a $1 buffer, and a midline exit that closes anything that closes back through gaussNow. CheckMaxDrawdown blocks all new entries once equity drawdown exceeds MaxDrawdownPercent.

Entry Signal

Two-bar inside-then-outside breakout of a 10-period EMA ± 0.85×ATR(14) Gaussian band, gated by an H4 EMA(50) directional side filter, the slope of the Gaussian midline, a 0.3×ATR minimum break distance, and a 60% candle-body strength check. A 14-period ATR floor and a 10% drawdown hard-gate sit in front of the entry. Only one position per symbol is allowed by default; adding to a position requires every existing position on the symbol to be showing at least $5 of unrealized profit.

Exit Signal

Position-management exits run in three stacked layers. The ATR trail (ATR_MultiplierSL = 1.2) ratchets the stop forward on every tick where the new stop is better. Breakeven moves the stop to entry once profit exceeds 1.2×ATR. The dynamic lock-profit steps the stop forward in $2 increments minus a $1 buffer. A Gaussian-midline exit closes the position the moment price closes back through gaussNow against the position direction. There is no time-based exit, no partial-close path, and no profit-target ladder beyond the fixed 160-point TP.

Stop Loss

Stop loss = ATR(14) × 1.2 with a hard floor of HardSL_Points = 120 quote points; the trade is placed at ask − 1.2×ATR for longs and bid + 1.2×ATR for shorts. The 10% drawdown kill-switch additionally blocks all new entries once live equity drawdown exceeds 10% of balance.

Take Profit

Take profit is a fixed 160 quote points (FixedTP_Points = 160) applied symmetrically to both long and short entries via ask + FixedTP_Points × _Point and bid − FixedTP_Points × _Point. With the default ATR-multiple SL this gives a 1:0.75 risk-to-reward ratio on a static-ATR basis, but the dynamic lock-profit typically captures more than 160 points on winners that extend, and the midline exit closes anything that comes back through gaussNow.

Best For

Designed for XAUUSD on the M5 timeframe, with secondary support for M5-H1 setups and other FX majors via the H1 default mapping. Minimum balance: $100. Best paired with a low-spread ECN or RAW account (the auto-tuner relies on SYMBOL_ASK − SYMBOL_BID to pick the pip factor). MEDIUM risk classification: 0.1 lot default, max 5 positions per symbol, 1.2×ATR stop with a 120-point floor, 10% drawdown kill-switch. Best run during London and New York overlap hours when XAUUSD volatility and trend-EMA agreement on H4 are most reliable. Skip the EA during low-volatility Asian-session compressions where the band thesis produces whipsaws rather than clean breaks.

Strategy Logic

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

Family: Volatility Magic: 22217022 Version: 2.00

BRIEF: Gaussian Band breakout EA with auto-tuning filters, ATR-based stop loss, fixed TP, trailing stop, breakeven, dynamic lock profit, and drawdown control. Enters on band breakouts confirmed by candle strength and trend EMA. 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()
  • CountOpenTrades()
  • AllPositionsHaveMinProfit()
  • TryClose_EX17022()
  • TryClosePartial_EX17022()
  • ...and 1 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (10 total across 4 groups):

  • [=== Identity ===] InpTradeComment = "Psgrowth.com Expert_17022" // Trade Comment
  • [=== Identity ===] InpMagicNumber = 22217022 // Magic Number
  • [=== Strategy Settings ===] Timeframe = 0 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
  • [=== Strategy Settings ===] TrendFilterTF = 6 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
  • [=== Trade Management ===] MaxDrawdownPercent = 10.0 // Max drawdown % allowed
  • [=== Trade Management ===] MaxOpenTrades = 5 // Maximum allowed open trades at the same time
  • [=== Trade Management ===] AllowOnlyProfitableAdditions = true // Enable filter
  • [=== Trade Management ===] MinProfitPerTradeToAdd = 5.0 // Minimum $ profit required per existing trade
  • [=== Dynamic Lock Profit ===] LockProfitEvery_X_Dollars = 2.0 // Step: every $6 profit
  • [=== Dynamic Lock Profit ===] LockMinusBuffer = 1.0 // Lock profit minus $1 buffer
Pseudocode
// Pipsgrowth EX17022 Volatility — Execution Flow (from source analysis)
// Family: Volatility
// Gaussian Band breakout EA with auto-tuning filters, ATR-based stop loss, fixed TP, trailing stop, breakeven, dynamic lock profit, and drawdown control. Enters on band breakouts confirmed by candle strength and trend EMA. 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
InpTradeComment"Psgrowth.com Expert_17022"Trade Comment
InpMagicNumber22217022Magic Number
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)
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
Source Code (.mq5)Open Source
Pipsgrowth_com_EX17022.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX17022 GB10_5_2 — Gaussian Band breakout with auto-tuning filters and trailing/breakeven, 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_TIMEFRAMES g_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_TrendFilterTF = PERIOD_H1;
input group "=== Identity ==="
input string InpTradeComment = "Psgrowth.com Expert_17022";    // Trade Comment
input ulong  InpMagicNumber  = 22217022;                       // Magic Number

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_TIMEFRAMES g_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_TrendFilterTF = PERIOD_H1;
input group "=== Strategy Settings ==="
input bool   UseAutoFilter       = true;
input int    Length              = 10;
input double DistanceMultiplier = 0.85;
input int Timeframe = 0; // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
input int TrendFilterTF = 6; // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
input int    TrendEMA            = 50;

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;

Full source code available on download

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

Tags:ex17022volatilitypipsgrowthfreemt5xauusd

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_EX17022.mq5
File Size14.2 KB
Versionv2.00
PlatformMetaTrader 5
File Type.mq5 Source
StrategyOther
Risk LevelMedium Risk
Timeframes
M5
Currency Pairs
XAUUSD
Min. Deposit$100