Strategy vault / Trend following
Dynamic Volatility Adjusted EMA Trend Trading Strategy with Smart Stop Loss System
This strategy is an intelligent trading system based on trend following and momentum trading, specifically designed for short-term and rapid trading scenarios. The strategy core employs a combination of Exponential…

Overview
This strategy is an intelligent trading system based on trend following and momentum trading, specifically designed for short-term and rapid trading scenarios. The strategy core employs a combination of Exponential Moving Average (EMA) crossovers, Relative Strength Index (RSI), and Average True Range (ATR), coupled with a percentage-based smart stop-loss mechanism. It is particularly suitable for trading on shorter timeframe charts like 1-minute and 5-minute, with dynamic parameter adjustments to adapt to different market conditions.
Strategy Principles
The strategy utilizes three core technical indicators to construct its trading signal system:
- Fast/Slow EMA Crossover System - Uses 9-period and 21-period EMA combination, identifying trends through golden and death crosses
- RSI Overbought/Oversold Filter - Employs 14-period RSI, with 70 and 30 as thresholds to avoid extreme condition entries
- ATR Volatility Confirmation Mechanism - Utilizes ATR to measure market volatility, ensuring trades are only executed when breakouts show sufficient strength
The trading logic is clearly defined: long entries require fast EMA crossing above slow EMA, RSI below 70, and price confirmation above ATR multiplier; short entries require fast EMA crossing below slow EMA, RSI above 30, and price confirmation below ATR multiplier. The system includes a 1% dynamic stop-loss mechanism for effective risk control.
Strategy Advantages
- Multiple technical indicator cross-validation improves signal reliability
- Dynamic parameter adaptation system suits different timeframes
- ATR-based volatility filtering mechanism reduces false signals
- Smart stop-loss system strictly controls risk per trade
- Complete visualization system including clear graphical markers and background alerts
Strategy Risks
- Ranging markets may generate frequent trading signals, increasing transaction costs
- Fixed percentage stop-loss may not suit all market environments
- Slippage risk during high volatility periods
- Parameters require continuous monitoring and adjustment
To mitigate risks, it is recommended to:
- Adjust stop-loss percentages based on instrument characteristics
- Add trend strength confirmation mechanisms
- Monitor market volatility in real-time
- Establish comprehensive money management systems
Strategy Optimization Directions
- Introduce adaptive stop-loss mechanism to dynamically adjust stop-loss percentages based on market volatility
- Add trend strength filters to improve trading signal quality
- Develop smart time filtering system to avoid low liquidity periods
- Integrate volume indicators to enhance signal reliability
- Develop dynamic parameter optimization system for strategy self-adjustment
Summary
This strategy constructs a complete trading system through the synergistic effect of multiple technical indicators. While maintaining flexibility, the system ensures trading safety through strict risk control. Although certain limitations exist, through continuous optimization and improvement, the strategy demonstrates good application value and development potential.
Source Pine Script
/*backtest
start: 2025-02-17 10:00:00
end: 2025-02-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DBate
//@version=6
strategy("Enhanced Scalping Strategy with Stop Loss", overlay=true)
// Input parameters
fastMA_length = input.int(9, title="Fast MA Length", minval=1)
slowMA_length = input.int(21, title="Slow MA Length", minval=1)
RSI_length = input.int(14, title="RSI Length", minval=1)
RSI_overbought = input.int(70, title="RSI Overbought")
RSI_oversold = input.int(30, title="RSI Oversold")
ATR_multiplier = input.float(1.5, title="ATR Multiplier")
ATR_length = input.int(14, title="ATR Length", minval=1)
stopLossPercent = input.float(1.0, title="Stop Loss %", minval=0.1) / 100 // Convert percentage to decimal
// Timeframe-specific adjustments
is1m = timeframe.period == "1"
is5m = timeframe.period == "5"
// Adjust input parameters based on timeframe
fastMA_length := is1m ? 9 : is5m ? 12 : fastMA_length
slowMA_length := is1m ? 21 : is5m ? 26 : slowMA_length
RSI_length := is1m ? 14 : is5m ? 14 : RSI_length
// Moving Averages
fastMA = ta.ema(close, fastMA_length)
slowMA = ta.ema(close, slowMA_length)
// RSI Calculation
rsi = ta.rsi(close, RSI_length)
// ATR Calculation for volatility filter
atr = ta.atr(ATR_length)
// Trade state variables
var bool inLongTrade = false
var bool inShortTrade = false
var float entryPrice = na
var float stopLossLevel = na
// Long and Short Conditions with added filters
longCondition = ta.crossover(fastMA, slowMA) and rsi < RSI_overbought and close > fastMA + ATR_multiplier * atr
shortCondition = ta.crossunder(fastMA, slowMA) and rsi > RSI_oversold and close < fastMA - ATR_multiplier * atr
// Ensure previous trades are closed before entering new ones
if (longCondition)
strategy.close("Short")
strategy.entry("Long", strategy.long)
entryPrice := close
stopLossLevel := close * (1 - stopLossPercent) // 1% below entry for long trades
inLongTrade := true
inShortTrade := false
if (shortCondition)
strategy.close("Long")
strategy.entry("Short", strategy.short)
entryPrice := close
stopLossLevel := close * (1 + stopLossPercent) // 1% above entry for short trades
inShortTrade := true
inLongTrade := false
// Stop Loss Exits
stopLossLongCondition = inLongTrade and close <= stopLossLevel
stopLossShortCondition = inShortTrade and close >= stopLossLevel
// Exit Conditions (Moving Average crossover or Stop Loss)
exitLongCondition = inLongTrade and (ta.crossunder(fastMA, slowMA) or stopLossLongCondition)
exitShortCondition = inShortTrade and (ta.crossover(fastMA, slowMA) or stopLossShortCondition)
// Reset trade state on exit
if (exitLongCondition)
strategy.close("Long")
inLongTrade := false
inShortTrade := false
if (exitShortCondition)
strategy.close("Short")
inShortTrade := false
inLongTrade := false
// Plot buy and sell signals
plotshape(longCondition, title="Long Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="LONG")
plotshape(shortCondition, title="Short Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SHORT")
// Plot moving averages
plot(fastMA, title="Fast MA", color=color.blue, linewidth=2)
plot(slowMA, title="Slow MA", color=color.orange, linewidth=2)
// Background color for overbought/oversold RSI
bgcolor(rsi > RSI_overbought ? color.new(color.red, 90) : na, title="Overbought Background")
bgcolor(rsi < RSI_oversold ? color.new(color.green, 90) : na, title="Oversold Background")
// Alerts
alertcondition(longCondition, title="Long Alert", message="Buy Signal")
alertcondition(shortCondition, title="Short Alert", message="Sell Signal")
alertcondition(exitLongCondition, title="Exit Long Alert", message="Exit Long Signal")
alertcondition(exitShortCondition, title="Exit Short Alert", message="Exit Short Signal")
Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-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/Dynamic-Volatility-Adjusted-EMA-Trend-Trading-Strategy-with-Smart-Stop-Loss-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
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual Mode Adaptive Trend Trading Strategy EMA Crossover with ATR Volatility Based Risk Management SystemPine Script · Trend following · 1d
- Dynamic Dual EMA Crossover Strategy with Adaptive Profit Loss ControlPine Script · Trend following · 1d
- Dynamic Multi Timeframe ATR Crossover Strategy Optimizing Trend Following and Risk Management with Flexible ParametersPine Script · Trend following · 1h