Dynamic Trend Momentum Crossover Strategy Quantitative Trading System Based on Dual EMA and MACD Indicators
This strategy is a quantitative trading system that combines Exponential Moving Averages (EMA) and Moving Average Convergence Divergence (MACD) indicators. By integrating crossover signals from short-term and…

Overview
This strategy is a quantitative trading system that combines Exponential Moving Averages (EMA) and Moving Average Convergence Divergence (MACD) indicators. By integrating crossover signals from short-term and long-term EMAs with MACD momentum confirmation, it provides traders with a comprehensive trend-following solution. The strategy also includes dynamic stop-loss and take-profit mechanisms for effective risk control while maximizing potential returns.
Strategy Principles
The core logic is based on the synergy of two technical indicators. First, it uses 12-period and 26-period EMAs to identify market trends, generating long signals when the short-term EMA crosses above the long-term EMA, and short signals when it crosses below. Second, it uses the MACD indicator (12,26,9 settings) to confirm trend momentum, requiring the MACD line and Signal line relationship to support the EMA-generated trading signals. The system employs percentage-based dynamic stop-loss (default 2%) and take-profit (default 5%) levels, with additional exit signals triggered by EMA crossovers or MACD reversals.
Strategy Advantages
- Robust signal confirmation: Dual confirmation through EMA crossovers and MACD momentum significantly reduces false breakout risks
- Flexible risk management: Percentage-based stop-loss and take-profit levels easily adaptable to different market conditions and instruments
- Excellent visualization: Clear display of EMA lines, MACD indicator, and trade signal markers on charts
- Strong parameterization: Allows adjustment of EMA periods, MACD parameters, and risk control ratios to adapt to different trading strategies
Strategy Risks
- Trend reversal risk: May generate frequent crossovers in ranging markets, leading to false signals
- Lagging indicator issue: Both EMA and MACD are lagging indicators, potentially missing optimal entry points in fast-moving markets
- Money management risk: Fixed percentage stops may not be flexible enough in high-volatility environments
- Parameter optimization risk: Over-optimization may lead to poorer live trading performance compared to backtests
Optimization Directions
- Incorporate volatility indicators: Suggest adding ATR indicator for dynamic stop-loss and take-profit adjustments
- Add market environment filters: Consider using ADX or similar indicators to gauge trend strength and avoid ranging markets
- Enhance signal confirmation: Consider adding volume confirmation or other momentum indicators as auxiliary signals
- Improve money management: Implement dynamic position sizing based on account equity
Summary
This is a well-designed, logically sound trend-following strategy. By combining the strengths of EMA and MACD, it achieves a reliable trade signal generation mechanism while maintaining simplicity and clarity. The strategy offers strong customization options and robust risk management mechanisms, making it suitable as a foundation for medium to long-term trend trading. Traders are advised to thoroughly test parameter settings and optimize the strategy according to specific trading instruments and market conditions before live implementation.
Source Pine Script
/*backtest
start: 2025-01-21 00:00:00
end: 2025-02-03 15:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("EMA + MACD Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === Inputs ===
shortEmaLength = input.int(12, title="Short EMA Period", minval=1)
longEmaLength = input.int(26, title="Long EMA Period", minval=1)
macdFastLength = input.int(12, title="MACD Fast EMA Period", minval=1)
macdSlowLength = input.int(26, title="MACD Slow EMA Period", minval=1)
macdSignalLength = input.int(9, title="MACD Signal Period", minval=1)
stopLossPerc = input.float(2.0, title="Stop-Loss (%)", minval=0.1, step=0.1)
takeProfitPerc = input.float(5.0, title="Take-Profit (%)", minval=0.1, step=0.1)
// === Indicator Calculations ===
// Exponential Moving Averages (EMA)
shortEMA = ta.ema(close, shortEmaLength)
longEMA = ta.ema(close, longEmaLength)
// MACD
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
// === Entry Conditions ===
// Buy signal: Short EMA crosses above Long EMA and MACD > Signal Line
longCondition = ta.crossover(shortEMA, longEMA) and (macdLine > signalLine)
// Sell signal: Short EMA crosses below Long EMA and MACD < Signal Line
shortCondition = ta.crossunder(shortEMA, longEMA) and (macdLine < signalLine)
// === Entry Signals with Stop-Loss and Take-Profit ===
if (longCondition)
strategy.entry("Long", strategy.long)
// Calculate Stop-Loss and Take-Profit
stopPrice = close * (1 - stopLossPerc / 100)
takePrice = close * (1 + takeProfitPerc / 100)
strategy.exit("Long Exit", from_entry="Long", stop=stopPrice, limit=takePrice)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Calculate Stop-Loss and Take-Profit
stopPrice = close * (1 + stopLossPerc / 100)
takePrice = close * (1 - takeProfitPerc / 100)
strategy.exit("Short Exit", from_entry="Short", stop=stopPrice, limit=takePrice)
// === Exit Conditions ===
// Alternative exit conditions based on crossovers
exitLongCondition = ta.crossunder(shortEMA, longEMA) or (macdLine < signalLine)
exitShortCondition = ta.crossover(shortEMA, longEMA) or (macdLine > signalLine)
if (exitLongCondition)
strategy.close("Long")
if (exitShortCondition)
strategy.close("Short")
// === Indicator Plotting ===
// EMA
plot(shortEMA, color=color.blue, title="Short EMA")
plot(longEMA, color=color.red, title="Long EMA")
// MACD Indicator in separate window
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dotted)
plot(macdLine - signalLine, color=(macdLine - signalLine) >= 0 ? color.green : color.red, title="MACD Histogram", style=plot.style_histogram)
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
// === Signal Visualization ===
// Markers for Long and Short entries
plotshape(series=longCondition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.labelup, text="Long")
plotshape(series=shortCondition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.labeldown, text="Short")
// Markers for Long and Short exits
plotshape(series=exitLongCondition, title="Long Exit", location=location.abovebar, color=color.red, style=shape.labeldown, text="Exit Long")
plotshape(series=exitShortCondition, title="Short Exit", location=location.belowbar, color=color.green, style=shape.labelup, text="Exit Short")
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/Dynamic-Trend-Momentum-Crossover-Strategy-Quantitative-Trading-System-Based-on-Dual-EMA-and-MACD-Indicators.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
- Multi Indicator Dynamic Stop Loss Momentum Trend Trading StrategyPine Script · Momentum · 1h
- Advanced Multi Indicator Trend Following and Momentum Quantitative Trading StrategyPine Script · Momentum · 1h
- KST EMA Momentum Trend Following StrategyPine Script · Momentum · 1d
- Multi Indicator Trend Momentum Trading Strategy with Dynamic Risk Management SystemPine Script · Momentum · 1h
- Multi Technical Indicator Based Trend Following and Momentum StrategyPine Script · Momentum · 1d
- Advanced EMA Crossover Momentum Trend Capture StrategyPine Script · Momentum · 2h