Strategy vault / Trend following
Adaptive Trend Following Strategy Based on Dual EMA Crossover System
This strategy is a trend following trading system based on the crossover of fast and slow Exponential Moving Averages (EMA). It generates more reliable buy and sell signals by confirming price position relative to…

Overview
This strategy is a trend following trading system based on the crossover of fast and slow Exponential Moving Averages (EMA). It generates more reliable buy and sell signals by confirming price position relative to both EMAs. The strategy includes customizable backtesting timeframe settings for performance evaluation within specific periods.
Strategy Principle
The strategy utilizes 10-period and 20-period EMAs as core indicators. A long signal is triggered when the fast EMA crosses above the slow EMA and the closing price is above both EMAs; a short signal is triggered when the fast EMA crosses below the slow EMA and the closing price is below both EMAs. This dual confirmation mechanism enhances signal reliability.
Strategy Advantages
- Signal confirmation mechanism reduces false breakouts and improves trading accuracy
- EMAs provide more sensitive response to market trend changes
- Customizable backtesting timeframe facilitates strategy optimization
- Clear visual markers for intuitive trading decisions
- Applicable to various market conditions and trading instruments
Strategy Risks
- Choppy markets may generate frequent false signals
- Improper EMA parameter settings can lead to excessive lag
- Rapid market reversals may cause significant drawdowns
- Proper stop-loss settings are necessary for risk control
- Trading costs may impact overall strategy returns
Strategy Optimization Directions
- Incorporate volatility indicators to adjust EMA parameters for better adaptability
- Add volume confirmation mechanism to enhance signal reliability
- Implement trend strength filters to reduce false signals in ranging markets
- Optimize stop-loss and take-profit mechanisms to improve risk-reward ratio
- Consider adding market state detection for strategy adaptation
Summary
This is a well-structured and logically rigorous trend following strategy. By combining dual EMA crossover with price confirmation mechanism, it effectively balances signal timeliness and reliability. The strategy offers good scalability and can be further enhanced through optimization. It serves as an excellent foundation for medium to long-term trend following trading frameworks.
Source Pine Script
/*backtest
start: 2024-02-21 00:00:00
end: 2024-10-01 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"BNB_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BFXGold
//@version=5
strategy("BFX Buy and Sell", overlay=true)
// Inputs
ema_fast_length = input.int(10, title="Fast EMA Length")
ema_slow_length = input.int(20, title="Slow EMA Length")
// Calculate EMAs
ema_fast = ta.ema(close, ema_fast_length)
ema_slow = ta.ema(close, ema_slow_length)
// Confirmation candles
confirmation_above = close > ema_fast and close > ema_slow
confirmation_below = close < ema_fast and close < ema_slow
// Crossovers with confirmation
long_condition = ta.crossover(ema_fast, ema_slow) and confirmation_above
short_condition = ta.crossunder(ema_fast, ema_slow) and confirmation_below
// Plot signals
if (long_condition )
label.new(bar_index, low, text="BUY", style=label.style_label_up, color=color.new(color.green, 0), textcolor=color.white)
if (short_condition)
label.new(bar_index, high, text="SELL", style=label.style_label_down, color=color.new(color.red, 0), textcolor=color.white)
// Strategy execution for backtesting
if (long_condition)
strategy.entry("Long", strategy.long)
if (short_condition)
strategy.entry("Short", strategy.short)
// Plot EMAs
plot(ema_fast, title="Fast EMA (10)", color=color.blue, linewidth=1)
plot(ema_slow, title="Slow EMA (20)", color=color.orange, linewidth=1)
Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-27. 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/Adaptive-Trend-Following-Strategy-Based-on-Dual-EMA-Crossover-System.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
- CM Multiple EMA Crossover StrategyPine Script · Trend following · 6h
- Dynamic Dual EMA Trend Following StrategyPine Script · Trend following · 1d
- EMA 200 Crossover with Volume and Trend StrategyPine Script · Trend following · 1d
- EMA SMA Trend Following with Swing Trading Strategy Combined Volume Filter and Percentage Take Profit Stop Loss SystemPine Script · Trend following · 1d
- Fixed Range Volume Profile And Anchored VWAP Trend Identification Strategy With Dynamic Stop LossPine Script · Trend following · 1h
- Multi Exponential Moving Average Crossover Strategy with Volume Based ATR Dynamic Stop Loss OptimizationPine Script · Trend following · 2d