Strategy vault / Trend following
Dynamic EMA Crossover Strategy with ADX Trend Strength Filtering System
This strategy is a trend-following trading system that combines the Exponential Moving Average (EMA) and Average Directional Index (ADX). It determines trading direction through EMA50 and price crossovers, uses ADX…

Overview
This strategy is a trend-following trading system that combines the Exponential Moving Average (EMA) and Average Directional Index (ADX). It determines trading direction through EMA50 and price crossovers, uses ADX to filter trend strength, and employs a dynamic stop-loss method based on consecutive profitable candles. This approach enables both capturing major market trends and timely exits when trends weaken.
Strategy Principles
The core logic is based on the following key elements:
- Uses 50-period EMA (EMA50) as trend direction indicator
- Filters market trend strength using ADX indicator (default parameter 20)
- Entry conditions:
- Long: Price closes above EMA50 and ADX above threshold
- Short: Price closes below EMA50 and ADX above threshold
- Unique stop-loss mechanism:
- Counts consecutive profitable candles
- Activates dynamic trailing stop after 4 consecutive profitable candles
- Stop-loss level adjusts dynamically with new highs/lows
Strategy Advantages
- Dual Trend Confirmation
- EMA crossover provides trend direction
- ADX filtering ensures trend strength, reduces false breakouts
- Intelligent Stop-Loss Design
- Dynamic stops based on market volatility
- Trailing stop activated only after consecutive profits
- High Adaptability
- Highly adjustable parameters
- Applicable to multiple trading instruments
- Comprehensive Risk Control
- Automatic exit on trend weakness
- Dynamic stops protect existing profits
Strategy Risks
- Trend Reversal Risk
- May face significant drawdowns during sudden reversals
- Recommend adding reversal confirmation mechanism
- Parameter Sensitivity
- Strategy performance affected by EMA and ADX parameter choice
- Recommend parameter optimization through backtesting
- Market Environment Dependency
- May trade frequently in ranging markets
- Recommend adding sideways market filter
- Stop-Loss Execution Risk
- Large gaps may cause stop-loss execution deviation
- Consider implementing hard stop-loss protection
Optimization Directions
- Entry Mechanism Enhancement
- Add volume confirmation signals
- Incorporate price pattern analysis
- Stop-Loss Mechanism Improvement
- Integrate ATR for dynamic stop-loss adjustment
- Add time-based stop-loss mechanism
- Market Environment Adaptation
- Add market volatility filters
- Adjust parameters for different market cycles
- Signal Confirmation Enhancement
- Integrate additional technical indicators
- Add fundamental filtering conditions
Summary
This is a well-designed trend-following strategy that effectively captures trends while controlling risks by combining the advantages of EMA and ADX. The dynamic stop-loss mechanism is particularly innovative, effectively balancing profit protection and trend capture. While there is room for optimization, the overall framework is complete and logically sound, making it a strategy system worth validating in live trading.
Source Pine Script
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Simple EMA 50 Strategy with ADX Filter", overlay=true)
// Input parameters
emaLength = input.int(50, title="EMA Length")
adxThreshold = input.float(20, title="ADX Threshold", minval=0)
// Calculate EMA and ADX
ema50 = ta.ema(close, emaLength)
adxSmoothing = input.int(20, title="ADX Smoothing")
[diPlus, diMinus, adx] = ta.dmi(20, adxSmoothing)
// Conditions for long and short entries
adxCondition = adx > adxThreshold
longCondition = adxCondition and close > ema50 // Check if candle closes above EMA
shortCondition = adxCondition and close < ema50 // Check if candle closes below EMA
// Exit conditions based on 4 consecutive profitable candles
var float longSL = na
var float shortSL = na
var longCandleCounter = 0
var shortCandleCounter = 0
// Increment counters if positions are open and profitable
if (strategy.position_size > 0 and close > strategy.position_avg_price)
longCandleCounter += 1
if (longCandleCounter >= 4)
longSL := na(longSL) ? close : math.max(longSL, close) // Update SL dynamically
else
longCandleCounter := 0
longSL := na
if (strategy.position_size < 0 and close < strategy.position_avg_price)
shortCandleCounter += 1
if (shortCandleCounter >= 4)
shortSL := na(shortSL) ? close : math.min(shortSL, close) // Update SL dynamically
else
shortCandleCounter := 0
shortSL := na
// Exit based on trailing SL
if (strategy.position_size > 0 and not na(longSL) and close < longSL)
strategy.close("Buy", comment="Candle-based SL")
if (strategy.position_size < 0 and not na(shortSL) and close > shortSL)
strategy.close("Sell", comment="Candle-based SL")
// Entry logic: Check every candle for new positions
if (longCondition)
strategy.entry("Buy", strategy.long)
if (shortCondition)
strategy.entry("Sell", strategy.short)
// Plot EMA and ADX for reference
plot(ema50, color=color.blue, title="EMA 50")
plot(adx, color=color.orange, title="ADX", style=plot.style_stepline, linewidth=1)
plot(longSL, color=color.green, title="Long SL", style=plot.style_cross, linewidth=1)
plot(shortSL, color=color.red, title="Short SL", style=plot.style_cross, linewidth=1)
// Plot signals
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")
Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-06. 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/Dynamic-EMA-Crossover-Strategy-with-ADX-Trend-Strength-Filtering-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
- Multi Exponential Moving Average Crossover Strategy with Volume Based ATR Dynamic Stop Loss OptimizationPine Script · Trend following · 2d
- Multi Factor Trend Price Action Strategy with Dynamic Risk Management SystemPine Script · Trend following · 2h
- DPO EMA Trend Crossover Quantitative Strategy ResearchPine Script · Trend following · 1d
- Dual EMA Crossover Trend Following Strategy with ATR and ADX FiltersPine Script · Trend following · 1d
- Advanced Multi Indicator Trend Confirmation Trading StrategyPine Script · Trend following · 1d
- Advanced Quantitative Trading Multi Moving Average Crossover System with Volume Filter StrategyPine Script · Trend following · 1d