Strategy vault / Trend following
Moving Average Crossover Gold Trading Strategy
This strategy is based on the 30-day and 200-day moving average crossover on the XAUUSD gold 1-minute timeframe. A buy signal is generated when the short-term moving average crosses above the long-term moving average…

Overview
This strategy is based on the 30-day and 200-day moving average crossover on the XAUUSD gold 1-minute timeframe. A buy signal is generated when the short-term moving average crosses above the long-term moving average from the bottom up. A sell signal is generated when the short-term moving average crosses below the long-term moving average from the top down.
The strategy also sets a 40,000-point stop loss and take profit to control the risk and reward of individual trades. When a reverse signal appears, it will close out existing positions and open positions in the opposite direction. This helps effectively control losses and capture profits from trend reversions.
Principle
The strategy uses the crossover of the 30-day and 200-day moving averages to determine the trend direction. When the short-term moving average crosses above the long-term moving average, it indicates a bull market, go long. When the short-term moving average crosses below the long-term moving average, it indicates a bear market, go short.
At the same time, set a 40,000-point stop loss and take profit to control the risk of individual trades. In addition, when a reverse signal appears, actively close out the original position and open a new one in the opposite direction to capture potential trend reversal opportunities.
Advantage Analysis
The advantages of this strategy include:
- High accuracy in judging trend direction using moving average crossover
- Use stop loss and take profit to control single trade risk
- Active position closing and reverse opening can effectively control losses and capture reversals
- Applicable to intraday and intermarket trading
- Suitable for high volatility products such as gold
Risk Analysis
There are also some risks in this strategy:
- May be trapped if cross-trend shock is too large
- Improper parameter settings may cause over-trading or misses
- Reverse opening needs caution to ensure trend reversal
Methods like optimizing moving average cycle parameters, setting stop loss range, judging reliability of reversal signals can be used to control and reduce risks.
Optimization Directions
The strategy can be optimized in the following aspects:
- Optimize moving average crossover cycles to find the best parameter combination
- Dynamically adjust stop loss and take profit range to optimize risk reward ratio
- Increase indicators like price patterns to filter reversal signals
- Increase trading varieties and time range for comprehensive multi-variety optimization
Summary
The overall effect of this moving average crossover strategy is good. Using moving averages to determine trend direction is quite accurate. With stop loss and take profit to control risk, the effect is especially significant on trending products like gold. It can be optimized and improved in various ways and has wide application scenarios.
Source Pine Script
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Moving Averages Crossover Strategy", overlay=true)
// Moving Averages
ma30 = ta.sma(close, 30)
ma60 = ta.sma(close, 60)
ma200 = ta.sma(close, 200)
// Moving Averages Crossover
crossoverUp = ta.crossover(ma30, ma200)
crossoverDown = ta.crossunder(ma30, ma200)
// Buy and Sell Signals
longCondition = crossoverUp
shortCondition = crossoverDown
// Order Execution
if (longCondition)
strategy.entry("Buy", strategy.long)
strategy.exit("Cover", "Buy", stop=close - 40.000, limit=close + 40.000)
if (shortCondition)
strategy.entry("Sell", strategy.short)
strategy.exit("Cover", "Sell", stop=close + 40.000, limit=close - 40.000)
// Plotting Moving Averages
plot(ma30, color=color.blue, title="MA 30")
plot(ma60, color=color.orange, title="MA 60")
plot(ma200, color=color.green, title="MA 200")
// Conditions to close opposite position
if (strategy.position_size > 0)
if (crossoverDown)
strategy.close("Buy")
if (strategy.position_size < 0)
if (crossoverUp)
strategy.close("Sell")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-22. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Moving-Average-Crossover-Gold-Trading-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- Adaptive FVG Detection and MA Trend Trading Strategy with Dynamic ResistancePine Script · Trend following · 1d
- Adaptive Risk Management Strategy Based on Dynamic ATR and Moving Average CrossoverPine Script · Trend following · 2h
- Adaptive Trading Strategy Based on Stochastic RSI Dual Line CrossoverPine Script · Trend following · 4h
- Adaptive Volatility Based Trend Following Short Strategy with Time Delay and Stop Loss ProtectionPine Script · Trend following · 2m