MACD Hook on Gold
- Doji
- May 30, 2024
- 2 min read
Updated: Oct 11, 2024
A Simple MACD Strategy for Gold
The Idea
This strategy uses two parts of the MACD indicator to look for an uptick in momentum. The MACD line above 0 indicates an overall momentum, and with that in place, the buy signal is given when the histogram forms a "hook". Additionally, the short-term trend is confirmed by a Hull Moving Average.

Setup for Backtest
Market: XAUUSD (Gold)
Contract: 1 € per point
Broker: IG
Testing environment: ProRealtime 12
Timeframe: Daily
Time zone: CET
No fees and commissions are included.
Result
Total gain: 1 616.6 €
Average gain: 6.2 €
Total trades: 261
Winners: 185
Losers: 74
Breakeven: 2
Max drawdown: –164.3 €
Risk/reward ratio: 0.9
Total time in the market: 17.3 %
Average time in the market: 5 days, 20 hours
CAGR (10 000 € in starting capital): 0.43 %

Entry Conditions
MACD line is over 0
MACD histogram is up
MACD histogram of previous bar is down
15 Period Hull Average is sloping upwards
Exit Conditions
Sell after:
Three bullish days in a row,
or 10 trading days.
Code
ProRealTime
//-------------------------------------------------------------------------
// Concept: MACD Hook
// Market: Gold
// Direction: Long only
// Timeframe: Daily
// Timezone: CET
// Versions: v.1 | By: Algomatictrading.com | 2024-04-10 | OOS since: 2022-04-01
//-------------------------------------------------------------------------
defparam preloadbars = 5000
defparam cumulateorders = false
// POSITION MANAGEMENT
//-------------------------------------------------------------------------
once positionsize = 1
// RISK MANAGEMENT
//-------------------------------------------------------------------------
once stoploss = 5
// INDICATORS
//-------------------------------------------------------------------------
ml = macdline[12,26,9]
m = macd[12,26,9]
ma = average[15,7]
// TRADING CONDITIONS
//-------------------------------------------------------------------------
// Long - Enter
// ------------------
cl = ml > 0
cl = cl and m > m[1]
cl = cl and m[1] < m[2]
cl = cl and ma > ma[1]
// Long - Exit
// ------------------
clx = summation[3](close>open)=3
clx = clx or barindex-tradeindex >= 10
// TRADING ACTION
//-------------------------------------------------------------------------
// Enter
// ------------------
if cl then
buy positionsize contract at market
set stop %loss stoploss
endif
// Exit
// ------------------
if longonmarket and clx then
sell at market
endif
FAQ
Q: Am I free to use this strategy however I want?
A: Sure! But we're happy if you refer to our website and keep the creator's name in the code.
Q: I'm using another platform, can you write the code in another language?
A: No, sorry. We might add code in more languages later to the website, but until then, we recommend you try ChatGPT or something similar to help you rewrite it.
Q: Why does my backtest look different when I run the code?
A: The strategy might give different backtest results for several reasons, like added spread or fees, the wrong time-zone settings, or that you're using another type of contract.
Q: Will I make money if I run this strategy live?
A: We don't know. We're not financial advisors, we're just traders sharing our ideas.