Momentum Dual Moving Average Crossover Strategy
This strategy uses moving average crossovers to determine price momentum direction, supplemented by golden/death crosses to judge overall trend, to implement trend following.

Overview
This strategy uses moving average crossovers to determine price momentum direction, supplemented by golden/death crosses to judge overall trend, to implement trend following.
Strategy Logic
The strategy uses EMA and SMA crossovers to determine price momentum direction. EMA reacts faster while SMA reacts more steadily. When EMA crosses above SMA, it is judged that the upside momentum is strong, go long. When EMA crosses below SMA, it is judged that the downside momentum is strong, go short.
In addition, the strategy also uses the crossover of fast period SMA and slow period SMA to determine the overall trend direction. When fast SMA crosses above slow SMA, it is a golden cross, indicating the market is in long-term uptrend. When fast SMA crosses below slow SMA, it is a death cross, indicating the market is in long-term downtrend.
The strategy identifies long opportunity when EMA crosses above SMA. If it is a golden cross at this time, it means going long is supported by both short-term momentum and long-term trend, which is a better long timing. If it is a death cross, going long is only supported by short-term momentum and against long-term trend, which is a more risky long timing.
Advantage Analysis
- Use MA crossovers to judge price momentum and direction
- Consider both short-term momentum and long-term trend
- Dual indicators confirmation improves reliability
- Adaptable to different periods by adjusting MA parameters
- Customizable to show/hide specific trade signals
Risk Analysis
- MA crossovers have lags, may miss best entry/exit points
- Fixed period SMA cannot reflect price change in real-time
- Wrong crossovers may happen between long/short period MAs
- Long holding may increase capital risk
Risks can be reduced by combining other indicators for signal confirmation, optimizing MA periods, or setting stop loss.
Optimization Directions
- Add other filters like volume, Bollinger Bands etc.
- Add stop loss strategy
- Optimize MA periods
- Optimize capital management
- Consider dynamic position sizing
Conclusion
Overall, this is a relatively stable and reliable trend following strategy. It considers both short-term price momentum and long-term trend direction, generating trading signals through MA crossovers. Compared to single MA strategies, it has higher reliability by combining dual indicators for confirmation. But as a trend following strategy, its parameter optimization and risk control are very important. It needs repeated testing and tuning to truly realize its potential. With continuous optimizations and improvements, this strategy can become a valuable component of a long-term quantitative investment portfolio.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 50 | Momentum Length (EMA=SMA) |
| v_input_2 | 50 | Golden Cross Length (Fast) |
| v_input_3 | 100 | Golden Cross Length (Slow) |
| v_input_4 | true | Show Signals |
| v_input_5 | false | Show MAs |
Source Pine Script
/*backtest
start: 2023-09-19 00:00:00
end: 2023-10-19 00:00:00
period: 1h
basePeriod: 15m
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/
// © Cryptoluc1d
//@version=4
strategy("Equal-Length EMA/SMA Crossover Strategy", initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=25, commission_type=strategy.commission.percent, commission_value=0.2, overlay=true)
// Create inputs
mom_length = input(title="Momentum Length (EMA=SMA)", defval=50)
bias_length_fast = input(title="Golden Cross Length (Fast)", defval=50)
bias_length_slow = input(title="Golden Cross Length (Slow)", defval=100)
// Define MAs
ema = ema(close, mom_length) // EMA/SMA crossover of the same period for detecting trend acceleration/deceleration
sma = sma(close, mom_length)
bias_fast = sma(close, bias_length_fast) // golden/death cross for overall trend bias
bias_slow = sma(close, bias_length_slow)
// Define signal conditions
buy_trend = crossover(ema, sma) and bias_fast >= bias_slow // buy when EMA cross above SMA. if this happens during a bullish golden cross, buying is in confluence with the overall trend (bias).
buy_risky = crossover(ema, sma) and bias_fast < bias_slow // buy when EMA cross above SMA. if this happens during a bearish death cross, buying is early, more risky, and not in confluence with the overall trend (bias).
buy_late = crossover(sma, bias_slow) and ema > sma // the SMA crossing the Slow_SMA gives further confirmation of bullish trend, but signal comes later.
sell = crossunder(ema, sma) // sell when EMA cross under SMA.
// Enable option to hide signals, then plot signals
show_signal = input(title="Show Signals", defval=true)
plotshape(show_signal ? buy_trend : na, title='Trend Buy', style=shape.triangleup, location=location.belowbar, color=color.green, text='TREND BUY')
plotshape(show_signal ? buy_risky : na, title='Risky Buy', style=shape.triangleup, location=location.belowbar, color=color.olive, text='RISKY BUY')
plotshape(show_signal ? buy_late : na, title='Late Buy', style=shape.triangleup, location=location.belowbar, color=color.lime, text='LATE BUY')
plotshape(show_signal ? sell : na, title='Sell', style=shape.triangledown, location=location.abovebar, color=color.red, text='SELL')
// Define entry and exit conditions
longCondition = ema > sma and bias_fast >= bias_slow // LONG when EMA above SMA, and overall trend bias is bullish
if (longCondition)
strategy.entry("BUY TREND", strategy.long)
exitLong = crossunder(ema, sma) // close LONG when EMA cross under SMA
strategy.close("BUY TREND", when=exitLong)
// // short conditions. turned off because up only.
// shortCondition = ema < sma and bias_fast <= bias_slow // SHORT when EMA under SMA, and overall trend bias is bearish
// if (shortCondition)
// strategy.entry("SELL TREND", strategy.short)
// exitShort = crossover(ema, sma) // close SHORT when EMA cross over SMA
// strategy.close("SELL TREND", when=exitShort)
// Enable option to show MAs, then plot MAs
show_ma = input(title="Show MAs", defval=false)
plot(show_ma ? ema : na, title="Momentum EMA", color=color.green, linewidth=1)
plot(show_ma ? sma : na, title="Momentum SMA", color=color.yellow, linewidth=1)
plot(show_ma ? bias_fast : na, title="Golden Cross SMA (Fast)", color=color.orange, linewidth=2)
plot(show_ma ? bias_slow : na, title="Golden Cross SMA (Slow)", color=color.red, linewidth=2)Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-20. 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/Momentum-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
- ADX Momentum Trend StrategyPine Script · Momentum · 10m
- Bollinger Bands Momentum Trend Following Quantitative StrategyPine Script · Momentum · 1d
- Moving Average Candle Regression StrategyPine Script · Momentum · 15m
- Multi Timeframe Unified Strategy Based on Quantitative Momentum and Convergence DivergencePine Script · Momentum · 1d
- Four factor Momentum Tracking Trading Strategy Based on ADX BB B AO and EMAPine Script · Momentum · 1d
- Momentum Indicator Aggregation Trading StrategyPine Script · Momentum · 1h