Strategy vault / Trend following
Dynamic Trend Following Dual Moving Average Crossover Trading Strategy
This strategy is a dynamic trend-following system based on technical analysis, primarily utilizing dual moving averages (200-day SMA and 21-week EMA) to identify market trends. The strategy integrates the Relative…

Overview
This strategy is a dynamic trend-following system based on technical analysis, primarily utilizing dual moving averages (200-day SMA and 21-week EMA) to identify market trends. The strategy integrates the Relative Strength Index (RSI) and Average Directional Index (ADX) as momentum filters, combined with Average True Range (ATR) for dynamic risk management, achieving precise capture of uptrends and effective risk control.
Strategy Principles
The core logic of the strategy is built on several key elements:
- Uses dual confirmation from 200-day Simple Moving Average (SMA) and 21-week Exponential Moving Average (EMA) to define bullish market conditions
- Ensures continued upward momentum through RSI>50 condition
- Validates trend strength with ADX>25 condition
- Implements dynamic stop-loss based on ATR, providing risk control adapted to market volatility
- Employs percentage-based take-profit mechanism to secure gains at predetermined levels
Strategy Advantages
- System demonstrates good adaptability with dynamic stop-loss adjustment based on market volatility
- Dual moving average crossover provides reliable trend confirmation signals, effectively reducing false breakout risks
- Combination of RSI and ADX significantly improves entry signal quality
- Highly customizable strategy parameters facilitate optimization for different market environments
- Daily timeframe trading reduces transaction costs and short-term volatility impact
Strategy Risks
- May generate frequent false signals in ranging markets, increasing transaction costs
- Moving average strategies inherently lag, potentially missing early trend gains
- Multiple filter conditions might cause missed trading opportunities
- ATR-based stops may become too wide in highly volatile markets
- Fixed percentage take-profit might exit profitable positions too early in strong trends
Strategy Optimization Directions
- Consider incorporating volume indicators for signal confirmation
- Implement dynamic take-profit mechanism to better adapt to different market phases
- Optimize RSI and ADX parameters to improve signal timeliness
- Add trend strength classification for dynamic position management
- Introduce volatility indicators to adjust trading frequency during high volatility periods
Summary
This is a well-designed trend-following strategy with clear logic, effectively balancing returns and risks through multiple technical indicators. The strategy's high customizability makes it suitable for maintaining effectiveness across different market environments through parameter optimization. While it carries some inherent lag risks, the comprehensive risk control mechanisms contribute to overall stability and reliability.
Source Pine Script
/*backtest
start: 2022-02-09 00:00:00
end: 2025-02-06 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("BTCUSDT Daily - Enhanced Bitcoin Bull Market Support [CYRANO]", shorttitle="BTCUSDT Daily BULL MARKET", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)
// Inputs
smaLength = input.int(200, title="SMA Length (Bull Market)")
emaLength = input.int(147, title="EMA Length (21-Week Approximation)")
atrLength = input.int(14, title="ATR Length")
riskATR = input.float(2.0, title="ATR Multiplier for Stop Loss", step=0.1)
takeProfitPercent = input.float(10.0, title="Take Profit (%)", step=0.1)
rsiFilter = input.bool(true, title="Enable RSI Filter")
rsiLength = input.int(14, title="RSI Length")
adxFilter = input.bool(true, title="Enable ADX Filter")
adxThreshold = input.float(25, title="ADX Threshold")
// Date Range Filter
startDate = input(timestamp("2018-01-01 00:00 +0000"), title="Start Date")
endDate = input(timestamp("2069-12-31 00:00 +0000"), title="End Date")
inDateRange = true
// Moving Averages
sma200 = ta.sma(close, smaLength)
ema21w = ta.ema(close, emaLength)
// ATR Calculation
atr = ta.atr(atrLength)
stopLoss = close - (riskATR * atr)
takeProfit = close * (1 + takeProfitPercent / 100)
// RSI Filter
rsi = ta.rsi(close, rsiLength)
rsiCondition = rsiFilter ? rsi > 50 : true
// ADX Filter
[diplus, diminus, adx] = ta.dmi(14, 14)
adxCondition = adxFilter ? adx > adxThreshold : true
// Entry and Exit Conditions
buyCondition = inDateRange and close > sma200 and close > ema21w and rsiCondition and adxCondition
exitCondition = inDateRange and (close < sma200 or close < ema21w)
// Strategy Execution
if buyCondition
strategy.entry("BUY", strategy.long, stop=stopLoss, limit=takeProfit)
if exitCondition
strategy.close("BUY")
// Plot MAs
plot(sma200, title="200-Day SMA", color=color.blue, linewidth=2)
plot(ema21w, title="21-Week EMA", color=color.purple, linewidth=2)
// Background Highlight
bullColor = color.new(color.green, 80)
bearColor = color.new(color.red, 80)
bgcolor(close > sma200 and close > ema21w ? bullColor : bearColor, title="Bull Market Background")
Published by ChaoZhang on the FMZ strategy square · last modified 2025-02-08. 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-Trend-Following-Dual-Moving-Average-Crossover-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
- Trend Tracking and Short term Trading Strategy Based on ADX IndicatorPine Script · Trend following · 1d
- Multi Period Trend Confirmation Dynamic Risk Control Quantitative Trading StrategyPine Script · Trend following · 1h
- Dual directional Trailing Stop Moving Average Trend StrategyPine Script · Trend following · 1m
- Multi Factor Trend Tracking Dynamic Risk Management Stock Trading StrategyPine Script · Trend following · 1d
- Multi Timeframe Volume and Trend Confluence Trading StrategyPine Script · Trend following · 1d
- Multi timeframe Trend Tracking Strategy Based on Impulse MACD and Dual Moving Average CrossoverPine Script · Trend following · 1d