Strategy vault / Trend following
Multiple Timeframe EMA Trend Following Trading Strategy
This strategy is a trend following and breakout trading strategy based on multiple timeframe exponential moving averages (EMA). It combines 5 EMAs with different periods and has strong capabilities in trend…

Overview
This strategy is a trend following and breakout trading strategy based on multiple timeframe exponential moving averages (EMA). It combines 5 EMAs with different periods and has strong capabilities in trend identification to catch medium-to-long term price movements along the trend.
Strategy Logic
Calculate 5 EMAs with periods of 12, 15, 18, 21 and 24 respectively.
EMA ranking rule: EMA12 > EMA15 > EMA18 > EMA21 > EMA24 as buy signal; EMA12 < EMA15 < EMA18 < EMA21 < EMA24 as sell signal.
Trigger trading signals only after the user-defined start date.
Long entry when buy signal triggered; short entry when sell signal triggered.
The strategy forms a trend channel using multiple EMAs to determine the trend direction based on the relationship between the channel bands. The EMA periods are set close to be more sensitive to breakout signals, while also avoiding being misled by short-term market noise. Also, allowing users to customize the start date provides more flexibility.
Advantage Analysis
Strong capabilities in trend identification using multiple EMAs as the trend channel.
Close EMA period setting makes it sensitive to trend breakout signals and able to catch mid-to-long term trends timely.
Customizable start date provides flexibility in use.
Customizable capital management to control per order size.
Clear and simple trading rules, suitable for trend following.
Risk Analysis
EMAs inherently have lagging effect, may miss short-term sharp price swings.
Breakout trading is prone to being trapped, requiring reasonable stop loss.
Potential huge loss when trend reverses.
Need to choose suitable products, not applicable to extremely volatile stocks.
Corresponding risk management and optimizations:
Fine tune EMA parameters, optimize period combination.
Add other indicators for trend direction validation.
Set proper stop loss to control per order loss.
Optimization Directions
Add other indicators like MACD, KDJ to improve strategy performance.
Add trading volume condition to avoid false breakout.
Optimize EMA periods to find the best combination.
Stop trading at specific time range to avoid market turbulence periods.
Use machine learning methods to dynamically optimize EMA periods and parameters.
Conclusion
In general, this is a typical trend following strategy. It capitalizes on the advantages of EMAs by forming a trading channel using multiple EMAs and generating trading signals when price breaks out of the channel. The pros are simple and clear trading rules which make it easy to follow mid-to-long term trends. The cons are sensitivity to short-term market noise and inherent lagging effect. Proper parameter tuning and optimizations like adding other assisting tools can improve the stability and performance. It suits investors with some trading experience.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | timestamp(2024-02-01) | Start Date |
Source Pine Script
/*backtest
start: 2024-01-26 00:00:00
end: 2024-02-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="Scalping Strategy - EMA",
shorttitle="EMA Scalp",
overlay=true)
// User input for start date
startDateInput = input(title="Start Date", defval=timestamp("2024-02-01"))
// Calculate EMAs
ema_12 = ta.ema(close, 12)
ema_15 = ta.ema(close, 15)
ema_18 = ta.ema(close, 18)
ema_21 = ta.ema(close, 21)
ema_24 = ta.ema(close, 24)
// Plot EMAs
plot(ema_12, color=color.red, title="EMA 12")
plot(ema_15, color=color.orange, title="EMA 15")
plot(ema_18, color=color.yellow, title="EMA 18")
plot(ema_21, color=color.green, title="EMA 21")
plot(ema_24, color=color.blue, title="EMA 24")
// Define a start date for the strategy based on user input
isAfterStartDate = true
// Visualize the isAfterStartDate condition
bgcolor(isAfterStartDate ? color.new(color.green, 90) : na, title="After Start Date")
// Entry conditions
buy_condition = (ema_12 > ema_15) and (ema_15 > ema_18) and (ema_18 > ema_21) and (ema_21 > ema_24) and isAfterStartDate
sell_condition = (ema_12 < ema_15) and (ema_15 < ema_18) and (ema_18 < ema_21) and (ema_21 < ema_24) and isAfterStartDate
// Execute trades using conditional blocks
if (buy_condition)
strategy.entry("Buy", strategy.long)
if (sell_condition)
strategy.entry("Sell", strategy.short)Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-26. 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/Multiple-Timeframe-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
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Advanced Multi Indicator Multi Dimensional Trend Cross Quantitative StrategyPine Script · Trend following · 3h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Crossover EMA Short term Trading StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual EMA Crossover Oscillation Tracking StrategyPine Script · Trend following · 5m