P
PipsGrowth
OtherOpen Source – Free

Pipsgrowth EX17013 Volatility

MT5 Expert Advisor (Open Source) · XAUUSD · M5

Pipsgrowth.com EX17013 gaussian2 — Gaussian2 Adaptive EA with multi-indicator auto-tuning and HTF filters, full 12-layer stack.

Overview

Pipsgrowth EX17013 is a self-tuning multi-indicator EA built around a Gaussian-smoothed parameter engine. The defining idea is that the indicator inputs themselves move with the market rather than staying frozen: ADX period, MACD fast/slow/signal, RSI period, and the ADX/RSI thresholds are all pushed through an adaptive loop, then the historical parameter stream is weighted with a Gaussian kernel (window 20 by default, sigma = window / GaussianSigmaDivisor) so the EA never snaps abruptly to a new regime. The result is a five-classic-indicator stack — ADX(14), MACD(12,26,9), RSI(14), ATR(14) and a 20/50 SMA pair — whose periods and thresholds drift gently inside their Min/Max envelopes as conditions shift.

The adaptive loop has two flavors selectable by EnableMarketBasedTuning. In its basic form UpdateAdaptiveParameters() reads currentVolatility against a 20-bar ATR average and the current regime (Ranging/Trending/Volatile, set by AnalyzeMarketConditions()) and multiplies each parameter by a volatilityFactor (1.2 high, 0.9 low) and a trendFactor (0.85 trending, 1.15 ranging). When EnableMarketBasedTuning is on, UpdateMarketBasedParameters() goes further: it walks a 50-trade rolling history (TuningPeriod), computes a weighted win rate using CalculatePerformanceMetrics(), and pushes parameters tighter or looser depending on whether currentWinRate sits below MinWinRate (60% default) or above MinWinRate + GoodPerformanceWinDelta (15%). In every case the values are clamped to their Min/Max bands and then pushed through GaussianSmooth() to settle.

Signal strength on each bar is the sum of three weighted votes. The ADX leg gives ADX_StrongWeight (1.5) when ADX > adaptiveADXThreshold with +DI dominant and rising, ADX_ModerateWeight (1.0) when the threshold is hit with ADX_ModerateFactor (0.8) scaling, and ADX_WeakWeight (0.5) when only ADX_WeakFactor (0.6) clears. The MACD leg adds MACD_CrossWeight (1.0) on a main/signal cross and MACD_MomentumWeight (0.5) on direction. The RSI leg adds RSI_OversoldWeight or RSI_OverboughtWeight (1.0) at the adaptive levels and RSI_MomentumWeight (0.5) on a 1.2× band touch. A TrendingMarketBonus (+0.5) lands when marketCondition==1, and a LowVolatilityBonus (+0.5) lands when ATR drops below LowVolatilityPoints (100) on a ranging day. UseFlexibleSignals=true drops the threshold one notch (MinSignalStrength=2 becomes 1, etc.) so partial-confluence bars still trigger.

The risk stack is conservative. CalculateLotSizeByRisk() takes RiskPercent (2.0% default), divides by the dynamic StopLossPips × pipValue, and refuses the trade outright if the margin level is below 200% or the resulting lot is below the broker minimum. UseFixedLot=true short-circuits to FixedLotSize (0.10). Equity protection adds a second layer: CheckRiskManagement() halts the EA if daily loss hits MaxDailyLossPercent (10%), if drawdown from the high-water mark hits MaxDrawdownPercent (20%), or if margin level slips below MinMarginLevel (200%).

SL and TP are dynamic, not static. StopLossPips (20) and TakeProfitPips (15) get multiplied by VolatileSLMultiplier (1.3) / VolatileTPMultiplier (1.5) on volatile bars, by TrendingSLMultiplier (0.8) / TrendingTPMultiplier (1.2) on trending bars, and by StrongSignalSLMultiplier (0.9) / StrongSignalTPMultiplier (1.2) when the entry's signalStrength clears StrongSignalThreshold (3). The base 20/15 default gives a 1:0.75 risk-reward, but the multipliers push the live ratio anywhere from 1:0.96 (trending strong) to 1:1.15 (volatile). The opener records the strength in the comment suffix, e.g. "Psgrowth.com Expert_17013_S3".

Exits are a four-track stack. ManagePositions() runs the trailing SL once profit clears TrailingStopStartPips (10), with TrailingStopStepPips (2) increments, and the trailing TP once profit clears TrailingTPStartPips (5) with TrailingTPStepPips (1) — both forward-only (no ratchet backward). ManageProfitBasedClosing() runs every ProfitManagerCheckSeconds (10) and closes the position if profit clears MinProfitToClose ($1), if a profitable trade is older than ProfitableCloseAfterMinutes (30) — provided CloseOnlyProfitable allows it — or if a losing trade breaches MaxLossToClose ($3) or ages past UnprofitableCloseAfterMinutes (60). CloseOnOppositeSignal=true reverses the book on a flip (long flipped to short signal and vice versa). Each fill is logged via OnTradeTransaction() and merged into the 100-slot tradeHistory circular buffer that UpdateMarketBasedParameters() later reads.

A no-trade gate runs through CanEnterTrade() on every entry. IsCooldownSatisfied() blocks re-entry for PostExitCooldownMinutes (10) after a close (off by default). IsHigherTimeframeAligned() confirms a higher-TF MA cross above HigherTFTrendThresholdPips (8) when EnableHigherTFConfirmation=true. IsVolatilityExpanded() requires current ATR ≥ average × ATRExpansionMultiplier (1.2) when EnableATRExpansionFilter=true. IsTrendStrengthSufficient() requires latestTrendStrengthPipsMinTrendStrengthBuffer (8) and latestAdxSlopeMinAdxSlope (0.5). IsHigherTimeframeIndicatorsAligned() lets you toggle individual HTF guards for ADX, MACD, RSI and ATR via EnableHTF_ADXFilter/MACD/RSI/ATR. Every guard is independently switchable, so a user can run the EA with no extra filters, with trend-strength alone, or with the full HTF quartet.

Indicator hygiene is also tighter than most EAs. UpdateIndicatorCache() reads ADX, MACD, RSI buffers only on a new bar, then the 3-bar arrays are reused by CheckBuySignalStrength() and CheckSellSignalStrength() so the loop is not hammering CopyBuffer. SafeCircularIndex() protects the tradeHistory write path against rollover, SafeDivision() blocks divide-by-zero, and ValidateInputParameters() refuses to start the EA unless all 100+ input values sit in their declared ranges (e.g. MACD_FastEMA must be < MACD_SlowEMA, RSI_Oversold < RSI_Overbought, SessionStartHour != SessionEndHour). RefreshIndicators() releases and recreates the handles whenever an adaptive parameter drift crosses the RefreshChangeThreshold (1.0 for each indicator), so the signal votes always read from handles that match the current period set.

A practical backtest outline: on XAUUSD M5 the EA's regime classifier keeps it selective in quiet sessions (mostly Ranging, low signal strength, fewer entries) and aggressive in clean trends (Trending, full 3-weight ADX vote, 20/15 SL/TP with Trending multipliers tightening SL to 16 pips and extending TP to 18 pips). The auto-tuner takes ~10 trades (TuningPeriod × 0.2) before its win-rate feedback loop is allowed to start pulling thresholds, so expect the first hour of a backtest to follow the base inputs literally. Magic is 22217013, comment prefix is "Psgrowth.com Expert_17013".

Strategy Deep Dive

On every tick the EA refreshes its 3-bar indicator cache only on a new bar, then UpdateAdaptiveParameters() or UpdateMarketBasedParameters() recomputes ADX period, MACD fast/slow/signal, RSI period, and ADX/RSI thresholds using currentVolatility, the regime state (Ranging/Trending/Volatile) and a 50-trade win-rate rolling window, clamps them to Min/Max, and feeds the history through a Gaussian kernel. CheckBuySignalStrength() and CheckSellSignalStrength() sum three weighted votes against the now-adaptive thresholds, the score is filtered through CanEnterTrade()'s cooldown/HTF/ATR/trend gates, and OpenPosition() sizes the lot from the dynamic SL and risk percent. ManagePositions() ratchets SL and TP forward once profits clear the trailing thresholds, ManageProfitBasedClosing() scans for profit-target and time-based exits, CloseOnOppositeSignal() flips the book on a regime change, and every closed deal is fed back into UpdateMarketBasedParameters() through OnTradeTransaction() so the parameter drift self-corrects toward MinWinRate.

Entry Signal

A bar is scored by three weighted votes: ADX strong/moderate/weak (1.5/1.0/0.5) on adaptiveADXThreshold with +DI or -DI dominance, MACD cross or momentum (1.0/0.5), and RSI oversold/overbought or momentum (1.0/0.5) on the adaptive RSI bands, plus a +0.5 bonus when marketCondition==1 (trending). A long triggers when total score meets MinSignalStrength (2) with plusDI dominant and the no-trade gate (cooldown, HTF MA alignment, ATR expansion, trend-strength buffer) clears.

Exit Signal

Exits run on four tracks: trailing SL ratchets forward after TrailingStopStartPips (10) in 2-pip steps, trailing TP pulls down after TrailingTPStartPips (5) in 1-pip steps, ManageProfitBasedClosing closes once profit clears MinProfitToClose ($1) or a profitable trade ages past ProfitableCloseAfterMinutes (30) and a losing trade past UnprofitableCloseAfterMinutes (60), and CloseOnOppositeSignal reverses the book on a flip of the score's direction.

Stop Loss

Default 20 pips, multiplied by VolatileSLMultiplier (1.3) on volatile bars, TrendingSLMultiplier (0.8) on trending bars, and an extra StrongSignalSLMultiplier (0.9) when entry signal strength hits 3 or more — so the live SL can land anywhere from 16 pips (strong trend) to 26 pips (volatile weak signal).

Take Profit

Default 15 pips, scaled by VolatileTPMultiplier (1.5), TrendingTPMultiplier (1.2), and StrongSignalTPMultiplier (1.2) when signal strength hits StrongSignalThreshold (3) — base 1:0.75 risk-reward that improves to roughly 1:1.15 in volatile conditions with strong confluence.

Best For

XAUUSD on M5 with a $100 minimum balance, MEDIUM risk tolerance, and an ECN or low-spread broker (the 3.0-pip spread filter assumes typical XAUUSD spreads under 25 points). Use a $300+ balance for the default 2% risk sizing to keep the lot above the broker minimum comfortably, and run on a London + New York overlap VPS to capture the volatility windows where the regime classifier and adaptive SL/TP multipliers have the most material to work with.

Strategy Logic

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

Family: Volatility Magic: 22217013 Version: 2.00

BRIEF: Gaussian2 Adaptive EA with ADX, MACD, RSI, ATR, MA and market-based auto-tuning. Enhanced with HTF filters, dynamic SL/TP, session filter, trailing stops, and position closing. 12 layers: REGIME, SIGNAL, ENTRY, CONFIRM, NO-TRADE, CAPITAL CAP, RISK, SIZING, MANAGE, EXIT, SCALING, OnTester

INDICATOR STACK:

  • Standard MT5 indicators

KEY FUNCTIONS:

  • CalculateGaussianWeights()
  • CalculateGaussianWeightsCustom()
  • CheckMagicNumberConflict()
  • ValidateInputParameters()
  • SafeTradeHistoryAccess()
  • SafeTradeHistoryWrite()
  • SafeCircularIndex()
  • CheckRiskManagement()
  • SafeDivision()
  • UpdateIndicatorCache()
  • OnTradeTransaction()
  • UpdateAdaptiveParameters()
  • ...and 23 more

INTERNAL CONSTANTS (0 total):

INPUT PARAMETERS (115 total across 15 groups):

  • [=== Execution & Limits ===] MaxPositions = 2 // Max simultaneous positions
  • [=== Execution & Limits ===] MaxDailyTrades = 100 // Max trades per day
  • [=== Execution & Limits ===] MaxSpreadPips = 3.0 // Max spread allowed
  • [=== Execution & Limits ===] Slippage = 5 // Max slippage in points
  • [=== Execution & Limits ===] Timeframe = 4 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Working timeframe for indicators
  • [=== Risk Management ===] RiskPercent = 2.0 // Risk percent per trade
  • [=== Risk Management ===] StopLossPips = 20 // Stop loss in pips
  • [=== Risk Management ===] TakeProfitPips = 15 // Take profit in pips
  • [=== Risk Management ===] UseFixedLot = false // Use fixed lot size instead of risk-based
  • [=== Risk Management ===] FixedLotSize = 0.10 // Fixed lot size when enabled
  • [=== Risk Management ===] MaxDailyLossPercent = 10.0 // Max daily loss as % of balance
  • [=== Risk Management ===] MaxDrawdownPercent = 20.0 // Max drawdown as % of balance
  • [=== Risk Management ===] MinMarginLevel = 200.0 // Minimum margin level %
  • [=== Risk Management ===] EnableEquityProtection = true // Enable equity-based protection
  • [=== Signals & Filters ===] UseFlexibleSignals = true // Allow partial signal matches
  • [=== Signals & Filters ===] MinSignalStrength = 2 // Minimum signals required (1-3)
  • [=== Gaussian & Auto-Tuning ===] EnableGaussianSmoothing = true // Enable Gaussian smoothing
  • [=== Gaussian & Auto-Tuning ===] GaussianWindow = 20 // Window for gauss averaging
  • [=== Gaussian & Auto-Tuning ===] GaussianSigmaDivisor = 6.0 // Controls Gaussian sigma (sigma = window / this)
  • [=== Gaussian & Auto-Tuning ===] GaussianWindowThresholds = 12 // Window for threshold smoothing
  • [=== Gaussian & Auto-Tuning ===] GaussianSigmaDivisor_Thresholds = 6.0 // Sigma divisor for thresholds smoothing
  • [=== Gaussian & Auto-Tuning ===] EnableMarketBasedTuning = true // Enable market-based auto-tuning
  • [=== Gaussian & Auto-Tuning ===] TuningPeriod = 50 // Trades to analyze for tuning
  • [=== Gaussian & Auto-Tuning ===] MinWinRate = 60.0 // Minimum win rate to maintain
  • [=== Gaussian & Auto-Tuning ===] GoodPerformanceWinDelta = 15.0 // Delta above MinWinRate to consider "good"
  • [=== Gaussian & Auto-Tuning ===] TuningAggressivenessScale = 1.0 // Scale factor for tuning aggressiveness
  • [=== Gaussian & Auto-Tuning ===] TuningStabilityScale = 1.0 // Scale factor for tuning stability
  • [=== ADX Settings ===] EnableADX = true // Use ADX-based signals
  • [=== ADX Settings ===] ADX_Period = 14 // Initial ADX Period
  • [=== ADX Settings ===] ADX_Threshold = 25.0 // Initial ADX Threshold
  • [=== ADX Settings ===] ADX_Lookback = 5 // Bars to read from ADX buffers
  • [=== ADX Settings ===] RequireADXRisingForTrend = true // Require ADX rising to confirm a trend
  • [=== ADX Settings ===] ADX_StrongWeight = 1.5 // Buy/sell score when ADX strong with direction
  • [=== ADX Settings ===] ADX_ModerateWeight = 1.0 // Score when ADX moderately strong
  • [=== ADX Settings ===] ADX_WeakWeight = 0.5 // Score when ADX weak
  • [=== ADX Settings ===] ADX_ModerateFactor = 0.8 // Moderate threshold factor of ADX
  • [=== ADX Settings ===] ADX_WeakFactor = 0.6 // Weak threshold factor of ADX
  • [=== ADX Settings ===] MinAdxSlope = 0.5 // Minimum ADX slope required
  • [=== ADX Settings ===] RefreshChangeThreshold_ADX = 1.0 // Min ADX change to refresh indicators
  • [=== ADX Settings ===] EnableHTF_ADXFilter = false // Require higher g_Timeframe ADX alignment
  • [=== ADX Settings ===] HTF_ADX_Timeframe = 8 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
  • [=== MACD Settings ===] EnableMACD = true // Use MACD-based signals
  • [=== MACD Settings ===] MACD_FastEMA = 12 // Initial MACD Fast EMA Period
  • [=== MACD Settings ===] MACD_SlowEMA = 26 // Initial MACD Slow EMA Period
  • [=== MACD Settings ===] MACD_SignalSMA = 9 // Initial MACD Signal SMA Period
  • [=== MACD Settings ===] MACD_CrossWeight = 1.0 // Score for MACD cross
  • [=== MACD Settings ===] MACD_MomentumWeight = 0.5 // Score for MACD momentum
  • [=== MACD Settings ===] RefreshChangeThreshold_MACD = 1.0 // Min MACD change to refresh indicators
  • [=== MACD Settings ===] EnableHTF_MACDFilter = false // Require higher g_Timeframe MACD confirmation
  • [=== MACD Settings ===] HTF_MACD_Timeframe = 8 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
  • [=== RSI Settings ===] EnableRSI = true // Use RSI-based signals
  • [=== RSI Settings ===] RSI_Period = 14 // Initial RSI Period
  • [=== RSI Settings ===] RSI_Overbought = 70.0 // RSI Overbought level
  • [=== RSI Settings ===] RSI_Oversold = 30.0 // RSI Oversold level
  • [=== RSI Settings ===] RSI_OversoldWeight = 1.0 // Score for RSI oversold
  • [=== RSI Settings ===] RSI_OverboughtWeight = 1.0 // Score for RSI overbought
  • [=== RSI Settings ===] RSI_MomentumWeight = 0.5 // Score for RSI momentum
  • [=== RSI Settings ===] RefreshChangeThreshold_RSI = 1.0 // Min RSI change to refresh indicators
  • [=== RSI Settings ===] EnableHTF_RSIFilter = false // Require higher g_Timeframe RSI guardrails
  • [=== RSI Settings ===] HTF_RSI_Timeframe = 8 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
  • [=== ATR Settings ===] EnableATR = true // Use ATR-based volatility checks
  • [=== ATR Settings ===] ATR_Period = 14 // ATR period for volatility
  • [=== ATR Settings ===] ATR_AvgLookback = 20 // Bars to average ATR
  • [=== ATR Settings ===] VolatilityMultiplier = 1.2 // Multiplier vs average ATR to classify volatile market
  • [=== ATR Settings ===] LowVolatilityPoints = 100.0 // Points threshold to grant low-volatility bonus
  • [=== ATR Settings ===] EnableATRExpansionFilter = false // Require ATR expansion before entries
  • [=== ATR Settings ===] ATRExpansionMultiplier = 1.2 // ATR multiple vs average to trade
  • [=== ATR Settings ===] EnableHTF_ATRFilter = false // Require higher g_Timeframe ATR minimum volatility
  • [=== ATR Settings ===] HTF_ATR_Timeframe = 8 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
  • [=== Moving Average Settings ===] EnableMovingAverages = true // Use moving-average trend confirmation
  • [=== Moving Average Settings ===] MA_FastPeriod = 20 // Fast MA period for trend detection
  • [=== Moving Average Settings ===] MA_SlowPeriod = 50 // Slow MA period for trend detection
  • [=== Moving Average Settings ===] MA_Lookback = 5 // Bars to read from MA buffers
  • [=== Moving Average Settings ===] TrendStrengthPips = 5.0 // Minimum MA distance (in pips) to consider trend
  • [=== Moving Average Settings ===] TrendingMarketBonus = 0.5 // Bonus in trending market
  • [=== Moving Average Settings ===] LowVolatilityBonus = 0.5 // Bonus in low-volatility conditions
  • [=== Moving Average Settings ===] EnableTrendStrengthBuffer = false // Enforce minimum trend/ADX slope buffers
  • [=== Moving Average Settings ===] MinTrendStrengthBuffer = 8.0 // Minimum MA distance buffer (pips)
  • [=== Moving Average Settings ===] EnableHigherTFConfirmation = false // Require higher g_Timeframe trend alignment
  • [=== Moving Average Settings ===] HigherTFConfirmationPeriod = 6 // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Higher timeframe to confirm trend
  • [=== Moving Average Settings ===] HigherTFFastMAPeriod = 20 // Fast MA period on higher timeframe
  • [=== Moving Average Settings ===] HigherTFSlowMAPeriod = 50 // Slow MA period on higher timeframe
  • [=== Moving Average Settings ===] HigherTFTrendThresholdPips = 8.0 // Minimum MA distance (pips) on higher g_Timeframe
  • [=== Market Analysis ===] MarketAnalysisPrintEvery = 100 // Print market analysis every N ticks
  • [=== Trailing ===] UseTrailingStop = true // Enable trailing stop loss
  • [=== Trailing ===] TrailingStopStartPips = 10 // Trailing SL start after profit in pips
  • [=== Trailing ===] TrailingStopStepPips = 2 // Trailing SL step pips
  • [=== Trailing ===] UseTrailingTP = true // Enable trailing take profit
  • [=== Trailing ===] TrailingTPStartPips = 5 // Start trailing TP after this many pips
  • [=== Trailing ===] TrailingTPStepPips = 1 // Trailing TP step pips
  • [=== Dynamic SL/TP ===] VolatileSLMultiplier = 1.3 // SL multiplier in volatile markets
  • [=== Dynamic SL/TP ===] VolatileTPMultiplier = 1.5 // TP multiplier in volatile markets
  • [=== Dynamic SL/TP ===] TrendingSLMultiplier = 0.8 // SL multiplier in trending markets
  • [=== Dynamic SL/TP ===] TrendingTPMultiplier = 1.2 // TP multiplier in trending markets
  • [=== Dynamic SL/TP ===] StrongSignalThreshold = 3 // Signal strength considered "strong"
  • [=== Dynamic SL/TP ===] StrongSignalSLMultiplier = 0.9 // SL multiplier for strong signals
  • [=== Dynamic SL/TP ===] StrongSignalTPMultiplier = 1.2 // TP multiplier for strong signals
  • [=== Position Closing ===] CloseOnOppositeSignal = true // Close positions on opposite signal
  • [=== Position Closing ===] CloseOnlyProfitable = true // Close only profitable positions
  • [=== Position Closing ===] MinProfitToClose = 1.0 // Minimum profit in $ to consider closing
  • [=== Position Closing ===] MaxLossToClose = 3.0 // Maximum loss in $ before forcing close (0=disabled threshold)
  • [=== Position Closing ===] ProfitableCloseAfterMinutes = 30 // Minutes after which to close profitable trades
  • [=== Position Closing ===] UnprofitableCloseAfterMinutes = 60 // Minutes after which to close losing trades (if allowed)
  • [=== Position Closing ===] ProfitManagerCheckSeconds = 10 // Interval between profit manager checks
  • [=== Position Closing ===] EnablePostExitCooldown = false // Prevent re-entry for cooldown period
  • [=== Position Closing ===] PostExitCooldownMinutes = 10 // Cooldown duration after exit (minutes)
  • [=== Session Filter ===] UseSessionFilter = false // Enable time/day session filter for entries
  • [=== Session Filter ===] SessionStartHour = 0 // Trading window start hour (0-23)
  • [=== Session Filter ===] SessionEndHour = 24 // Trading window end hour (1-24)
  • [=== Session Filter ===] TradeMonday = true // Allow trading on Monday
  • [=== Session Filter ===] TradeTuesday = true // Allow trading on Tuesday
  • [=== Session Filter ===] TradeWednesday = true // Allow trading on Wednesday
  • [=== Session Filter ===] TradeThursday = true // Allow trading on Thursday
  • [=== Session Filter ===] TradeFriday = true // Allow trading on Friday
  • [=== Identity ===] MagicNumber = 22217013 // Order magic number
Pseudocode
// Pipsgrowth EX17013 Volatility — Execution Flow (from source analysis)
// Family: Volatility
// Gaussian2 Adaptive EA with ADX, MACD, RSI, ATR, MA and market-based auto-tuning. Enhanced with HTF filters, dynamic SL/TP, session filter, trailing stops, and position closing. 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
MaxPositions2Max simultaneous positions
MaxDailyTrades100Max trades per day
MaxSpreadPips3.0Max spread allowed
Slippage5Max slippage in points
Timeframe4Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Working timeframe for indicators
RiskPercent2.0Risk percent per trade
StopLossPips20Stop loss in pips
TakeProfitPips15Take profit in pips
UseFixedLotfalseUse fixed lot size instead of risk-based
FixedLotSize0.10Fixed lot size when enabled
MaxDailyLossPercent10.0Max daily loss as % of balance
MaxDrawdownPercent20.0Max drawdown as % of balance
MinMarginLevel200.0Minimum margin level %
EnableEquityProtectiontrueEnable equity-based protection
UseFlexibleSignalstrueAllow partial signal matches
MinSignalStrength2Minimum signals required (1-3)
EnableGaussianSmoothingtrueEnable Gaussian smoothing
GaussianWindow20Window for gauss averaging
GaussianSigmaDivisor6.0Controls Gaussian sigma (sigma = window / this)
GaussianWindowThresholds12Window for threshold smoothing
GaussianSigmaDivisor_Thresholds6.0Sigma divisor for thresholds smoothing
EnableMarketBasedTuningtrueEnable market-based auto-tuning
TuningPeriod50Trades to analyze for tuning
MinWinRate60.0Minimum win rate to maintain
GoodPerformanceWinDelta15.0Delta above MinWinRate to consider "good"
TuningAggressivenessScale1.0Scale factor for tuning aggressiveness
TuningStabilityScale1.0Scale factor for tuning stability
EnableADXtrueUse ADX-based signals
ADX_Period14Initial ADX Period
ADX_Threshold25.0Initial ADX Threshold
ADX_Lookback5Bars to read from ADX buffers
RequireADXRisingForTrendtrueRequire ADX rising to confirm a trend
ADX_StrongWeight1.5Buy/sell score when ADX strong with direction
ADX_ModerateWeight1.0Score when ADX moderately strong
ADX_WeakWeight0.5Score when ADX weak
ADX_ModerateFactor0.8Moderate threshold factor of ADX
ADX_WeakFactor0.6Weak threshold factor of ADX
MinAdxSlope0.5Minimum ADX slope required
RefreshChangeThreshold_ADX1.0Min ADX change to refresh indicators
EnableHTF_ADXFilterfalseRequire higher g_Timeframe ADX alignment
HTF_ADX_Timeframe8Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
EnableMACDtrueUse MACD-based signals
MACD_FastEMA12Initial MACD Fast EMA Period
MACD_SlowEMA26Initial MACD Slow EMA Period
MACD_SignalSMA9Initial MACD Signal SMA Period
MACD_CrossWeight1.0Score for MACD cross
MACD_MomentumWeight0.5Score for MACD momentum
RefreshChangeThreshold_MACD1.0Min MACD change to refresh indicators
EnableHTF_MACDFilterfalseRequire higher g_Timeframe MACD confirmation
HTF_MACD_Timeframe8Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
EnableRSItrueUse RSI-based signals
RSI_Period14Initial RSI Period
RSI_Overbought70.0RSI Overbought level
RSI_Oversold30.0RSI Oversold level
RSI_OversoldWeight1.0Score for RSI oversold
RSI_OverboughtWeight1.0Score for RSI overbought
RSI_MomentumWeight0.5Score for RSI momentum
RefreshChangeThreshold_RSI1.0Min RSI change to refresh indicators
EnableHTF_RSIFilterfalseRequire higher g_Timeframe RSI guardrails
HTF_RSI_Timeframe8Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
EnableATRtrueUse ATR-based volatility checks
ATR_Period14ATR period for volatility
ATR_AvgLookback20Bars to average ATR
VolatilityMultiplier1.2Multiplier vs average ATR to classify volatile market
LowVolatilityPoints100.0Points threshold to grant low-volatility bonus
EnableATRExpansionFilterfalseRequire ATR expansion before entries
ATRExpansionMultiplier1.2ATR multiple vs average to trade
EnableHTF_ATRFilterfalseRequire higher g_Timeframe ATR minimum volatility
HTF_ATR_Timeframe8Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)
EnableMovingAveragestrueUse moving-average trend confirmation
MA_FastPeriod20Fast MA period for trend detection
MA_SlowPeriod50Slow MA period for trend detection
MA_Lookback5Bars to read from MA buffers
TrendStrengthPips5.0Minimum MA distance (in pips) to consider trend
TrendingMarketBonus0.5Bonus in trending market
LowVolatilityBonus0.5Bonus in low-volatility conditions
EnableTrendStrengthBufferfalseEnforce minimum trend/ADX slope buffers
MinTrendStrengthBuffer8.0Minimum MA distance buffer (pips)
EnableHigherTFConfirmationfalseRequire higher g_Timeframe trend alignment
HigherTFConfirmationPeriod6Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1) // Higher timeframe to confirm trend
HigherTFFastMAPeriod20Fast MA period on higher timeframe
HigherTFSlowMAPeriod50Slow MA period on higher timeframe
HigherTFTrendThresholdPips8.0Minimum MA distance (pips) on higher g_Timeframe
MarketAnalysisPrintEvery100Print market analysis every N ticks
UseTrailingStoptrueEnable trailing stop loss
TrailingStopStartPips10Trailing SL start after profit in pips
TrailingStopStepPips2Trailing SL step pips
UseTrailingTPtrueEnable trailing take profit
TrailingTPStartPips5Start trailing TP after this many pips
TrailingTPStepPips1Trailing TP step pips
VolatileSLMultiplier1.3SL multiplier in volatile markets
VolatileTPMultiplier1.5TP multiplier in volatile markets
TrendingSLMultiplier0.8SL multiplier in trending markets
TrendingTPMultiplier1.2TP multiplier in trending markets
StrongSignalThreshold3Signal strength considered "strong"
StrongSignalSLMultiplier0.9SL multiplier for strong signals
StrongSignalTPMultiplier1.2TP multiplier for strong signals
CloseOnOppositeSignaltrueClose positions on opposite signal
CloseOnlyProfitabletrueClose only profitable positions
MinProfitToClose1.0Minimum profit in $ to consider closing
MaxLossToClose3.0Maximum loss in $ before forcing close (0=disabled threshold)
ProfitableCloseAfterMinutes30Minutes after which to close profitable trades
UnprofitableCloseAfterMinutes60Minutes after which to close losing trades (if allowed)
ProfitManagerCheckSeconds10Interval between profit manager checks
EnablePostExitCooldownfalsePrevent re-entry for cooldown period
PostExitCooldownMinutes10Cooldown duration after exit (minutes)
UseSessionFilterfalseEnable time/day session filter for entries
SessionStartHour0Trading window start hour (0-23)
SessionEndHour24Trading window end hour (1-24)
TradeMondaytrueAllow trading on Monday
TradeTuesdaytrueAllow trading on Tuesday
TradeWednesdaytrueAllow trading on Wednesday
TradeThursdaytrueAllow trading on Thursday
TradeFridaytrueAllow trading on Friday
MagicNumber22217013Order magic number
Source Code (.mq5)Open Source
Pipsgrowth_com_EX17013.mq5
#property copyright "Pipsgrowth.com"
#property link      "https://pipsgrowth.com"
#property version   "2.00"
#property strict
#property description "Pipsgrowth.com EX17013 gaussian2 — Gaussian2 Adaptive EA with multi-indicator auto-tuning and HTF filters, full 12-layer stack."
#include <Trade\Trade.mqh>

// Input Parameters
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_HTF_ADX_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_HTF_MACD_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_HTF_RSI_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_HTF_ATR_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_HigherTFConfirmationPeriod = PERIOD_H1;
input group "=== Execution & Limits ==="
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 int Timeframe = 4; // Timeframe (1=M1,2=M5,3=M15,4=M30,5=H1,6=H4,7=D1)     // Working timeframe for indicators

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_HTF_ADX_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_HTF_MACD_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_HTF_RSI_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_HTF_ATR_Timeframe = PERIOD_H1;
ENUM_TIMEFRAMES g_HigherTFConfirmationPeriod = PERIOD_H1;
input group "=== Risk Management ==="
input double   RiskPercent            = 2.0;           // Risk percent per trade
input int      StopLossPips          = 20;            // Stop loss in pips
input int      TakeProfitPips        = 15;            // Take profit in pips
input bool     UseFixedLot            = false;         // Use fixed lot size instead of risk-based

Full source code available on download

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

Tags:ex17013volatilitypipsgrowthfreemt5xauusd

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