Pipsgrowth EX17008 Volatility
MT5 Expert Advisor (Open Source) · XAUUSD · M15, M5
Pipsgrowth.com EX17008 GoldScalper_BollingerBreakout_VolatilitySqueeze — BB squeeze breakout gold scalper, full 12-layer stack.
Overview
Pipsgrowth EX17008 is built around one specific market behavior: the Bollinger Band volatility squeeze. The Bollinger Band envelope around price periodically compresses — bandwidth contracts, ATR drops, candles tighten — and the moment that compression releases, gold almost always moves. EX17008 is the EA that hunts those release points.
The signal logic lives in GetBreakoutSignal(). On every new M15 bar, RefreshIndicators() copies the upper band, lower band, and middle band from the previous two closed bars, plus the ATR(14) read. The function then calculates a bandwidth percentage: (upper - lower) / middle * 100. Two conditions must both be true for a trade. First, the previous bar's bandwidth must have been below the SqueezeThreshold input, which defaults to 0.015% — that means the bands were pressed tightly against price. Second, the current bar's bandwidth must be more than 10% wider than the previous bar's, which is the isExpanding check (bandwidth > prevBandwidth * 1.1). When both fire, the squeeze just released. The direction comes from where the closed bar finished: a close above the upper band is long, a close below the lower band is short. No middle-band touches, no inside-band mean-reversion, no false-break filter — the only entry is the band break after a real squeeze.
Stop placement is a two-way minimum calculation handled in OpenPosition(). For a buy, the stop is placed at whichever is closer to entry: the current lower band, or StopLossPips (default 15 pips) below price. For a sell, the stop is the higher of the current upper band or 15 pips above price. The function then enforces a minimum stop distance of max(stopLevel * _Point, 10 pips) * 1.5 to satisfy broker stop-level rules, recalculates the actual pips the stop represents, and feeds that number into CalculatePositionSize(). With UseMoneyManagement = true and RiskPercent = 2.0, the lot size is sized so that a stop hit equals 2% of account balance, using SymbolInfoDouble(SYMBOL_TRADE_TICK_VALUE) and tick size to derive pip value per lot. Lots are floored to the broker's SYMBOL_VOLUME_STEP, capped to SYMBOL_VOLUME_MAX / SYMBOL_VOLUME_MIN, and finally checked against free margin — if the would-be lot would consume more than 90% of free margin, the lot is scaled down.
Take-profit sits at exactly 2x the stop distance — fixed 1:2 R:R by structure, not by a user-set ratio. With the 15-pip default stop, that produces a 30-pip TP (TakeProfitPips is a legacy field but the actual TP calculation overrides it with tpDist = slDist * 2). TP is also clamped to the broker's minimum stop level times 1.5 to prevent exchange rejections. There is no partial close, no basket TP, and no time-decay exit. Either the price hits the 1:2 target, hits the structural stop, or the position gets managed by the trailing logic.
Trailing is the most distinctive runtime feature. ManageOpenPositions() runs on every tick, not just on bar close. Once a position is in profit by more than TrailingStartPips (default 10 pips), the stop is ratcheted forward in the TrailingStepPips (default 5) increments. By default TrailToSMA = true, which means the new stop level is the middle Bollinger band minus 5 pips (for longs) or plus 5 pips (for shorts). This is structurally different from a fixed-pip trailing stop — the stop is anchored to the band that defines the squeeze's center, so the trade is always exited if the bands collapse back into the prior squeeze. Set TrailToSMA = false to switch to a fixed-pip trailing stop at currentPrice - TrailingStartPips.
The pyramid and filter layers are intentionally simple. UsePyramiding is false by default, with MaxOpenPositions = 2 as a hard cap. If a second position opens in the same direction while the first is still active, the same squeeze-breakout logic generates both — there is no scaled lot multiplier, the second trade is sized identically to the first. CheckFilters() runs two gates before every entry. The spread filter is on by default and blocks entries when the spread exceeds 25 pips — generous for XAUUSD typical 10-30 pips, but prevents pathological fills during thin liquidity. The time filter is off by default but, when enabled, restricts entries to the StartTime/EndTime window (default 08:00-17:00 server, which is roughly London + New York).
The SafePositionModify() function does the heavy lifting on every stop change. It re-reads SYMBOL_TRADE_STOPS_LEVEL from the broker, normalizes the new SL and TP, verifies SL is on the correct side of current price, and falls back to TryModify_EX17008 for the actual trade.PositionModify call with a 3-retry/100ms scaffold for requotes and timeouts. TryClose_EX17008 and TryClosePartial_EX17008 provide the same retry scaffold for trade.PositionClose and trade.PositionClosePartial, with 200ms sleeps between attempts. These functions are declared but not called by OnTick directly — they sit as the plumbing layer for any future exit-mode expansion.
The position-management math is worth understanding for backtests. Because both the SL and the trailing anchor are derived from current Bollinger band values, the stop and the trail both move on every new M15 bar, not every tick. That means a backtest's reported SL is the minimum of (opposite band, fixed 15 pips) at the time the signal fired — not a constant. The trailing stop starts behaving only after 10 pips of profit, then jumps in 5-pip steps each time the middle band moves 5 pips further in the trade's favor. On quiet days where the bands stay tight, the trailing stop effectively pinches the position and may close it near breakeven even though the original TP was 30 pips away. On trending days where the bands widen, the trailing stops far behind and the 1:2 R:R target becomes the dominant exit.
EX17008 fits traders who want a low-input, structurally clear breakout EA on gold. There is no ADX filter, no trend EMA stack, no news filter — the entire edge is the band-squeeze-then-release pattern. This makes the EA simple to reason about in backtest, but it also means it will trade both breakout directions during every release: a long signal followed by a short signal is a normal pattern when bands re-squeeze and release the other way. For best results, run it on XAUUSD M15, expect a few trades per session, and treat any single trade as part of a longer squeeze-and-release cycle rather than an isolated signal.
Strategy Deep Dive
The OnTick() handler runs ManageOpenPositions() on every tick to handle the trailing stop, then only on a new M15 bar (IsNewBar()) does it call RefreshIndicators() to copy the previous two closed bars' upper, middle, and lower Bollinger Bands, plus ATR(14). GetBreakoutSignal() calculates bandwidth as (upper - lower) / middle * 100 for both bars and fires when the previous bandwidth was below SqueezeThreshold (0.015%) and the current bandwidth is more than 10% wider — a squeeze release. The closed bar's position relative to the bands then determines direction: above the upper band is long, below the lower band is short. CheckFilters() gates entries on spread ≤ 25 pips and an optional 08:00-17:00 server-time window, while CountPositions() enforces the 2-position cap. Position sizing is dynamic by default — CalculatePositionSize() floors lots to RiskPercent = 2.0% of balance, clamped to the broker's volume step and free margin. SL is the closer of (opposite BB, 15 pips), TP is exactly 2x SL. Trailing starts at 10 pips of profit and ratchets in 5-pip steps, anchored to the middle BB when TrailToSMA = true. All position modifications go through SafePositionModify() → TryModify_EX17008 (3 retries / 100ms) to handle requotes and timeouts.
Goes long when the previous M15 bar's Bollinger Band bandwidth is below 0.015% and the current bar's bandwidth is at least 10% wider — i.e., a real squeeze just released — and the closed bar finished above the upper BB(20, 2.0) band. Goes short on the mirror condition (closed bar below the lower band). No other filters: no trend check, no ADX gate, no news filter — the band-squeeze-release is the entire entry.
Exits at the fixed 1:2 R:R target (TP at exactly 2x the stop distance) or at the original stop if hit. Once in profit by more than 10 pips, ManageOpenPositions() ratchets the stop forward in 5-pip steps, anchored to the middle Bollinger band by default (or to a fixed pip distance when TrailToSMA = false). The position is closed if price re-enters the prior squeeze zone on the trailing path.
Stop loss is the closer of the opposite Bollinger Band or the fixed 15-pip distance (StopLossPips) — a buy's SL is at min(currentBB_Lower, price - 15 pips), a sell's SL is at max(currentBB_Upper, price + 15 pips). After that initial placement, the trailing logic ratchets the SL forward only in the profit direction, anchored to the middle BB or to a fixed pip distance.
Take profit is fixed at exactly 2x the actual stop distance (tpDist = slDist * 2) — a structural 1:2 R:R, not a user-set pip count. The TakeProfitPips input is legacy and is overridden by this 2:1 calculation in OpenPosition(). There is no partial TP and no basket TP.
Built for XAUUSD on M15 (works on M5 as well), with a $100 minimum balance at MEDIUM risk. Best paired with an ECN or low-spread broker — the 25-pip spread cap and 3-point slippage tolerance assume competitive gold pricing. The 2% default risk and 0.01 fixed-lot fallback make the EA accessible to small accounts, but the 1:2 R:R with a 15-pip structural stop means you need to size for ~15-pip excursions; we recommend a $500+ account for sensible per-trade dollar risk. Default time filter is OFF (24/5 trading on gold); enable the 08:00-17:00 server window if you want to restrict to London + New York overlap only.
Strategy Logic
Pipsgrowth EX17008 Volatility — Strategy Logic Analysis (from .mq5 source)
Family: Volatility
Magic: 22217008
Version: 2.00
BRIEF:
Gold scalping strategy using Bollinger Bands volatility squeeze breakout detection. Enters when BB bandwidth contracts below threshold and price closes outside bands, with trailing stop along SMA, spread and time filters. Full 12-layer stack. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
SafePositionModify()RefreshIndicators()GetBreakoutSignal()OpenPosition()CalculatePositionSize()ManageOpenPositions()IsNewBar()GetPipSize()CheckFilters()CountPositions()TryClose_EX17008()TryClosePartial_EX17008()- ...and 1 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (22 total across 5 groups):
- [=== Risk Management ===]
UseMoneyManagement=true// Use Dynamic Risk % - [=== Risk Management ===]
RiskPercent=2.0// Risk Percent per Trade - [=== Risk Management ===]
FixedLotSize=0.01// Fixed LotSize(if MMfalse) - [=== Trade Settings ===] BB_Period = 20 // Bollinger Bands Period
- [=== Trade Settings ===] BB_Deviation =
2.0// Bollinger Bands Deviation - [=== Trade Settings ===]
SqueezeThreshold=0.015// SqueezeThreshold(bandwidth %) - [=== Trade Settings ===]
StopLossPips= 15 // StopLoss(pips) - [=== Trade Settings ===]
TakeProfitPips= 30 // TakeProfit(pips) - [=== Trade Settings ===] Slippage = 3 // Max
Slippage(points) - [=== Trade Settings ===]
InpMagicNumber=22217008// MagicNumber(222 + Expert ID) - [=== Trade Settings ===]
InpTradeComment= "Psgrowth.com Expert_17008" // TradeComment - [=== Trailing Stop ===]
UseTrailingStop=true// Use Trailing Stop - [=== Trailing Stop ===]
TrailToSMA=true// Trail toSMA(else fixed) - [=== Trailing Stop ===]
TrailingStartPips= 10 // TrailingStart(pips) - [=== Trailing Stop ===]
TrailingStepPips= 5 // TrailingStep(pips) - [=== Pyramiding ===]
UsePyramiding=false// Use Pyramiding - [=== Pyramiding ===]
MaxOpenPositions= 2 // Max Open Positions - [=== Filters ===]
UseSpreadFilter=true// Use Spread Filter - [=== Filters ===]
MaxSpreadPips=25.0// MaxSpread(pips) - [=== Filters ===]
UseTimeFilter=false// Use Time Filter - [=== Filters ===]
StartTime= "08:00" // StartTime(HH:MM) - [=== Filters ===]
EndTime= "17:00" // EndTime(HH:MM)
// Pipsgrowth EX17008 Volatility — Execution Flow (from source analysis)
// Family: Volatility
// Gold scalping strategy using Bollinger Bands volatility squeeze breakout detection. Enters when BB bandwidth contracts below threshold and price closes outside bands, with trailing stop along SMA, spread and time filters. Full 12-layer stack. 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 |
|---|---|---|
| UseMoneyManagement | true | Use Dynamic Risk % |
| RiskPercent | 2.0 | Risk Percent per Trade |
| FixedLotSize | 0.01 | Fixed Lot Size (if MM false) |
| BB_Period | 20 | Bollinger Bands Period |
| BB_Deviation | 2.0 | Bollinger Bands Deviation |
| SqueezeThreshold | 0.015 | Squeeze Threshold (bandwidth %) |
| StopLossPips | 15 | Stop Loss (pips) |
| TakeProfitPips | 30 | Take Profit (pips) |
| Slippage | 3 | Max Slippage (points) |
| InpMagicNumber | 22217008 | Magic Number (222 + Expert ID) |
| InpTradeComment | "Psgrowth.com Expert_17008" | Trade Comment |
| UseTrailingStop | true | Use Trailing Stop |
| TrailToSMA | true | Trail to SMA (else fixed) |
| TrailingStartPips | 10 | Trailing Start (pips) |
| TrailingStepPips | 5 | Trailing Step (pips) |
| UsePyramiding | false | Use Pyramiding |
| MaxOpenPositions | 2 | Max Open Positions |
| UseSpreadFilter | true | Use Spread Filter |
| MaxSpreadPips | 25.0 | Max Spread (pips) |
| UseTimeFilter | false | Use Time Filter |
| StartTime | "08:00" | Start Time (HH:MM) |
| EndTime | "17:00" | End Time (HH:MM) |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX17008 GoldScalper_BollingerBreakout_VolatilitySqueeze — BB squeeze breakout gold scalper, full 12-layer stack."
#include <Trade\Trade.mqh>
//+------------------------------------------------------------------+
//| Inputs |
//+------------------------------------------------------------------+
input group "=== Risk Management ==="
input bool UseMoneyManagement = true; // Use Dynamic Risk %
input double RiskPercent = 2.0; // Risk Percent per Trade
input double FixedLotSize = 0.01; // Fixed Lot Size (if MM false)
input group "=== Trade Settings ==="
input int BB_Period = 20; // Bollinger Bands Period
input double BB_Deviation = 2.0; // Bollinger Bands Deviation
input double SqueezeThreshold = 0.015; // Squeeze Threshold (bandwidth %)
input int StopLossPips = 15; // Stop Loss (pips)
input int TakeProfitPips = 30; // Take Profit (pips)
input int Slippage = 3; // Max Slippage (points)
input int InpMagicNumber = 22217008; // Magic Number (222 + Expert ID)
input string InpTradeComment = "Psgrowth.com Expert_17008"; // Trade Comment
input group "=== Trailing Stop ==="
input bool UseTrailingStop = true; // Use Trailing Stop
input bool TrailToSMA = true; // Trail to SMA (else fixed)
input int TrailingStartPips = 10; // Trailing Start (pips)
input int TrailingStepPips = 5; // Trailing Step (pips)
input group "=== Pyramiding ==="
input bool UsePyramiding = false; // Use Pyramiding
input int MaxOpenPositions = 2; // Max Open Positions
input group "=== Filters ==="
input bool UseSpreadFilter = true; // Use Spread Filter
input double MaxSpreadPips = 25.0; // Max Spread (pips)
input bool UseTimeFilter = false; // Use Time Filter
input string StartTime = "08:00"; // Start Time (HH:MM)
input string EndTime = "17:00"; // End Time (HH:MM)
// Global Variables
CTrade trade;
int handleBB;
int handleATR;
datetime lastBarTime = 0;
// Cached indicator values
double currentBB_Upper, currentBB_Lower, currentBB_Middle;
double prevBB_Upper, prevBB_Lower, prevBB_Middle;
double currentATR;
double lastBarClose, lastBarOpen, lastBarHigh, lastBarLow;
//+------------------------------------------------------------------+
//| Helper function for broker filling mode |
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE_FILLING GetAllowedFilling()
{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 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.