Strategy vault / Trend following
Multi EMA Trend Following Trading Strategy
This strategy is a trend following trading system based on multiple Exponential Moving Averages (EMAs). By utilizing three EMAs with different periods (10, 30, 50), combined with price crossovers and trend direction…

Overview
This strategy is a trend following trading system based on multiple Exponential Moving Averages (EMAs). By utilizing three EMAs with different periods (10, 30, 50), combined with price crossovers and trend direction analysis, it constructs a complete buy and sell signal system. The strategy thoroughly considers trend formation, confirmation, and reversal, effectively capturing major trending opportunities in the market.
Strategy Principle
The strategy employs a hierarchical judgment mechanism to determine trading signals:
- Trend Determination Layer: Uses the relative positions of three EMAs (10/30/50) to judge trend direction. An uptrend is identified when EMA10 > EMA30 > EMA50; a downtrend when EMA50 > EMA30 > EMA10.
- Signal Trigger Layer: Once a trend is established, trading signals are triggered by price crossovers with EMA30. Upward crosses trigger buy signals, downward crosses trigger sell signals.
- Position Management Layer: When EMA30 crosses EMA50 in the opposite direction, it triggers corresponding position closing signals, providing a systematic exit mechanism.
Strategy Advantages
- Multiple Confirmation Mechanism: Multiple line arrangements and crossovers provide multiple confirmations, reducing false signal interference.
- Strong Trend Following: Effectively captures major trends while filtering short-term fluctuations.
- Systematic Approach: Clear entry and exit conditions, minimizing subjective judgment.
- Good Adaptability: Can adapt to different market environments through EMA parameter adjustments.
- Reasonable Risk Control: Timely stop-loss through trend reversal signals.
Strategy Risks
- Sideways Market Risk: May generate frequent false signals during market consolidation, leading to consecutive losses.
- Lag Risk: EMA systems have inherent lag, potentially missing important price opportunities at trend beginnings.
- Gap Risk: May encounter significant price gaps during volatile periods, affecting strategy performance.
- Parameter Sensitivity: Different parameter combinations may lead to significant performance variations.
Strategy Optimization Directions
- Incorporate Volatility Indicators: Suggest adding ATR or similar indicators for dynamic position sizing and improved capital efficiency.
- Optimize Signal Filtering: Can add volume, momentum, or other auxiliary indicators to filter false signals.
- Improve Stop-Loss Mechanism: Recommend adding trailing stop-loss functionality for better profit protection.
- Add Time Filters: Consider adding trading time restrictions to avoid highly volatile periods.
- Parameter Adaptation: Consider introducing adaptive mechanisms for dynamic EMA parameter adjustment based on market conditions.
Summary
This is a well-designed trend following strategy with clear logic. The combination of multiple EMAs ensures both strategy stability and clear trading signals. While there are some inherent lag risks, the strategy demonstrates good practical value through reasonable optimization and risk control measures. It is particularly suitable for traders seeking stable returns with controlled risk.
Source Pine Script
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-09 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © banyat6913
//@version=5
strategy("EMA Trend Strategy", overlay=true)
// Input Parameters
ema_short_length = input.int(10, title="EMA Short Length", minval=1)
ema_mid_length = input.int(30, title="EMA Mid Length", minval=1)
ema_long_length = input.int(50, title="EMA Long Length", minval=1)
// Calculate EMA
ema_short = ta.ema(close, ema_short_length)
ema_mid = ta.ema(close, ema_mid_length)
ema_long = ta.ema(close, ema_long_length)
// **TREND UP**
// 1. EMA 10 > EMA 30 > EMA 50
uptrend_condition = ema_short > ema_mid and ema_mid > ema_long
// 2. Bullish Candle Crossing Up EMA 30
bullish_candle = close > open
cross_up_ema_mid = ta.crossover(close, ema_mid)
// 3. If EMA 30 crosses down EMA 50 -> Close Buy Order
ema_30_cross_down_50 = ta.crossunder(ema_mid, ema_long)
// Buy Signal
buy_signal = uptrend_condition and cross_up_ema_mid
// Sell Signal for closing Buy Order
close_buy_signal = ema_30_cross_down_50
// **TREND DOWN**
// 1. EMA 50 > EMA 30 > EMA 10
downtrend_condition = ema_long > ema_mid and ema_mid > ema_short
// 2. Bearish Candle Crossing Down EMA 30
bearish_candle = close < open
cross_down_ema_mid = ta.crossunder(close, ema_mid)
// 3. If EMA 30 crosses up EMA 50 -> Close Sell Order
ema_30_cross_up_50 = ta.crossover(ema_mid, ema_long)
// Sell Signal
sell_signal = downtrend_condition and cross_down_ema_mid
// Buy Signal for closing Sell Order
close_sell_signal = ema_30_cross_up_50
// Backtesting Logic
if (buy_signal)
strategy.entry("Buy", strategy.long)
if (close_buy_signal)
strategy.close("Buy")
if (sell_signal)
strategy.entry("Sell", strategy.short)
if (close_sell_signal)
strategy.close("Sell")
// Plot EMA Lines
plot(ema_short, color=color.blue, title="EMA 10")
plot(ema_mid, color=color.orange, title="EMA 30")
plot(ema_long, color=color.green, title="EMA 50")
// Plot Buy and Sell Signals on Chart
plotshape(buy_signal, style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), text="BUY", title="Buy Signal")
plotshape(close_buy_signal, style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), text="CLOSE BUY", title="Close Buy Signal")
plotshape(sell_signal, style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), text="SELL", title="Sell Signal")
plotshape(close_sell_signal, style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), text="CLOSE SELL", title="Close Sell Signal")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-12-11. 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/Multi-EMA-Trend-Following-Trading-Strategy.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
- 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
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m