
Gold Signal Logic: The Triple-Check Engine for XAUUSD
November 13, 2025
The 2025 Guide to Profitable Gold (XAU/USD) Trading Signals: Reviews & Strategy
November 13, 2025FXPremiere · Telegram subscriptions
Your market. Your plan.
Explore Gold, Forex, Crypto and Indices signals. Choose monthly or yearly billing.
Gold Signals
XAU/USD
Select “Yearly” on our homepage to see annual pricing and subscribe.
View yearly options →Forex Signals
Major forex pairs
Select “Yearly” on our homepage to see annual pricing and subscribe.
View yearly options →Crypto Signals
BTC, ETH, SOL & more
Select “Yearly” on our homepage to see annual pricing and subscribe.
View yearly options →Indices Signals
US30, NAS100, S&P 500 & GER40
Select “Yearly” on our homepage to see annual pricing and subscribe.
View yearly options →Implementing the Trailing Stop Logic for Gold Signals
While the 1:2 Risk-Reward Ratio (RRR) is set when the trade opens, we need an active management system to protect that risk-free profit. This is the job of the Trailing Stop.
A Trailing Stop automatically adjusts the Stop Loss (SL) level as the price moves in your favor, locking in gains and ensuring that the trade becomes risk-free as quickly as possible.
1. Defining the Trailing Stop (TS) Rules
For this strategy, the Trailing Stop logic should activate under the following conditions:
- Activation Point: The trade must have moved into profit by a defined distance, typically $1 \times \text{SL Distance}$ (i.e., when the trade reaches the $1R$ profit mark).
- Introducing MQL4: The Code Behind the Strategy(Opens in a new browser tab)
- Gold Signal Logic: The Triple-Check Engine for XAUUSD(Opens in a new browser tab)
- London Session Gold Signals: Volatility Windows & Stops(Opens in a new browser tab)
- Partial Profits & Trailing Stops: Advanced Exit Strategies for Gold & FX Signals (2025)(Opens in a new browser tab)
- The Role of Stop Loss & Take Profit in Gold Signals (XAU/USD)(Opens in a new browser tab)
- Trailing Distance: The SL should trail the current price by a fixed distance (e.g., 20 pips/200 points). This distance must be wide enough to avoid being prematurely stopped out by market noise.
Key Trailing Stop Parameters
| Parameter | Value (Example) | Purpose |
|---|---|---|
| TS_Start_Pips | SL Distance (in Pips) | Profit required before trailing begins (1R). |
| TS_Step_Pips | 20 Pips (200 Points) | Distance the SL must trail the current price. |
2. The MQL4 Trailing Function
The Trailing Stop logic must be checked on every single tick while a position is open. This is done inside the OnTick() function, after the initial check for new signals.
In MQL4, the core logic is implemented in a dedicated function that iterates through all open positions.
The CheckForTrailingStop() Function
// --- Global Input Parameter for Trailing Stop ---
input int TrailingStopPips = 20; // 20 Pips = 200 Points
//+------------------------------------------------------------------+
//| FUNCTION: Manages the SL for open trades |
//+------------------------------------------------------------------+
void CheckForTrailingStop()
{
// Convert input pips to points
int TS_Step_Points = TrailingStopPips * 10; // XAUUSD: 1 Pip = 10 Points
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
// Only manage trades for the current symbol and Magic Number
if (OrderSymbol() != _Symbol || OrderMagicNumber() != MagicNumber) continue;
// --- A. CALCULATE PROFIT IN POINTS ---
int profitInPoints;
double currentPrice;
if (OrderType() == OP_BUY)
{
currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
profitInPoints = (int)MathRound((currentPrice - OrderOpenPrice()) / _Point);
}
else // OP_SELL
{
currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
profitInPoints = (int)MathRound((OrderOpenPrice() - currentPrice) / _Point);
}
// --- B. DETERMINE ACTIVATION POINT (1R) ---
// Get the original SL distance in points from the modified SL price
int originalSLPoints = (int)MathRound(MathAbs(OrderOpenPrice() - OrderStopLoss()) / _Point);
// Trailing Stop Activation is when profit >= original SL distance
if (profitInPoints >= originalSLPoints)
{
// --- C. CALCULATE NEW SL PRICE ---
double newSL = 0.0;
if (OrderType() == OP_BUY)
{
// New SL is the current BID price minus the TS Step
newSL = currentPrice - (TS_Step_Points * _Point);
// The new SL must be higher than the current SL to trail up
if (newSL > OrderStopLoss())
{
// Ensure SL is above breakeven (OrderOpenPrice)
newSL = MathMax(newSL, OrderOpenPrice());
}
}
else // OP_SELL
{
// New SL is the current ASK price plus the TS Step
newSL = currentPrice + (TS_Step_Points * _Point);
// The new SL must be lower than the current SL to trail down
if (newSL < OrderStopLoss())
{
// Ensure SL is below breakeven (OrderOpenPrice)
newSL = MathMin(newSL, OrderOpenPrice());
}
}
// --- D. MODIFY THE ORDER ---
// Normalize the new SL price for MQL4 requirements
newSL = NormalizeDouble(newSL, _Digits);
if (OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE))
{
Print("Order #", OrderTicket(), " SL successfully trailed to ", newSL);
}
else
{
// Error 1 = No change needed (SL too close to price)
if (GetLastError() != 1)
{
Print("Error modifying order #", OrderTicket(), ". Error: ", GetLastError());
}
}
}
}
}
}
3. Integrating into the OnTick() Function
To make the trailing stop operational, you must call the new function in your main OnTick() loop.
In your XAUUSD_H4_EA.mq4 file, modify the OnTick() as follows:
void OnTick()
{
// Trailing Stop must run on every tick, regardless of the candle close time.
CheckForTrailingStop(); // <-- New function call added here
// --- 1. CANDLE CLOSE GUARD ---
datetime CurrentH4Time = iTime(_Symbol, TimeFrame_EA, 0);
if (CurrentH4Time == LastTradeTime) return;
LastTradeTime = CurrentH4Time;
// Ensure we are not already in a trade for this symbol
if (CountOpenTrades(MagicNumber) > 0)
{
return;
}
// --- 2. SIGNAL CHECK EXECUTION ---
CheckSignal();
}
FXPremiere Official Trading Resources
Use only the official FXPremiere website and Telegram channels. Trading involves risk, and past performance does not guarantee future results.
Explore More FXPremiere Trading Resources
FXPremiere.com is the official source for Forex, Gold, Crypto and Indices trading signals via Telegram.




