Pipsgrowth EX17012 Volatility
MT5 Expert Advisor (Open Source) · XAUUSD · M5, H1
Pipsgrowth.com EX17012 gaussian — Gaussian Adaptive EA with ADX/MACD/RSI auto-tuning, full 12-layer stack.
Overview
EX17012 reads a four-handle indicator stack every tick — ADX(14, threshold 25), MACD(12/26/9), RSI(14, bands 30/70), and ATR(14) — and then layers a Gaussian parameter smoother on top of them so the indicator periods themselves drift toward recent trade conditions instead of staying fixed. The smoothing is built around a 20-element weight array generated by the CalculateGaussianWeights() function, with sigma equal to window/6.0 and the central bar receiving the highest weight, then normalized so the array sums to 1.0. The same GaussianSmooth() function is then run over rolling 100-bar parameter histories for ADX period, MACD fast/slow/signal periods, and RSI period; whenever any of those smoothed values diverges from the last refresh by more than 1.0–2.0 units, the EA calls RefreshIndicators() to release and recreate the four handles at PERIOD_M5.
The adaptive engine has two modes selected by EnableMarketBasedTuning. With auto-tuning on (the default), UpdateMarketBasedParameters() calls CalculatePerformanceMetrics() to compute a rolling win rate across the last TuningPeriod (default 50) closed trades stored in the tradeHistory[100] array. When currentWinRate falls below MinWinRate (60.0%), the EA biases indicator periods toward the current marketCondition: ranging markets push ADX period down to roughly 0.8× and RSI period to 0.9× to make signals more sensitive; trending markets shorten MACD fast to 0.9× and stretch MACD slow to 1.1× to follow the trend; volatile markets inflate ADX to 1.2× and RSI to 1.1× to make signals more conservative. All overrides are clamped — ADX stays in 10–30, MACD fast in 8–20, MACD slow in 20–40, MACD signal in 5–15, RSI in 8–25 — so the smoothing can never wander off into nonsense periods. When auto-tuning is off, UpdateAdaptiveParameters() still applies Gaussian smoothing to the static input values just to keep the handles periodically refreshed as the smoother rolls.
Signal generation is scored, not binary. CheckBuySignalStrength() walks the same ADX/MACD/RSI stack and awards 1.5 points for ADX above threshold with +DI over −DI and rising, 1.0 point for ADX above 80% of threshold with the same direction, 0.5 points for ADX above 60% of threshold regardless of direction. MACD contributes 1.0 for a fresh main-over-signal crossover and 0.5 for an above-signal main that's still rising. RSI adds 1.0 below the oversold band and 0.5 in the bottom 20% of the band while turning up. A market-condition bonus adds 0.5 if marketCondition == 1 and the trend is confirmed, plus another 0.5 if the market is ranging and ATR is low. The total is rounded and compared against MinSignalStrength (default 2); a buy triggers whenever the score clears 2 and the EA is not already long. CheckSellSignalStrength() is the mirrored function with the same scoring against −DI over +DI, MACD main under signal, and RSI overbought bands. This is the flexible-signal system: a single strong ADX leg with a matching MACD crossover and a touch of RSI can clear the bar even when the third indicator disagrees.
Risk is sized to the 20-pip base stop. CalculateLotSizeByRisk() reads the account balance, multiplies by RiskPercent (2.0% by default), divides by stop-pips × pip-value, then normalizes to the broker's SYMBOL_VOLUME_STEP and clamps inside SYMBOL_VOLUME_MIN/SYMBOL_VOLUME_MAX. Stop and take-profit are not applied at their raw input values when the EA is in a trending or volatile regime — OpenPosition() multiplies the 20-pip stop by 0.8 in trending markets and 1.3 in volatile markets, and multiplies the 15-pip take-profit by 1.2 in trending and 1.5 in volatile markets. A signal strength of 3 or higher then tightens stop by 0.9× and stretches take-profit by 1.2×, giving stronger-conviction trades a wider target. So in practice the realized risk/reward on a 3-point volatile-market long is roughly 20 × 1.3 × 0.9 = 23.4 pips stop and 15 × 1.5 × 1.2 = 27 pips target.
Trailing runs on both sides. ManagePositions() walks every position with the magic, and once profit reaches TrailingStopStartPips (10) it ratchets the stop by TrailingStopStepPips (2) per pip of new progress; once profit reaches TrailingTPStartPips (5) it ratchets the take-profit down by TrailingTPStepPips (1) to lock gains. Both updates only fire when the new value is more conservative than the existing one, so the trail is forward-only and never loosens. The opposite-signal close in ClosePositionsOnOppositeSignal() sits behind a profit gate — CloseOnlyProfitable defaults to true, and any position whose POSITION_PROFIT is below MinProfitToClose ($1.0) is skipped and logged as a missed close, with a one-line summary printed at the end of the pass.
Pre-trade safety is the standard guard stack with a few specifics. The OnTick routine first resets the daily trade counter at the D1 bar rollover, then computes the live spread in pips and returns silently if it exceeds MaxSpreadPips (3.0 — tight for an XAUUSD scalper, so this is a low-spread broker only). It also bails if dailyTradeCount >= MaxDailyTrades (100). All three retry helpers — TryClose_EX17012, TryClosePartial_EX17012, TryModify_EX17012 — wrap the standard CTrade calls in 3-attempt loops with 200ms sleeps on requote/timeout/price-changed responses, matching the broader corpus pattern. Order comments append the signal-strength score as _S<n>, so you can see in the trade history whether a position was a 1, 2, or 3 conviction entry. Magic 22217012.
What to expect in backtest: the Gaussian smoother is reactive rather than predictive — it does not forecast volatility, it lags it. The EA tends to take more trades in clean trending runs and fewer in mixed sessions, and the win-rate-driven re-tuning means the parameter set will visibly drift over the first 50–100 trades as the engine settles into a regime. Because auto-tuning only fires when the win-rate gate opens, an early streak of losers can drag the ADX/RSI/MACD periods to their lower or upper clamps for a stretch, which is normal behavior and not a bug. The minimum deposit of $100 with 2% risk and a 20-pip stop on a tight-spread XAUUSD broker is the intended deployment profile; a wider stop on the same account would dilute the lot size below the broker's minimum lot step.
Strategy Deep Dive
Every tick the EA first re-derives its adaptive period set by Gaussian-smoothing five rolling 100-bar parameter histories (ADX period, MACD fast/slow/signal, RSI period) with 20-element normalized weights, then recreates the four handles if any smoothed value drifted more than 1.0–2.0 units from the last refresh. AnalyzeMarketConditions() reads 20 bars of ATR for currentVolatility, 5 bars of ADX/+DI/−DI plus two SMA(20)/SMA(50) series, and bins the regime into ranging (0), trending (1), or volatile (2) using ATR-vs-20-bar-average and MA+ADX agreement. CheckBuySignalStrength() and CheckSellSignalStrength() each walk the same ADX/MACD/RSI stack to score a 0–5 point conviction, with regime bonuses adding half-points when conditions line up; positions open once the score clears MinSignalStrength=2 and the daily-trade and max-position gates allow it. The close logic in ManagePositions() ratchets both stop and take-profit forward in pip steps once their activation thresholds are met, while ClosePositionsOnOppositeSignal() flips profitable positions on a confirmed opposite score but skips any trade whose profit is below MinProfitToClose.
A buy is opened when CheckBuySignalStrength() returns 2 or more points — that score sums 1.5 for ADX > 25 with +DI over −DI and rising, 1.0 for a fresh MACD main-over-signal crossover, 1.0 for RSI below 30, plus 0.5 boosts for confirmed trends or low-volatility ranging states. Sells mirror the same scoring against −DI over +DI, MACD main under signal, and RSI above 70. Entries are blocked whenever the spread exceeds MaxSpreadPips (3.0), when dailyTradeCount reaches MaxDailyTrades (100), or when MaxPositions (2) is already filled with the EA's magic.
Exits run on three independent paths. Trailing stop-loss ratchets in 2-pip steps once profit clears 10 pips, trailing take-profit ratchets in 1-pip steps once profit clears 5 pips, and the base 20-pip stop / 15-pip take-profit still caps the first move. CloseOnOppositeSignal closes any profitable open position (POSITION_PROFIT ≥ MinProfitToClose of $1.0) when the opposite direction clears MinSignalStrength.
Stop loss is fixed at 20 pips × 10 points (the StopLossPips input) and is further multiplied by 0.8 in trending markets, 1.3 in volatile markets, and 0.9 again when signal strength is 3+. After the trade is in profit by TrailingStopStartPips (10 pips) the stop is ratcheted forward in TrailingStopStepPips (2-pip) increments and never loosens.
Take profit is 15 pips × 10 points at the base (TakeProfitPips input) and is multiplied by 1.2 in trending markets, 1.5 in volatile markets, and 1.2 again when signal strength is 3+. Once profit clears 5 pips the TP is ratcheted down in 1-pip steps via TrailingTPStepPips, and the EA also closes profitable longs/shorts when the opposite-direction signal clears MinSignalStrength (default 2).
Built for XAUUSD on M5 (works M5–H1) on a low-spread ECN or RAW broker where the 3-pip spread ceiling actually holds during London and New York. The 2% risk-per-trade sizing with a 20-pip stop means the $100 minimum deposit supports 0.01-lot micro entries; larger accounts benefit from the trailing 2-pip SL and 1-pip TP ratchets when the EA locks in extended moves. Best paired with traders who want the indicator periods themselves to drift with market conditions rather than manually re-optimizing between regimes.
Strategy Logic
Pipsgrowth EX17012 Volatility — Strategy Logic Analysis (from .mq5 source)
Family: Volatility
Magic: 22217012
Version: 2.00
BRIEF:
Gaussian Adaptive EA using ADX, MACD, and RSI with market-based auto-tuning. Closes positions on opposite signals, supports flexible signal matching, trailing SL/TP. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester
INDICATOR STACK:
- Standard
MT5indicators
KEY FUNCTIONS:
CalculateGaussianWeights()UpdateAdaptiveParameters()AnalyzeMarketConditions()UpdateMarketBasedParameters()CalculatePerformanceMetrics()GaussianSmooth()RefreshIndicators()CheckBuySignalStrength()CheckSellSignalStrength()CountPositions()OpenPosition()CalculateLotSizeByRisk()- ...and 6 more
INTERNAL CONSTANTS (0 total):
INPUT PARAMETERS (31 total across 11 groups):
- [=== Risk Management ===]
RiskPercent=2.0// Risk percent per trade - [=== Risk Management ===]
MaxPositions= 2 // Max simultaneous positions - [=== Risk Management ===]
MaxDailyTrades= 100 // Max trades per day - [=== Risk Management ===]
MaxSpreadPips=3.0// Max spread allowed - [=== Risk Management ===] Slippage = 5 // Max slippage in points
- [=== Gaussian & Adaptive Settings ===]
GaussianWindow= 20 // Window for gauss averaging - [=== Gaussian & Adaptive Settings ===]
EnableMarketBasedTuning=true// Enable market-based auto-tuning - [=== Gaussian & Adaptive Settings ===]
TuningPeriod= 50 // Trades to analyze for tuning - [=== Gaussian & Adaptive Settings ===]
MinWinRate=60.0// Minimum win rate to maintain - [=== Signal Configuration ===]
UseFlexibleSignals=true// Allow partial signal matches - [=== Signal Configuration ===]
MinSignalStrength= 2 // Minimum signals required (1-3) - [=== Position Management ===]
CloseOnOppositeSignal=true// Close positions on opposite signal - [=== Position Management ===]
CloseOnlyProfitable=true// Close only profitable positions - [=== Position Management ===]
MinProfitToClose=1.0// Minimum profit in $ to consider closing - [===
ADXIndicator ===] ADX_Period = 14 // InitialADXPeriod - [===
ADXIndicator ===] ADX_Threshold =25.0// InitialADXThreshold - [===
MACDIndicator ===] MACD_FastEMA = 12 // InitialMACDFastEMAPeriod - [===
MACDIndicator ===] MACD_SlowEMA = 26 // InitialMACDSlowEMAPeriod - [===
MACDIndicator ===] MACD_SignalSMA = 9 // InitialMACDSignalSMAPeriod - [===
RSIIndicator ===] RSI_Period = 14 // InitialRSIPeriod - [===
RSIIndicator ===] RSI_Overbought =70.0//RSIOverboughtlevel - [===
RSIIndicator ===] RSI_Oversold =30.0//RSIOversoldlevel - [=== Trailing Stop Loss ===]
UseTrailingStop=true// Enable trailing stop loss - [=== Trailing Stop Loss ===]
TrailingStopStartPips= 10 // Trailing SL start after profit in pips - [=== Trailing Stop Loss ===]
TrailingStopStepPips= 2 // Trailing SL step pips - [=== Trailing Take Profit ===]
UseTrailingTP=true// Enable trailing take profit - [=== Trailing Take Profit ===]
TrailingTPStartPips= 5 // Start trailing TP after this many pips - [=== Trailing Take Profit ===]
TrailingTPStepPips= 1 // Trailing TP step pips - [=== Risk
Management(SL/TP) ===]StopLossPips= 20 // Stop loss in pips - [=== Risk
Management(SL/TP) ===]TakeProfitPips= 15 // Take profit in pips - [=== Identity ===]
MagicNumber=22217012// Order magic number
// Pipsgrowth EX17012 Volatility — Execution Flow (from source analysis)
// Family: Volatility
// Gaussian Adaptive EA using ADX, MACD, and RSI with market-based auto-tuning. Closes positions on opposite signals, supports flexible signal matching, trailing SL/TP. 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 |
|---|---|---|
| RiskPercent | 2.0 | Risk percent per trade |
| MaxPositions | 2 | Max simultaneous positions |
| MaxDailyTrades | 100 | Max trades per day |
| MaxSpreadPips | 3.0 | Max spread allowed |
| Slippage | 5 | Max slippage in points |
| GaussianWindow | 20 | Window for gauss averaging |
| EnableMarketBasedTuning | true | Enable market-based auto-tuning |
| TuningPeriod | 50 | Trades to analyze for tuning |
| MinWinRate | 60.0 | Minimum win rate to maintain |
| UseFlexibleSignals | true | Allow partial signal matches |
| MinSignalStrength | 2 | Minimum signals required (1-3) |
| CloseOnOppositeSignal | true | Close positions on opposite signal |
| CloseOnlyProfitable | true | Close only profitable positions |
| MinProfitToClose | 1.0 | Minimum profit in $ to consider closing |
| ADX_Period | 14 | Initial ADX Period |
| ADX_Threshold | 25.0 | Initial ADX Threshold |
| MACD_FastEMA | 12 | Initial MACD Fast EMA Period |
| MACD_SlowEMA | 26 | Initial MACD Slow EMA Period |
| MACD_SignalSMA | 9 | Initial MACD Signal SMA Period |
| RSI_Period | 14 | Initial RSI Period |
| RSI_Overbought | 70.0 | RSI Overbought level |
| RSI_Oversold | 30.0 | RSI Oversold level |
| UseTrailingStop | true | Enable trailing stop loss |
| TrailingStopStartPips | 10 | Trailing SL start after profit in pips |
| TrailingStopStepPips | 2 | Trailing SL step pips |
| UseTrailingTP | true | Enable trailing take profit |
| TrailingTPStartPips | 5 | Start trailing TP after this many pips |
| TrailingTPStepPips | 1 | Trailing TP step pips |
| StopLossPips | 20 | Stop loss in pips |
| TakeProfitPips | 15 | Take profit in pips |
| MagicNumber | 22217012 | Order magic number |
#property copyright "Pipsgrowth.com"
#property link "https://pipsgrowth.com"
#property version "2.00"
#property strict
#property description "Pipsgrowth.com EX17012 gaussian — Gaussian Adaptive EA with ADX/MACD/RSI auto-tuning, full 12-layer stack."
#include <Trade\Trade.mqh>
input group "=== Risk Management ==="
input double RiskPercent = 2.0; // Risk percent per trade
input int MaxPositions = 2; // Max simultaneous positions
input int MaxDailyTrades = 100; // Max trades per day
input double MaxSpreadPips = 3.0; // Max spread allowed
input int Slippage = 5; // Max slippage in points
input group "=== Gaussian & Adaptive Settings ==="
input int GaussianWindow = 20; // Window for gauss averaging
input bool EnableMarketBasedTuning = true; // Enable market-based auto-tuning
input int TuningPeriod = 50; // Trades to analyze for tuning
input double MinWinRate = 60.0; // Minimum win rate to maintain
input group "=== Signal Configuration ==="
input bool UseFlexibleSignals = true; // Allow partial signal matches
input int MinSignalStrength = 2; // Minimum signals required (1-3)
input group "=== Position Management ==="
input bool CloseOnOppositeSignal = true; // Close positions on opposite signal
input bool CloseOnlyProfitable = true; // Close only profitable positions
input double MinProfitToClose = 1.0; // Minimum profit in $ to consider closing
input group "=== ADX Indicator ==="
input int ADX_Period = 14; // Initial ADX Period
input double ADX_Threshold = 25.0; // Initial ADX Threshold
input group "=== MACD Indicator ==="
input int MACD_FastEMA = 12; // Initial MACD Fast EMA Period
input int MACD_SlowEMA = 26; // Initial MACD Slow EMA Period
input int MACD_SignalSMA = 9; // Initial MACD Signal SMA Period
input group "=== RSI Indicator ==="
input int RSI_Period = 14; // Initial RSI Period
input double RSI_Overbought = 70.0; // RSI Overbought level
input double RSI_Oversold = 30.0; // RSI Oversold level
input group "=== Trailing Stop Loss ==="
input bool UseTrailingStop = true; // Enable trailing stop loss
input int TrailingStopStartPips = 10; // Trailing SL start after profit in pips
input int TrailingStopStepPips = 2; // Trailing SL step pips
input group "=== Trailing Take Profit ==="
input bool UseTrailingTP = true; // Enable trailing take profit
input int TrailingTPStartPips = 5; // Start trailing TP after this many pips
input int TrailingTPStepPips = 1; // Trailing TP step pips
input group "=== Risk Management (SL/TP) ==="
input int StopLossPips = 20; // Stop loss in pips
input int TakeProfitPips = 15; // Take profit in pips
input group "=== Identity ==="
input int MagicNumber = 22217012; // Order magic number
input string InpTradeComment = "Psgrowth.com Expert_17012";
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.