Strategy vault / Trend following
Dual Moving Average Trend Crossover Quantitative Trading Strategy Analysis and Optimization
This strategy is a trend-following trading system based on dual moving average crossovers. By comparing the relative positions of short-term and long-term moving averages (9-day and 21-day respectively), it captures…

Overview
This strategy is a trend-following trading system based on dual moving average crossovers. By comparing the relative positions of short-term and long-term moving averages (9-day and 21-day respectively), it captures market trend reversal opportunities. The strategy combines classical technical analysis theory with modern quantitative trading methods to achieve fully automated trading decisions.
Strategy Principle
The core logic relies on crossover signals between two moving averages of different periods. When the short-term MA (9-day) crosses above the long-term MA (21-day), the system identifies upward momentum and triggers a long position; when the short-term MA crosses below the long-term MA, the system recognizes downward momentum and closes the position. Additionally, the strategy includes trade statistics functionality that tracks total trades, winning trades, and losing trades in real-time to help traders evaluate strategy performance.
Strategy Advantages
- Simple and clear logic, easy to understand and maintain
- Purely price-based, requiring no complex indicators
- Built-in trend-following capability, effective for capturing medium to long-term trends
- Complete trade statistics system for strategy evaluation
- Fully automated operation, reducing emotional interference
Strategy Risks
- Frequent false signals in ranging markets
- Slight lag in entry and exit timing
- Absence of stop-loss mechanism, potential for significant losses during volatile periods
- Reliance solely on moving averages, lacking multi-dimensional market analysis
- Fixed parameters, difficult to adapt to different market conditions
Strategy Optimization Directions
- Implement adaptive moving average periods to improve market environment adaptability
- Add volatility filters to reduce false signals in ranging markets
- Design dynamic stop-loss mechanisms to control downside risk
- Incorporate additional technical indicators like RSI or MACD to enhance signal reliability
- Develop market environment recognition modules for intelligent parameter adjustment
Summary
This is a classic and practical trend-following strategy that captures market momentum changes through dual moving average crossovers. While it has certain limitations in terms of lag and false signals, its simplicity and robustness make it an important tool in quantitative trading. Through the proposed optimization directions, the strategy's stability and profitability can be further enhanced.
Source Pine Script
/*backtest
start: 2024-05-20 00:00:00
end: 2024-12-13 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Simple MA Crossover Strategy", overlay=true)
// Input parameters
shortMA = ta.sma(close, 9)
longMA = ta.sma(close, 21)
// Buy/Sell conditions
buyCondition = ta.crossover(shortMA, longMA)
sellCondition = ta.crossunder(shortMA, longMA)
// Plot moving averages
plot(shortMA, color=color.blue, title="Short MA")
plot(longMA, color=color.red, title="Long MA")
// Execute trades
if (buyCondition)
strategy.entry("Buy", strategy.long)
if (sellCondition)
strategy.close("Buy")
// Track trades, wins, and losses
var int totalTrades = 0
var int totalWins = 0
var int totalLosses = 0
if (strategy.opentrades > 0)
totalTrades := totalTrades + 1
if (strategy.opentrades == 0 and strategy.opentrades[1] > 0)
if (strategy.netprofit > 0)
totalWins := totalWins + 1
else
totalLosses := totalLosses + 1
// Plot trade statistics
var label tradeStats = na
if (not na(tradeStats))
label.delete(tradeStats)
tradeStats := label.new(bar_index, high, text="Trades: " + str.tostring(totalTrades) + "\nWins: " + str.tostring(totalWins) + "\nLosses: " + str.tostring(totalLosses), style=label.style_label_down, color=color.white, textcolor=color.black)
Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-27. 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/Dual-Moving-Average-Trend-Crossover-Quantitative-Trading-Strategy-Analysis-and-Optimization.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
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual SMA Crossover StrategyPine Script · Trend following · 5m
- Dynamic Dual EMA Crossover Strategy with Adaptive Profit Loss ControlPine Script · Trend following · 1d
- EMA SMA Multi Indicator Comprehensive Trend Following StrategyPine Script · Trend following · 1h
- EMA and RSI Trend Trading StrategyPine Script · Trend following · 1d