Summary: Gold Signal Pro EA is an MQL4 expert advisor for XAUUSD that integrates 7 independent filters including multi-timeframe trend confirmation, RSI momentum, volatility detection and MA structure analysis. Suitable for M15 stable operation.




Gold Signal Pro EA is built specifically for XAUUSD with a rigorous 7-layer filter system to eliminate low-probability signals. Unlike typical grid or martingale EAs, this strategy prioritizes signal quality through multi-timeframe confirmation (M5 for entry, H1 for trend, H4 for primary direction), volatility regime detection, and dynamic quality scoring. Each signal comes with calculated TP/SL levels based on current ATR and market structure. The EA includes daily equity protection, spread monitoring, session-based filtering, and Friday close mechanisms.

Recommended Timeframe: M15
Trading Logic:
  • Multi-Timeframe Filter: H4 EMA(50) determines primary trend. H1 confirms intermediate direction. M5 scans for entry triggers.

  • Volatility Detection: Current ATR must not exceed 1.6x the 20-period average. Abnormal volatility spikes block trading.

  • MA Structure Check: Verify alignment of SMA 13/21/75/100. Flat MA periods automatically filtered out.

  • RSI Momentum Filter: RSI(14) must be >50 for long signals, <50 for short signals. No entry at extreme overbought/oversold.

  • Quality Scoring System: Each signal receives a score based on confluence factors (★★★ strong, ★★ standard, ★ cautious).

  • Risk Management: ATR-based dynamic stop loss (1.4x ATR), take profit (2.5x ATR). Trailing stop activates at 1x ATR profit.


  • ``mql4
    //+------------------------------------------------------------------+
    //| GoldSignalProEA.mq4 |
    //+------------------------------------------------------------------+
    #property copyright ""
    #property link ""
    #property version "1.00"
    #property strict

    //--- input parameters with comments
    input double LotSize = 0.01; // Fixed lot size (0.01 for XAUUSD)
    input int FastMAPeriod = 13; // Fast SMA period (13)
    input int MidMAPeriod1 = 21; // Mid SMA period (21)
    input int MidMAPeriod2 = 75; // Mid SMA period (75)
    input int SlowMAPeriod = 100; // Slow SMA period (100)
    input int H1TrendPeriod = 50; // H1 EMA period for trend confirmation
    input int H4TrendPeriod = 50; // H4 EMA period for primary trend
    input int RSIPeriod = 14; // RSI period for momentum filter
    input int ATRPeriod = 14; // ATR period for volatility management
    input double MaxATRMultiplier = 1.6; // Max ATR multiplier (volatility guard)
    input double ATRStopMultiplier = 1.4; // Stop loss as multiple of ATR
    input double ATRTakeMultiplier = 2.5; // Take profit as multiple of ATR
    input double TrailingStartATR = 1.0; // Trailing activates at profit (x ATR)
    input double TrailingStepATR = 0.5; // Trailing step (x ATR)
    input int MinQualityScore = 2; // Minimum quality score (1-3, 3=highest)
    input int MagicNumber = 202420; // Unique EA identifier
    input int MaxSpread = 35; // Maximum allowed spread in points
    input double DailyLossLimit = 5.0; // Daily loss limit as percentage
    input bool UseLondonSessionOnly = true; // Trade only during London/New York overlap
    input bool UseFridayClose = true; // Close trades before Friday 20:00 GMT

    //--- global variables
    double dailyStartBalance = 0;
    datetime lastBarTime = 0;
    bool fridayCloseExecuted = false;
    double avgATR = 0;

    //+------------------------------------------------------------------+
    //| Expert initialization function |
    //+------------------------------------------------------------------+
    int OnInit()
    {
    dailyStartBalance = AccountBalance();
    lastBarTime = 0;
    fridayCloseExecuted = false;
    avgATR = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
    if(avgATR <= 0) avgATR = 180 Point;
    return(INIT_SUCCEEDED);
    }

    //+------------------------------------------------------------------+
    //| Expert deinitialization function |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
    {
    Comment("");
    }

    //+------------------------------------------------------------------+
    //| Get higher timeframe trend direction (H4) |
    //+------------------------------------------------------------------+
    int GetH4Trend()
    {
    double closeH4 = iClose(Symbol(), PERIOD_H4, 1);
    double emaH4 = iMA(Symbol(), PERIOD_H4, H4TrendPeriod, 0, MODE_EMA, PRICE_CLOSE, 1);
    if(closeH4 > emaH4) return 1;
    if(closeH4 < emaH4) return -1;
    return 0;
    }

    //+------------------------------------------------------------------+
    //| Get H1 trend confirmation |
    //+------------------------------------------------------------------+
    int GetH1Trend()
    {
    double closeH1 = iClose(Symbol(), PERIOD_H1, 1);
    double emaH1 = iMA(Symbol(), PERIOD_H1, H1TrendPeriod, 0, MODE_EMA, PRICE_CLOSE, 1);
    if(closeH1 > emaH1) return 1;
    if(closeH1 < emaH1) return -1;
    return 0;
    }

    //+------------------------------------------------------------------+
    //| Check MA structure alignment |
    //+------------------------------------------------------------------+
    bool IsMAStructured()
    {
    double sma13 = iMA(Symbol(), PERIOD_M15, FastMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
    double sma21 = iMA(Symbol(), PERIOD_M15, MidMAPeriod1, 0, MODE_SMA, PRICE_CLOSE, 1);
    double sma75 = iMA(Symbol(), PERIOD_M15, MidMAPeriod2, 0, MODE_SMA, PRICE_CLOSE, 1);
    double sma100 = iMA(Symbol(), PERIOD_M15, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);

    // Bullish alignment: 13 > 21 > 75 > 100
    bool bullish = (sma13 > sma21 && sma21 > sma75 && sma75 > sma100);
    // Bearish alignment: 13 < 21 < 75 < 100
    bool bearish = (sma13 < sma21 && sma21 < sma75 && sma75 < sma100);

    return (bullish || bearish);
    }

    //+------------------------------------------------------------------+
    //| Check MA slope (not flat) |
    //+------------------------------------------------------------------+
    bool IsMASloping()
    {
    double sma21_current = iMA(Symbol(), PERIOD_M15, MidMAPeriod1, 0, MODE_SMA, PRICE_CLOSE, 1);
    double sma21_prev = iMA(Symbol(), PERIOD_M15, MidMAPeriod1, 0, MODE_SMA, PRICE_CLOSE, 4);
    double slope = (sma21_current - sma21_prev) / Point;

    // Require meaningful slope (not flat)
    return (MathAbs(slope) > 15);
    }

    //+------------------------------------------------------------------+
    //| Calculate signal quality score (1-3) |
    //+------------------------------------------------------------------+
    int CalculateQualityScore(int direction, double rsi, double atrRatio)
    {
    int score = 1; // base score

    // Check confluence factors
    bool h4Align = (direction == GetH4Trend());
    bool h1Align = (direction == GetH1Trend());
    bool maStructured = IsMAStructured();
    bool maSloping = IsMASloping();
    bool rsiValid = (direction == 1 && rsi > 50 && rsi < 70) || (direction == -1 && rsi < 50 && rsi > 30);
    bool lowVolatility = (atrRatio < 1.2);

    int confluence = 0;
    if(h4Align) confluence++;
    if(h1Align) confluence++;
    if(maStructured) confluence++;
    if(maSloping) confluence++;
    if(rsiValid) confluence++;
    if(lowVolatility) confluence++;

    if(confluence >= 5) score = 3; // ★★★ strong
    else if(confluence >= 3) score = 2; // ★★ standard
    else score = 1; // ★ cautious

    return score;
    }

    //+------------------------------------------------------------------+
    //| Check entry signal based on price action and filters |
    //+------------------------------------------------------------------+
    bool CheckEntry(int direction, double &entryPrice, double &sl, double &tp, double atr, int qualityScore)
    {
    if(qualityScore < MinQualityScore) return false;

    double close1 = iClose(Symbol(), PERIOD_M15, 1);
    double open1 = iOpen(Symbol(), PERIOD_M15, 1);
    double high1 = iHigh(Symbol(), PERIOD_M15, 1);
    double low1 = iLow(Symbol(), PERIOD_M15, 1);
    double ema21 = iMA(Symbol(), PERIOD_M15, MidMAPeriod1, 0, MODE_SMA, PRICE_CLOSE, 1);

    if(direction == 1) // Long
    {
    // Bullish candle close above open and price near/above EMA21
    bool bullishClose = (close1 > open1);
    bool aboveEMA = (low1 > ema21 || close1 > ema21);
    bool noUpperWick = ((high1 - close1) < (close1 - open1)
    0.5);

    if(bullishClose && aboveEMA && noUpperWick)
    {
    entryPrice = Ask;
    sl = entryPrice - (atr ATRStopMultiplier);
    tp = entryPrice + (atr
    ATRTakeMultiplier);
    return true;
    }
    }
    else if(direction == -1) // Short
    {
    // Bearish candle close below open and price near/below EMA21
    bool bearishClose = (close1 < open1);
    bool belowEMA = (high1 < ema21 || close1 < ema21);
    bool noLowerWick = ((close1 - low1) < (open1 - close1) 0.5);

    if(bearishClose && belowEMA && noLowerWick)
    {
    entryPrice = Bid;
    sl = entryPrice + (atr
    ATRStopMultiplier);
    tp = entryPrice - (atr ATRTakeMultiplier);
    return true;
    }
    }
    return false;
    }

    //+------------------------------------------------------------------+
    //| Check if current time is within London/New York session |
    //+------------------------------------------------------------------+
    bool IsValidSession()
    {
    if(!UseLondonSessionOnly) return true;

    datetime currentTime = TimeCurrent();
    int hour = TimeHour(currentTime);
    int minute = TimeMinute(currentTime);
    int currentMinutes = hour
    60 + minute;

    // London session: 08:00 - 16:00 GMT
    int londonStart = 8 60;
    int londonEnd = 16
    60;
    // New York session: 13:00 - 22:00 GMT
    int nyStart = 13 60;
    int nyEnd = 22
    60;

    // London-New York overlap: 13:00 - 16:00 GMT (most liquid)
    bool inOverlap = (currentMinutes >= 13 60 && currentMinutes < 16 60);
    bool inLondon = (currentMinutes >= londonStart && currentMinutes < londonEnd);
    bool inNewYork = (currentMinutes >= nyStart && currentMinutes < nyEnd);

    return (inOverlap || inLondon || inNewYork);
    }

    //+------------------------------------------------------------------+
    //| Manage trailing stop for open position |
    //+------------------------------------------------------------------+
    void ManageTrailingStop(double atr)
    {
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
    {
    double activate = atr TrailingStartATR;
    double step = atr
    TrailingStepATR;
    double newSL = 0;

    if(OrderType() == OP_BUY)
    {
    double profit = Bid - OrderOpenPrice();
    if(profit >= activate)
    {
    newSL = Bid - step;
    if(newSL > OrderStopLoss())
    OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE);
    }
    }
    else if(OrderType() == OP_SELL)
    {
    double profit = OrderOpenPrice() - Ask;
    if(profit >= activate)
    {
    newSL = Ask + step;
    if(newSL < OrderStopLoss() || OrderStopLoss() == 0)
    OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE);
    }
    }
    break;
    }
    }
    }
    }

    //+------------------------------------------------------------------+
    //| Expert tick function |
    //+------------------------------------------------------------------+
    void OnTick()
    {
    // Daily equity protection
    double currentEquity = AccountEquity();
    double lossPercent = (dailyStartBalance - currentEquity) / dailyStartBalance 100;
    if(lossPercent >= DailyLossLimit)
    {
    Comment("Daily loss limit reached. No new trades.");
    return;
    }

    // Friday close before weekend
    if(UseFridayClose && !fridayCloseExecuted)
    {
    datetime currentTime = TimeCurrent();
    if(TimeDayOfWeek(currentTime) == 5 && TimeHour(currentTime) >= 20)
    {
    CloseAllOrders();
    fridayCloseExecuted = true;
    return;
    }
    if(TimeDayOfWeek(currentTime) != 5)
    fridayCloseExecuted = false;
    }

    // Session filter
    if(!IsValidSession())
    {
    Comment("Outside London/NY session");
    return;
    }

    // Spread filter
    if(MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread)
    {
    Comment("Spread too high: ", MarketInfo(Symbol(), MODE_SPREAD));
    return;
    }

    // New bar logic (M15)
    if(Time[0] == lastBarTime)
    return;
    lastBarTime = Time[0];

    // Manage existing position
    int posCount = CountPositions();
    if(posCount > 0)
    {
    double atr = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
    if(atr > 0) ManageTrailingStop(atr);
    return;
    }

    // Get indicators
    double close1 = iClose(Symbol(), PERIOD_M15, 1);
    double rsi = iRSI(Symbol(), PERIOD_M15, RSIPeriod, PRICE_CLOSE, 1);
    double atr = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);

    // Update average ATR for volatility filter
    if(atr > 0) avgATR = (avgATR
    0.95) + (atr 0.05);

    // Volatility guard
    double atrRatio = atr / avgATR;
    if(atr > avgATR
    MaxATRMultiplier && avgATR > 0)
    {
    Comment("Volatility too high. ATR ratio: ", atrRatio);
    return;
    }

    // Get H4 primary trend
    int h4Trend = GetH4Trend();
    if(h4Trend == 0)
    {
    Comment("No clear H4 trend direction");
    return;
    }

    // RSI momentum filter
    if(h4Trend == 1 && rsi < 50)
    {
    Comment("RSI below 50, no bullish momentum");
    return;
    }
    if(h4Trend == -1 && rsi > 50)
    {
    Comment("RSI above 50, no bearish momentum");
    return;
    }

    // Calculate quality score
    int qualityScore = CalculateQualityScore(h4Trend, rsi, atrRatio);

    // Display quality score on chart
    string scoreStars = (qualityScore == 3) ? "★★★ STRONG" : ((qualityScore == 2) ? "★★ STANDARD" : "★ CAUTIOUS");
    Comment("Signal Quality: ", scoreStars, " | H4 Trend: ", (h4Trend==1?"BULL":"BEAR"), " | ATR Ratio: ", DoubleToStr(atrRatio,2));

    // Check entry condition
    double entryPrice = 0, sl = 0, tp = 0;
    if(CheckEntry(h4Trend, entryPrice, sl, tp, atr, qualityScore))
    {
    int cmd = (h4Trend == 1) ? OP_BUY : OP_SELL;
    int ticket = OrderSend(Symbol(), cmd, LotSize, entryPrice, 5, sl, tp, "Gold Signal Pro", MagicNumber, 0, clrNONE);
    if(ticket < 0)
    Print("OrderSend failed: ", GetLastError());
    else
    Print("Order opened. Direction: ", cmd==OP_BUY?"BUY":"SELL", " | Quality: ", qualityScore);
    }
    }

    //+------------------------------------------------------------------+
    //| Count open positions with this MagicNumber |
    //+------------------------------------------------------------------+
    int CountPositions()
    {
    int count = 0;
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
    count++;
    }
    }
    return count;
    }

    //+------------------------------------------------------------------+
    //| Close all orders for this symbol and magic |
    //+------------------------------------------------------------------+
    void CloseAllOrders()
    {
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
    {
    if(OrderType() == OP_BUY)
    OrderClose(OrderTicket(), OrderLots(), Bid, 5, clrNONE);
    else if(OrderType() == OP_SELL)
    OrderClose(OrderTicket(), OrderLots(), Ask, 5, clrNONE);
    }
    }
    }
    }
    //+------------------------------------------------------------------+
    ``
    Reference: Original MQL4 code inspired by multi-filter signal trading concepts from professional gold trading systems.
    Disclaimer: Gold trading involves significant risk due to high volatility. This EA is provided as-is without any guarantee of profit. Test thoroughly on a demo account before live deployment. Past performance does not guarantee future results.