0bps

Strategy vault / Trend following

Dynamic EMA Trend Crossover Entry Quantitative Strategy

This strategy is a quantitative trading system based on the crossover of dual Exponential Moving Averages (EMA). It utilizes a short-term EMA (14 periods) and a long-term EMA (100 periods) to capture market trend…

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

IMG

Overview

This strategy is a quantitative trading system based on the crossover of dual Exponential Moving Averages (EMA). It utilizes a short-term EMA (14 periods) and a long-term EMA (100 periods) to capture market trend transition points by determining entry timing through the intersection of short-term and long-term moving averages. Buy signals are generated when the short-term EMA crosses above the long-term EMA, and sell signals are generated when the opposite occurs. This strategy is particularly suitable for traders looking to position themselves at the beginning of trend reversals.

Strategy Principles

The core logic of the strategy is built on momentum changes in price trends. The short-term EMA is more sensitive to price changes, while the long-term EMA better filters market noise and reflects the primary trend. When the short-term moving average crosses above the long-term moving average, it indicates strengthening short-term momentum and a possible uptrend; when the short-term moving average crosses below the long-term moving average, it suggests weakening momentum and a potential downtrend. The strategy uses ta.crossover and ta.crossunder functions to accurately capture these crossing points and execute position operations at appropriate times.

Strategy Advantages

  1. Clear and simple operational logic, easy to understand and execute
  2. Effectively captures trend initiation points, capitalizing on major market movements
  3. Good risk control capability through automatic stop-loss using moving average crossovers
  4. Utilizes EMA's dynamic characteristics for faster response to price changes
  5. Supports customizable parameters for optimization based on different market characteristics
  6. Features automated execution capability, reducing emotional interference

Strategy Risks

  1. May generate frequent false signals in choppy markets
  2. Moving average crossovers have inherent lag, potentially missing optimal entry points
  3. Possible significant drawdowns in rapidly volatile markets
  4. Improper parameter selection may lead to decreased signal quality
  5. Need to consider the impact of trading costs on strategy returns

Strategy Optimization Directions

  1. Incorporate volume indicators as confirmatory signals
  2. Add trend strength filters to reduce false breakout risks
  3. Optimize moving average period parameters for specific markets
  4. Implement dynamic stop-loss mechanisms to enhance risk control
  5. Integrate other technical indicators to improve signal reliability
  6. Develop adaptive parameter mechanisms to enhance strategy adaptability

Summary

The Dynamic EMA Trend Crossover Entry Quantitative Strategy is a classic and practical trend-following system. By combining short-term and long-term exponential moving averages, the strategy effectively captures market trend transition opportunities. While there are risks of lag and false signals, stable trading results can still be achieved through appropriate parameter optimization and risk control measures. The strategy's simplicity and scalability make it an excellent foundation framework for quantitative trading.

Source Pine Script

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

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

// Input for EMAs
shortEmaLength = input(14, title="Short EMA Length")
longEmaLength = input(100, 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="100 EMA")

// Historical Signal Tracking
var float lastBuyPrice = na
var float lastSellPrice = na

// Buy and Sell Signals
buySignal = ta.crossover(shortEma, longEma)
sellSignal = ta.crossunder(shortEma, longEma)

// Track last buy and sell prices
if (buySignal)
    lastBuyPrice := close

if (sellSignal)
    lastSellPrice := close

// Plot buy and sell signals on the chart
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Strategy Logic
if (buySignal)
    strategy.entry("Buy", strategy.long)

if (sellSignal)
    strategy.close("Buy")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-12-13. 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/Dynamic-EMA-Trend-Crossover-Entry-Quantitative-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