
Introducing MQL4: The Code Behind the Strategy
November 13, 2025
Implementing the Trailing Stop Logic for Gold Signals
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 →Gold Signal Logic: The Triple-Check Engine for XAUUSD
Your high-probability XAUUSD strategy relies on the convergence of three factors: Trend, Location, and Momentum. Whether you are executing the trade manually or translating the strategy into an Expert Advisor (EA), the entry sequence follows a rigid, non-negotiable checklist. Gold Signal Logic: The Triple-Check Engine for XAUUSD
This article details the exact “if/then” logic required to generate a confirmed BUY or SELL signal on the H4 timeframe.
London Session Gold Signals: Volatility Windows & Stops(Opens in a new browser tab)
How to make Money in 2024(Opens in a new browser tab)
Final Case Study: Executing a High-Probability XAUUSD Trade(Opens in a new browser tab)
Dubai Living as a Digital Forex Nomad: A Comprehensive Guide(Opens in a new browser tab)
The Master Checklist: The Golden Hour
The entire signal check must only occur immediately after a new H4 candle closes. Checking mid-candle leads to false signals and inconsistent results. This moment is your Golden Hour of decision-making.
For any trade to be valid, all three conditions must be met for the intended direction.
1. Step 1: Trend Confirmation (200 EMA)
The 200 Exponential Moving Average (EMA) acts as the ultimate filter, ensuring we are only trading with the primary market direction.
Logic for a BUY Signal (Long)
- IF the closing price of the last completed H4 candle is ABOVE the 200 EMA.
- THEN the market is in an Uptrend. Proceed to Step 2 (Location).
Logic for a SELL Signal (Short)
- IF the closing price of the last completed H4 candle is BELOW the 200 EMA.
- THEN the market is in a Downtrend. Proceed to Step 2 (Location).
If the price is inside the 200 EMA, or constantly crossing it, the market is range-bound or consolidating. Do not trade.
2. Step 2: Location and Pattern (S&R and Candlestick)
This is the most crucial filter. We are looking for the market to complete a Pullback and signal reversal off a key area of value.
Logic for a BUY Signal (Long)
- LOCATION: The price must have recently pulled back to or tested a previously confirmed Support Level (a strong floor).
- PATTERN: The latest H4 candle must form a bullish reversal candlestick pattern (e.g., Bullish Engulfing, Hammer, or Morning Star) that closes above the Support Level.
Logic for a SELL Signal (Short)
- LOCATION: The price must have recently pulled back to or tested a previously confirmed Resistance Level (a strong ceiling).
- PATTERN: The latest H4 candle must form a bearish reversal candlestick pattern (e.g., Bearish Engulfing, Shooting Star, or Evening Star) that closes below the Resistance Level.
Key Rule: The reversal pattern must be at the level, not far away. If the pattern is floating in the middle of the range, it’s low-quality noise.
3. Step 3: Momentum Filter (RSI 14)
The Relative Strength Index (RSI) confirms that momentum is aligning with the trade direction, giving the move velocity. We specifically look for the RSI crossing the 50 centerline.
Logic for a BUY Signal (Long)
- IF the RSI value for the H4 candle before the signal was BELOW 50.
- AND the RSI value for the H4 signal candle is ABOVE 50.
- THEN momentum is shifting bullish.
Logic for a SELL Signal (Short)
- IF the RSI value for the H4 candle before the signal was ABOVE 50.
- AND the RSI value for the H4 signal candle is BELOW 50.
- THEN momentum is shifting bearish.
The Power of the Cross: A cross over (or under) the 50 line is a stronger indicator of a momentum shift than simply checking if the RSI is above or below 50.
The Final Decision: Entry Confirmation
Only if ALL THREE STEPS (Trend, Location/Pattern, and Momentum) are true for the intended direction is the trade considered Confirmed.
Confirmed BUY Trade:
- ENTRY: Place a buy order at the opening of the next H4 candle.
- STOP LOSS (SL): Place the SL immediately below the low of the bullish signal candle (or below the key support level).
- TAKE PROFIT (TP): Set the TP at a minimum of 2x the SL distance (1:2 RRR).
Confirmed SELL Trade:
- ENTRY: Place a sell order at the opening of the next H4 candle.
- STOP LOSS (SL): Place the SL immediately above the high of the bearish signal candle (or above the key resistance level).
- TAKE PROFIT (TP): Set the TP at a minimum of 2x the SL distance (1:2 RRR).
This checklist transforms your strategy from an idea into a concrete, executable plan.
We’ve covered the structure, the rules, and now the exact entry logic. Do you want the next article to delve into the MQL4 code for calculating Stop Loss and Take Profit, or would you prefer a strategy for a new asset like EURUSD?
FXPremiere Official Trading Resources
Use only the official FXPremiere website and Telegram channels. Trading involves risk, and past performance does not guarantee future results.




