Strategy vault / Machine learning
Golden Ratio Moving Average Trading Strategy
The golden ratio moving average trading strategy is a quantitative trading strategy that attempts to use the golden cross of short-term and long-term moving averages as trading signals. The strategy also incorporates…

Overview
The golden ratio moving average trading strategy is a quantitative trading strategy that attempts to use the golden cross of short-term and long-term moving averages as trading signals. The strategy also incorporates the RSI indicator to avoid opening positions at local highs in order to control risks.
Strategy Logic
The strategy is mainly based on two moving averages: the 200-day MA as the long-term MA and the 10-day MA as the short-term MA. A buy signal is generated when the short-term MA crosses over the long-term MA; A sell signal is generated when the short-term MA crosses below the long-term MA. This is the famous "golden cross". The strategy also incorporates the RSI indicator so that the strategy only opens long positions in the oversold area when RSI is less than 30.
Specifically, a long position will be opened if the following conditions are met:
- 10-day MA crosses above 200-day MA
- Currently no position
- RSI less than 30
The closing position conditions are as follows:
- Stop loss: stop loss when the price falls below a certain percentage (adjustable) of the opening price
- Take profit: take profit when the price exceeds a certain percentage (adjustable)
Advantage Analysis
The strategy has the following advantages:
- It utilizes the golden cross signal of moving averages, which is a classic and effective technical indicator trading signal
- Incorporating RSI avoids buying at the highs, which can control risks to some extent
- With stop loss and take profit settings, it can lock in profits and avoid risks
Risk Analysis
The strategy also has some risks:
- Moving average strategies are prone to generating wrong signals and whipsaws
- RSI can fail in some strong trending markets
- If the stop loss is set too small, it may lead to ultra short-term trading and frequent stop loss activation
To reduce these risks, the following optimization measures can be considered:
- Adjust the MA parameters, or add more MAs
- Incorporate other indicators to confirm RSI signals
- Adjust stop loss and take profit parameter settings
Optimization Directions
There is room for further optimization of the strategy:
- Increase more indicator filters to avoid wrong signals
- Optimize moving average parameters
- Incorporate volatility indicators to set dynamic stops
- Add machine learning models to judge market conditions
- Use algorithms to automatically optimize parameters
Conclusion
In summary, the golden ratio moving average trading strategy is a simple and effective trend following strategy. It generates trading opportunities using classic MA crossover signals and has stops to control risks. The strategy can be further improved through multi-indicator combinations, parameter optimization, machine learning, etc. to obtain better strategy performance.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 200 | (?パラメータ)Long-term moving averageBASE200 |
| v_input_int_2 | 10 | Long-term moving averageBASE10 |
| v_input_int_3 | 20 | Stop loss ratio% |
| v_input_int_4 | 5 | Take profit ratio% |
| v_input_1 | timestamp(01 Jan 2018 13:30 +0000) | (?(Period) Start date for backtesting |
| v_input_2 | timestamp(1 Jan 2099 19:30 +0000) | バックテスをFinal day |
Source Pine Script
/*backtest
start: 2022-12-29 00:00:00
end: 2024-01-04 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tsujimoto0403
//@version=5
strategy("Holy Grail", overlay=true,default_qty_type=strategy.percent_of_equity,
default_qty_value=100)
//ユーザーインプットのPrepare
malongperiod=input.int(200,"Long-term moving averageBASE200",group = "パラメータ")
mashortperiod=input.int(10,"Long-term moving averageBASE10",group = "パラメータ")
stop=input.int(20,title = "Stop loss ratio%",group = "パラメータ")
profit=input.int(5,title = "Take profit ratio%",group = "パラメータ")
startday=input(title="バックテストをThe day to open", defval=timestamp("01 Jan 2018 13:30 +0000"), group="period")
endday=input(title="バックテスをBad day", defval=timestamp("1 Jan 2099 19:30 +0000"), group="period")
//UseうVariable
var float stopprice=0
var float takeprofit=0
//とりあえずUseうインジケーターをプロット
malong=ta.sma(close,malongperiod)
mashort=ta.sma(close,mashortperiod)
plot(malong,color=color.aqua,linewidth = 2)
plot(mashort,color=color.yellow,linewidth = 2)
bgcolor(ta.rsi(close,3)<30?color.rgb(229, 86, 86, 48):na)
//Period conditions
datefilter = true
//エントリーcondition
if close>malong and close<mashort and strategy.position_size == 0 and datefilter and ta.rsi(close,3)<30
strategy.entry(id="long", direction=strategy.long)
if strategy.position_size>0
strategy.exit(id="long",stop=(1-0.01*stop)*strategy.position_avg_price)
//Sellり
if strategy.position_size > 0 and close>mashort and close<low[1]
strategy.close(id ="long")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-05. 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/Golden-Ratio-Moving-Average-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
- AI Driven Dynamic Volatility Adaptive Trend Breakout Trading StrategyPine Script · Machine learning · 2d
- AI Powered Volatility Price System Divergence Trading StrategyPine Script · Machine learning · 1h
- Configurable BBRSIAroon Strategy BacktestPine Script · Machine learning · 5m
- EMA and RSI Quantitative Trading StrategyPine Script · Machine learning · 1h
- High Frequency Hybrid Technical Analysis Quantitative StrategyPine Script · Machine learning · 15m
- KRK aDa Stochastic Slow Mean Reversion Strategy with AI Enhancements KRK aDaPine Script · Machine learning · 1h