0bps

Strategy vault / Momentum

EMA Crossover Momentum Trend Following Strategy Dual EMA Crossover Momentum Trend Following Strategy

This strategy is a trend following trading system based on the crossover signals of 9-day and 20-day Exponential Moving Averages (EMA). It captures market trend reversals by monitoring the crossover relationship…

Author
ChaoZhang
Complexity
Starter · 41 lines
Parameters
0
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is a trend following trading system based on the crossover signals of 9-day and 20-day Exponential Moving Averages (EMA). It captures market trend reversals by monitoring the crossover relationship between the fast EMA (9-day) and slow EMA (20-day). The strategy employs programmatic trading to achieve fully automated operation, effectively avoiding human emotional interference.

Strategy Principle

The core of the strategy uses two EMAs with different periods to identify trend direction and turning points. When the 9-day EMA crosses above the 20-day EMA, the system generates a long signal; when the 9-day EMA crosses below the 20-day EMA, the system generates a short signal. EMAs assign greater weight to recent prices, enabling quick response to price changes and timely capture of trend reversals.

Strategy Advantages

  1. Clear operational rules with fully programmatic execution, avoiding emotional interference
  2. Uses exponential moving average calculation method for sensitive market response
  3. Includes trading alert functionality for timely trader notification
  4. Clear code structure, easy to maintain and optimize
  5. Applicable to different markets and time periods
  6. Strong trend following capability

Strategy Risks

  1. May generate frequent false signals in ranging markets
  2. Potential delay in entry timing
  3. Lack of stop-loss and take-profit mechanisms
  4. Trading costs not considered
  5. May underperform in highly volatile markets
  6. Requires attention to money management

Strategy Optimization Directions

  1. Add stop-loss and take-profit mechanisms for risk control
  2. Incorporate volume indicators to improve signal reliability
  3. Include trend filters to reduce false signals in ranging markets
  4. Optimize EMA parameters for better strategy adaptability
  5. Add volatility indicators to optimize trading timing
  6. Design position management module to improve risk-reward ratio

Summary

This strategy is a classical trend following system that captures trend reversal opportunities through EMA crossovers. The strategy logic is simple and clear, making it easy to understand and implement. However, for live trading, it is recommended to combine it with other technical indicators and money management methods to further improve the trading system. Additionally, optimizing parameters according to different market characteristics can enhance the strategy's practicality.

Source Pine Script

/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-04 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("EMA Crossover Strategy with Buttons", overlay=true)

// Input parameters for EMAs
shortEmaLength = input(9, title="Short EMA Length")
longEmaLength = input(20, title="Long EMA Length")

// Calculate EMAs
shortEma = ta.ema(close, shortEmaLength)
longEma = ta.ema(close, longEmaLength)

// Plot EMAs
plot(shortEma, color=color.blue, title="9 EMA")
plot(longEma, color=color.red, title="20 EMA")

// Buy and Sell Logic
longCondition = ta.crossover(shortEma, longEma)
shortCondition = ta.crossunder(shortEma, longEma)

// Buy Button
if (ta.change(longCondition))
    if (longCondition)
        strategy.entry("Buy", strategy.long)

// Sell Button
if (ta.change(shortCondition))
    if (shortCondition)
        strategy.entry("Sell", strategy.short)

// Alert Conditions
alertcondition(longCondition, title="Buy Alert", message="Buy Signal")
alertcondition(shortCondition, title="Sell Alert", message="Sell Signal")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-12-05. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/EMA-Crossover-Momentum-Trend-Following-Strategy-Dual-EMA-Crossover-Momentum-Trend-Following-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open