Strategy vault / Trend following
Multi EMA Crossover Trend Following Strategy 454747
This strategy is a trend-following approach based on multiple Exponential Moving Average (EMA) crossovers. It utilizes 20-day, 50-day, and 100-day EMAs to determine market trends and executes buy and sell operations…

Overview
This strategy is a trend-following approach based on multiple Exponential Moving Average (EMA) crossovers. It utilizes 20-day, 50-day, and 100-day EMAs to determine market trends and executes buy and sell operations when specific conditions are met. The strategy aims to capture medium to long-term trends while improving signal reliability through multi-timeframe crossovers.
Strategy Principles
Buy Conditions:
- Current closing price is above the 20-day, 50-day, and 100-day EMAs
- This condition must be met for two consecutive days to trigger a buy signal
Sell Conditions:
- Closing price falls below any of the 20-day, 50-day, or 100-day EMAs
- Or when the strategy's net profit reaches 20%
Strategy Logic:
- Uses the ta.ema() function to calculate the three EMA lines
- Tracks the consecutive fulfillment of buy conditions using variables
- Executes strategy.entry() for buying when buy conditions are met
- Executes strategy.close() for selling when sell conditions are met
Strategy Advantages
Multi-timeframe Confirmation: Using three different period EMAs provides more reliable trend confirmation, reducing false breakouts.
Consecutive Confirmation Mechanism: Requiring buy conditions to be met for two consecutive days can reduce false signals in choppy markets.
Trend Following: By following the direction of price breakouts above EMAs, the strategy can capture medium to long-term trends.
Risk Management: Setting a 20% profit target allows for timely profit-taking.
Flexible Exit Mechanism: Exiting when the price falls below any EMA helps in timely stop-loss.
Visualization: The strategy plots the three EMA lines on the chart, facilitating intuitive market analysis.
Strategy Risks
Lag: EMAs inherently have some lag, which may lead to delayed entry and exit timing.
Poor Performance in Ranging Markets: In sideways markets, the strategy may generate frequent false signals.
Fixed Percentage Take Profit: The 20% fixed take-profit may lead to early exits in strong trends.
Lack of Stop-Loss Mechanism: The strategy doesn't have a clear stop-loss setting, potentially leading to significant losses in case of sharp reversals.
Parameter Sensitivity: The choice of EMA periods can significantly impact strategy performance.
Strategy Optimization Directions
Introduce Adaptive EMAs: Consider using adaptive EMAs to dynamically adjust moving average periods to suit different market environments.
Incorporate Quantitative Indicators: Combining RSI, MACD, or other indicators can improve entry and exit accuracy.
Optimize Take-Profit and Stop-Loss: Consider using trailing stops or ATR-based dynamic stops to optimize risk management.
Market Environment Filtering: Add trend strength indicators like ADX to execute trades only in strong trend markets.
Phased Position Building and Reduction: Consider establishing and closing positions in multiple phases to reduce single price point risk.
Backtesting Optimization: Conduct backtests on different EMA period combinations to find optimal parameters.
Add Volume Conditions: Consider adding volume confirmation to improve signal reliability.
Conclusion
The Multi-EMA Crossover Trend Following Strategy is a medium to long-term trend following system that combines multiple timeframes. By requiring price breakouts above multiple EMAs with consecutive confirmation, the strategy enhances signal reliability. However, it also has some inherent limitations, such as performance in ranging markets and potential lag. The strategy can be further improved by introducing more technical indicators, optimizing take-profit and stop-loss mechanisms, adding market environment filters, and other methods to enhance stability and profitability. In practical application, thorough backtesting and parameter optimization are necessary, and appropriate adjustments should be made based on specific trading instruments and market characteristics.
Source Pine Script
/*backtest
start: 2023-06-15 00:00:00
end: 2024-06-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Strategy", overlay=true)
// Define EMAs
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
// Variables to track consecutive days condition
var bool buy_condition = false
var bool prev_buy_condition = false
// Buy condition logic
if (close > ema20 and close > ema50 and close > ema100)
prev_buy_condition := buy_condition
buy_condition := true
else
buy_condition := false
// Buy only if condition is true for 2 consecutive days
buy_signal = buy_condition and prev_buy_condition
// Sell conditions
sell_condition = close < ema20 or close < ema50 or close < ema100 or strategy.netprofit / strategy.equity * 100 >= 20
// Plot EMAs
plot(ema20, color=color.blue, title="EMA 20")
plot(ema50, color=color.red, title="EMA 50")
plot(ema100, color=color.green, title="EMA 100")
// Execute strategy orders
if (buy_signal)
strategy.entry("Buy", strategy.long)
if (sell_condition)
strategy.close("Buy")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-06-21. 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-Crossover-Trend-Following-Strategy-454747.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
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dynamic Dual EMA Crossover Strategy with Adaptive Profit Loss ControlPine Script · Trend following · 1d
- EMA SMA Multi Indicator Comprehensive Trend Following StrategyPine Script · Trend following · 1h