Strategy vault / Trend following
Quantitative Strategy Based on Dual Exponential Moving Average Crossover
This article explains in detail a quantitative trading strategy based on dual EMA crossover. It sets up fast and slow EMAs and generates signals when they cross over. I. Strategy Logic The core of this strategy is…
This article explains in detail a quantitative trading strategy based on dual EMA crossover. It sets up fast and slow EMAs and generates signals when they cross over.
I. Strategy Logic
The core of this strategy is setting up two EMAs with different parameters, one fast and one slow, and generating buy and sell signals based on their crossover relationship. The specific logic is:
Set up a short-period EMA (e.g. 29 periods) to represent the short-term trend.
Set up a long-period EMA (e.g. 86 periods) to represent the long-term trend.
Go long when the short EMA crosses above the long EMA, and go short when it crosses below.
Currently only entry logic is defined, with no stop loss or take profit.
Trade fixed position sizing.
By using a fast EMA to react to short-term moves and a slow EMA to track the long-term trend, the crossover generates signals that capture the core direction of price changes.
II. Advantages of the Strategy
The biggest advantage of this strategy is its simplicity and ease of implementation. EMA is straightforward to calculate and crossover signals are visually clear.
Secondly, the fast and slow EMA complement each other to track both short and long-term trends simultaneously. The fast EMA moves nimbly while the slow EMA filters out noise.
Lastly, the fixed position sizing also reduces optimization difficulty.
III. Potential Weaknesses
Despite being easy to implement, the following risks should be noted for live trading:
Firstly, EMA crossovers have a lag and may miss the optimal entry point.
Secondly, the lack of a stop loss means losing trades cannot be controlled.
Finally, the lack of a take profit level also makes it hard to manage profit potential.
Additional exit logic needs to be added, with stop loss and take profit conditions.
IV. Summary
In summary, this article has explained a quantitative trading strategy based on dual EMA crossovers. It uses fast and slow EMA combinations to determine trend direction for trade signals. While easy to implement, the strategy also lacks sophistication in optimization. Overall, it can serve as a smoothing trend trading framework but requires proper enhancements to manage risks.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 29 | Small EMA |
| v_input_2 | 86 | Long EMA |
Source Pine Script
/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("EMA Cross Strategy", overlay=true, initial_capital=100, currency="USD", default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.075)
small_ema = input(29, title="Small EMA")
long_ema = input(86, title="Long EMA")
ema1 = ema(close, small_ema)
ema2 = ema(close, long_ema)
longCondition = ema1 > ema2
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = ema1 < ema2
if (shortCondition)
strategy.entry("Short", strategy.short)
//strategy.close("Long", when=close < ema1)
//strategy.close("Short", when=close > ema1)
x1 = plot(ema(close, small_ema), title="EMA 1", color=longCondition?green:shortCondition?red:blue, transp=0, linewidth=0)
x2 = plot(ema(close, long_ema), title="EMA 2", color=longCondition?green:shortCondition?red:blue, transp=0, linewidth=0)
//bgcolor(longCondition?green:shortCondition?red:blue, transp=75)
fill(x1,x2,color=longCondition?green:shortCondition?red:blue)Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-14. 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/Quantitative-Strategy-Based-on-Dual-Exponential-Moving-Average-Crossover.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
- 200 EMA VWAP MFI Trend Following StrategyPine Script · Trend following · 1d
- 4 EMA Trend StrategyPine Script · Trend following · 1d
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- ATR and T3 Moving Average StrategyPine Script · Trend following · 5m