Strategy vault / Trend following
Dual Moving Average Crossover Strategy
This article deeply analyzes a Dual Moving Average crossover trading strategy. The strategy uses the crossover of fast and slow moving averages as the buy and sell signals. When the fast moving average crosses above…

This article deeply analyzes a Dual Moving Average crossover trading strategy. The strategy uses the crossover of fast and slow moving averages as the buy and sell signals. When the fast moving average crosses above the slow moving average from the bottom up, it generates a buy signal. When the fast moving average crosses down through the slow moving average from the top, it generates a sell signal.
Strategy Principle
The Dual Moving Average strategy utilizes two moving averages with different parameter settings to generate trading signals by comparison. One is a fast moving average with a smaller parameter setting that can quickly capture price changes. The other one is a slow moving average, with a larger parameter setting as the benchmark of long term trend. When short term price is higher than long term trend, i.e. the fast moving average crosses above the slow one, it sends a buy signal. When short term price is lower than long term trend, i.e. the fast moving average crosses below the slow one, it generates a sell signal.
Specifically, this strategy takes two moving average parameters as input, and calculates the fast and slow moving averages respectively. Then it plots both moving averages on the price chart, with the fast line in blue and slow line in red. When the fast blue line crosses above the red line from the bottom up, it triggers a buy signal. When the fast blue line crosses down the red line from the top, it triggers a sell signal. After the trading signal is generated, it executes corresponding long or short entry orders. Finally, it sets stop loss and take profit logic for the long trades.
Advantage Analysis
The Dual Moving Average strategy has the following advantages:
- Simple to understand and implement.
- Makes good use of the merits of moving averages to catch short term opportunities alongside major trends.
- Flexible parameter tuning to adapt to different market environments.
- Applicable across timeframes and instruments.
- Optimizable with additional indicators like volume, stochastics etc.
Risk Analysis
The Dual Moving Average strategy also has the following risks:
- Crossovers may fail to filter out choppy consolidation moves effectively, generating excessive false signals.
- Frequent crosses back and forth when price oscillates near the moving averages, causing over-trading.
- Inappropriate parameter selection negatively impacts strategy performance.
To address the above risks, the following optimization methods can be adopted:
- Add distance filters so crosses too close to the moving averages are ignored.
- Incorporate additional filters like volume spike and STOCH to avoid ineffective trades in range-bound zones.
- Test different moving average parameters and combinations to find the optimal settings.
Optimization Directions
The Dual Moving Average strategy can be further optimized in the following aspects:
- Add volume filter to trigger signals only when price crossover is accompanied by significant volume spike.
- Combine with Stochastic Oscillator etc. to avoid wrong signals in overbought/oversold zones.
- Test optimal moving average parameters across different products and timeframes.
- Incorporate machine learning models to judge trend direction.
- Build adaptive trading systems using deep learning and decision trees.
Conclusion
In summary, the Dual Moving Average strategy is very classical and practical. It combines both trend following and short term mean reversion, enabling it to ride big trends while catching reversal moves. By optimizing the models and tuning parameters properly, it can generate more reliable trading signals while maintaining simplicity and intuitiveness, thus leading to better strategy performance. Different traders can customize details of this strategy based on their own preference and market conditions.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 10 | Fast MA Length |
| v_input_2 | 21 | Slow MA Length |
| v_input_3 | true | Stop Loss Percentage |
Source Pine Script
/*backtest
start: 2023-12-31 00:00:00
end: 2024-01-07 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Moving Average Crossover Strategy", overlay=true)
// Input parameters
fastLength = input(10, title="Fast MA Length")
slowLength = input(21, title="Slow MA Length")
stopLossPercent = input(1, title="Stop Loss Percentage")
// Calculate moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// Plot the moving averages on the chart
plot(fastMA, color=color.blue, title="Fast MA")
plot(slowMA, color=color.red, title="Slow MA")
// Define trading signals
longCondition = ta.crossover(fastMA, slowMA)
shortCondition = ta.crossunder(fastMA, slowMA)
// Execute trades
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
// Implement stop loss
strategy.exit("Stop Loss/Profit", from_entry="Long", loss=close * stopLossPercent / 100, profit=close * 2)
// Plot buy and sell signals on the chart
plotshape(series=longCondition, title="Buy Signal", color=color.green, style=shape.labelup, location=location.belowbar)
plotshape(series=shortCondition, title="Sell Signal", color=color.red, style=shape.labeldown, location=location.abovebar)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-08. 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-Crossover-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
- Adaptive Trading Strategy Based on Stochastic RSI Dual Line CrossoverPine Script · Trend following · 4h
- Dual Moving Average Crossover Strategy with Stop Loss and Take ProfitPine Script · Trend following · 4h
- EMA AROON ASHPine Script · Trend following · 3m
- EMA SMA Multi Indicator Comprehensive Trend Following StrategyPine Script · Trend following · 1h
- EMA200 and Stochastic RSI StrategyPine Script · Trend following · 1h
- Gaussian Channel Trend Following with Stochastic RSI Trading StrategyPine Script · Trend following · 1d