Quant Trading Strategy Based on Monthly and Quarterly Moving Average Operation
This strategy is mainly based on the moving averages of monthly and quarterly lines for operation. Specifically, the 20-day line is used as the monthly line and the 60-day line as the quarterly line. The strategy…

Overview
This strategy is mainly based on the moving averages of monthly and quarterly lines for operation. Specifically, the 20-day line is used as the monthly line and the 60-day line as the quarterly line. The strategy signals come from the golden cross and death cross of the two moving averages. When the monthly line crosses above the quarterly line, go long; when the monthly line falls below the quarterly line, close positions. This strategy is suitable for medium- and long-term operations to capture consolidation and divergence opportunities.
Strategy Logic
This strategy uses the 20-day simple moving average as the monthly line indicator and the 60-day simple moving average as the quarterly line indicator. The specific trading signal generation logic is as follows:
- When the 20-day line crosses above the 60-day line, that is, a golden cross occurs, go long.
- When the price retreats more than 10% from the highest point in the last 10 days, close long positions for profit taking.
- When the 20-day line crosses below the 60-day line, that is, a death cross occurs, close all positions.
- When the loss reaches 10%, stop loss.
Use the moving average crossovers of monthly and quarterly lines to determine medium- and long-term trends. The golden cross for going long indicates the start of a medium- and long-term bull market, while the death cross for going short indicates the start of a medium- and long-term bear market. At the same time, use stop profit and stop loss strategies to control risks.
Advantages of the Strategy
- Using monthly and quarterly moving averages filters out market noise and captures medium- and long-term trends.
- The strategy parameters are simple and easy to implement.
- Customizable take profit and stop loss parameters to control risks.
Risk Analysis
- Unable to determine trend reversal points, with risk of losses.
- Monthly and quarterly moving averages have lagging effects, potentially missing short-term opportunities.
- Need to select appropriate stop loss points to avoid being stopped out too quickly.
Solutions:
- Adopt trailing stop loss to stop out in a timely manner.
- Incorporate other indicators to filter signals and determine trends.
- Adjust moving average parameters to optimize the strategy.
Directions for Strategy Optimization
- Add other indicators for filtering, such as KD indicator, etc., to avoid false breakouts.
- Optimize moving average parameters to find the best parameter combination.
- Incorporate additional take profit strategies such as trailing take profit to capture more profits.
Summary
This strategy systematically utilizes the advantages of monthly and quarterly moving averages by judging medium- and long-term trend directions through golden cross and death cross of the moving averages. At the same time, reasonable stop loss and take profit mechanisms are configured to control risks. There is still much room for optimizing this strategy, worth further testing and optimization.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 2020 | backtest_year |
| v_input_2 | 10 | backtest_month |
| v_input_3 | true | backtest_date |
Source Pine Script
/*backtest
start: 2022-12-08 00:00:00
end: 2023-12-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Moving average operation-Rose", overlay=true, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 30)
sma20 = sma(close, 20)
sma60 = sma(close, 60)
plot(sma20, title="Month line", color=color.purple,linewidth=2)
plot(sma60, title="Season Line", color=color.yellow,linewidth=2)
backtest_year = input(title="backtest_year",type=input.integer,defval=2020)
backtest_month = input(title="backtest_month",type=input.integer,defval=10)
backtest_date = input(title="backtest_date",type=input.integer,defval=1)
backtest_start_time = timestamp(backtest_year,backtest_month,backtest_date,0,0,0)
to_long = sma20 > sma60 and close > highest(10)*0.9 // Golden Cross
to_close = sma20 < sma60 // Death Cross
to_exit = close < highest(10)*0.9 //The stock price fell seriously
to_stop = close < 0.9*strategy.position_avg_price
// to_long = crossover(sma20, sma60) // Golden Cross
// to_close = crossunder(sma20, sma60) // Death Cross
//plotchar(to_long, char="B", text="buy", color=color.red, location=location.belowbar)
//plotchar(to_close, char="S", text="Sell", color=color.green, location=location.abovebar)
//strategy.close("open long",when = tslide, comment="Sliding price for multiple orders7%Appearance")
if true
strategy.entry("golden", strategy.long, when=to_long,comment="Multiple orders entry")
strategy.close("golden", when=to_exit,comment="Sliding price for multiple orders7%Appearance")
strategy.close("golden", when=to_close,comment="Monthly Line Quarterly Line Death Cross")
strategy.close("golden", when=to_stop,comment="Loss10%Forced stop loss")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-15. 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/Quant-Trading-Strategy-Based-on-Monthly-and-Quarterly-Moving-Average-Operation.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
- 5 Day Moving Average Channel Breakout Strategy Combined With Mileage ConceptPine Script · Breakout · 1d
- Adaptive Bollinger Breakout with Moving Average Quantitative Strategy SystemPine Script · Breakout · 1h
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h
- Adaptive Trading Strategy Based on ADX IndicatorPine Script · Breakout · 1d
- Average Line Breakthrough StrategyPine Script · Breakout · 1d
- BB Breakout StrategyPine Script · Breakout · 1d