Strategy vault / Trend following
Trend Following Strategy Based on Dual EMA
This strategy is named "Trend Following Strategy Based on Dual EMA". It calculates two EMA lines of different periods and judges trend direction based on their relationship, to follow trends. Specifically, the…
This strategy is named "Trend Following Strategy Based on Dual EMA". It calculates two EMA lines of different periods and judges trend direction based on their relationship, to follow trends.
Specifically, the trading logic is:
Calculate the 50-day EMA and 200-day EMA.
When the 50-day EMA crosses above the 200-day EMA, it signals an uptrend, thus going long.
When the 50-day EMA crosses below the 200-day EMA, it flags a downtrend, thus going short.
When trend reversal happens, existing positions are closed and direction is switched to the new trend.
The advantage of this strategy is using EMA "golden cross" and "dead cross" to determine the main trend direction. But EMA lagging requires parameter optimization, plus stop loss to manage risks.
In general, the dual EMA strategy suits mid-to-long term positioning by timely capturing major trend reversals for trend following. But traders still need to watch more indicators and maintain flexibility in strategy adjustment.
Source Pine Script
/*backtest
start: 2023-08-13 00:00:00
end: 2023-09-12 00:00:00
period: 2h
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/
// © Sonu1997
//@version=4
//@version=5
strategy('moving average strategy', overlay=true)
ema50 =ema(close, 50)
ema200 =ema(close, 200)
long = ema50 > ema200
short = ema50 < ema200
strategy.entry('long', strategy.long, 0, when=long)
strategy.entry('short', strategy.short, 0, when=short)
strategy.close('long', when=short)
strategy.close('short', when=long)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Trend-Following-Strategy-Based-on-Dual-EMA.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