Strategy vault / Trend following
Dynamic Dual EMA Trend Following Strategy
This strategy is a trend following trading system based on dual Exponential Moving Averages (EMA). It utilizes 44-period and 200-period EMAs, combined with price breakout signals to determine trading direction. The…

Overview
This strategy is a trend following trading system based on dual Exponential Moving Averages (EMA). It utilizes 44-period and 200-period EMAs, combined with price breakout signals to determine trading direction. The system integrates risk management mechanisms, including dynamic position sizing and trailing stop-loss.
Strategy Principle
The core logic is based on price interaction with dual EMAs. The 44-period EMA is applied to both high and low prices to form a channel, while the 200-period EMA serves as a long-term trend filter. Long signals are generated when the closing price breaks above the upper EMA and satisfies the 200 EMA filter condition; short signals are generated when the closing price breaks below the lower EMA and meets the 200 EMA filter condition. The strategy employs dynamic position sizing based on account equity, automatically calculating position size according to risk percentage per trade. Stop-loss levels are set at respective EMA positions.
Strategy Advantages
- Clear trend following logic with reliable trend confirmation through dual EMA channel and long-term moving average filter
- Flexible trade direction options, allowing long-only, short-only, or bidirectional trading
- Comprehensive risk control mechanisms including dynamic position sizing and trailing stops
- Highly adjustable parameters for optimization in different market environments
- Simple and efficient calculations suitable for real-time trading execution
Strategy Risks
- EMA indicators have inherent lag, potentially generating delayed signals in volatile markets
- Range-bound markets may produce frequent false breakout signals
- Stop-loss placement may be too wide during quick reversals, leading to larger drawdowns
- Position sizing depends on price volatility, potentially generating oversized positions in highly volatile environments
Strategy Optimization Directions
- Add volume confirmation indicators to improve breakout signal reliability
- Implement volatility adaptive mechanisms for dynamic EMA parameter adjustment
- Optimize stop-loss mechanism, consider introducing ATR-based dynamic stops
- Add profit target management with dynamic trailing take-profit
- Incorporate market environment filters to identify unsuitable trading conditions
Summary
This is a well-structured trend following strategy with clear logic. It provides trading signals through dual EMA channels and long-term trend filtering, coupled with comprehensive risk management mechanisms, demonstrating good practicality. Strategy optimization opportunities mainly lie in signal confirmation, dynamic parameter adjustment, and risk management mechanism enhancement. In practical application, it is recommended to thoroughly test parameter sensitivity and optimize specifically based on the characteristics of the traded instrument.
Source Pine Script
/*backtest
start: 2024-02-25 00:00:00
end: 2024-03-17 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("RENTABLE Dual EMA Breakout TSLA ", overlay=true)
// Inputs for EMA lengths and risk per trade
length = input(44, title="EMA Length")
longTermLength = input(200, title="Long-Term EMA Length")
riskPerTrade = input.float(1.0, title="Risk per Trade (%)", minval=0.1, maxval=10.0)
// Additional inputs for strategy customization
useFilter = input.bool(true, title="Use 200 EMA Filter")
tradeDirection = input.string("Both", title="Trade Direction", options=["Long", "Short", "Both"])
// EMAs based on the high and low prices and long-term EMA
emaHigh = ta.ema(high, length)
emaLow = ta.ema(low, length)
ema200 = ta.ema(close, longTermLength)
// Plotting EMAs on the chart
plot(emaHigh, color=color.green, title="High EMA")
plot(emaLow, color=color.red, title="Low EMA")
plot(ema200, color=color.blue, title="200 EMA")
// Entry conditions with optional EMA filter
longCondition = close > emaHigh and (useFilter ? close > ema200 : true)
shortCondition = close < emaLow and (useFilter ? close < ema200 : true)
// Calculating stop-loss and position size
longStop = emaLow
shortStop = emaHigh
riskPerShareLong = close - longStop
riskPerShareShort = shortStop - close
equity = strategy.equity
// Ensure risk per share is positive for calculations
riskPerShareLong := riskPerShareLong > 0 ? riskPerShareLong : 0.01
riskPerShareShort := riskPerShareShort > 0 ? riskPerShareShort : 0.01
positionSizeLong = (equity * riskPerTrade / 100) / riskPerShareLong
positionSizeShort = (equity * riskPerTrade / 100) / riskPerShareShort
// Ensure position sizes are positive before entering trades
if (longCondition and (tradeDirection == "Long" or tradeDirection == "Both") and positionSizeLong > 0)
strategy.entry("Long", strategy.long, qty= positionSizeLong)
if (shortCondition and (tradeDirection == "Short" or tradeDirection == "Both") and positionSizeShort > 0)
strategy.entry("Short", strategy.short, qty=positionSizeShort)
// Applying the stop-loss to strategy
strategy.exit("Exit Long", "Long", stop=longStop)
strategy.exit("Exit Short", "Short", stop=shortStop)
////Usar en 1,2 3 4 HRS TSLAPublished 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/Dynamic-Dual-EMA-Trend-Following-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
- 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
- Multi Factor Trend Price Action Strategy with Dynamic Risk Management SystemPine Script · Trend following · 2h
- Multi Period Moving Average Ribbon and MACD Crossover Strategy SystemPine Script · Trend following · 1h
- Multi Period Trend Following with Volume Confirmation StrategyPine Script · Trend following · 5d
- Trend Following Strategy Based on Moving Average 439858Pine Script · Trend following · 1d