
This strategy is a dynamic trailing stop-loss trading system based on the Average True Range (ATR) indicator, combined with EMA filter signals, primarily used to capture market trend reversal points and execute trades. The core of the strategy is to calculate dynamic stop-loss levels through ATR values, triggering trading signals when price crosses these stop-loss levels. The strategy is designed to backtest within a specific date range and is particularly suitable for running on 15-minute timeframes with Heikin Ashi candles, helping to reduce noise and identify trend changes more clearly.
The core logic of this strategy is based on a dynamic trailing stop system built with the ATR indicator. The specific working principles are as follows:
The entire trading logic is similar to a trend-following system, but by dynamically adjusting stop-loss positions through ATR, the strategy can adapt to different volatility environments.
Through in-depth analysis of the strategy code, I have summarized the following significant advantages:
Despite its many advantages, this strategy still has the following risks in practical application:
Solutions: - Add oscillation indicators (such as RSI or Bollinger Bands) to filter signals in ranging markets - Adjust sensitivity parameters based on different market characteristics and timeframes - Consider using longer-period EMAs to smooth prices - Add volume or other technical indicators as signal confirmation conditions - Implement dynamic position management, adjusting trading size based on market volatility or account equity
Based on code analysis, the strategy can be optimized in the following directions:
Enhanced Signal Filtering:
Dynamic Parameter Adjustment:
Position Management Optimization:
Add Take Profit Mechanism:
Time Filtering Improvements:
Multi-Timeframe Analysis:
These optimization directions are important because they can significantly improve the robustness of the strategy. In particular, adding signal filtering and dynamic parameter adjustment can reduce false signals, while improving position management and take-profit mechanisms can optimize capital efficiency and risk-reward ratios.
The ATR Dynamic Trailing Stop Loss Quantitative Trading Strategy is an elegantly designed trend-following system that creates a dynamic stop-loss mechanism adaptable to market volatility by combining the ATR indicator with EMA. The strategy’s greatest advantages lie in its adaptability and simplicity, automatically adjusting stop-loss distances under various market conditions while maintaining clear operational logic.
However, the strategy may underperform in ranging markets and relies too heavily on a single indicator system. By adding additional signal filtering, optimizing parameter adjustment mechanisms, improving position management, and adding take-profit strategies, its performance can be significantly enhanced.
For traders, this is an excellent basic strategy framework that can be customized and expanded according to personal trading styles and target market characteristics. It is recommended to thoroughly backtest different parameter combinations and market environments before live application, and consider combining other technical indicators to form a more comprehensive trading system.
This strategy is particularly suitable for markets with obvious medium to long-term trends, providing traders with a relatively simple but effective quantitative trading solution by allowing profits to continue growing while dynamically protecting realized gains.
/*backtest
start: 2024-05-13 00:00:00
end: 2025-05-11 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"DOGE_USDT"}]
*/
//@version=6
strategy("UT Bot Strategy Backtest with Date Range", overlay=true)
// === Inputs ===
keyValue = input.float(1.0, title="Key Value (Sensitivity)")
atrPeriod = input.int(10, title="ATR Period")
// === Calculations ===
xATR = ta.atr(atrPeriod)
nLoss = keyValue * xATR
src = close
// === Trailing Stop Logic ===
var float xATRTrailingStop = na
xATRTrailingStop := src > nz(xATRTrailingStop[1]) and src[1] > nz(xATRTrailingStop[1]) ?
math.max(nz(xATRTrailingStop[1]), src - nLoss) :
src < nz(xATRTrailingStop[1]) and src[1] < nz(xATRTrailingStop[1]) ?
math.min(nz(xATRTrailingStop[1]), src + nLoss) :
src > nz(xATRTrailingStop[1]) ? src - nLoss : src + nLoss
// === Signal Logic ===
emaVal = ta.ema(src, 1)
above = ta.crossover(emaVal, xATRTrailingStop)
below = ta.crossover(xATRTrailingStop, emaVal)
buySignal = src > xATRTrailingStop and above
sellSignal = src < xATRTrailingStop and below
// === Strategy Execution ===
if buySignal
strategy.close("Short")
strategy.entry("Long", strategy.long)
if sellSignal
strategy.close("Long")
strategy.entry("Short", strategy.short)
// === Visuals ===
plotshape(buySignal, title="Buy", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(sellSignal, title="Sell", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")
barcolor(buySignal ? color.green : sellSignal ? color.red : na)
// === Alerts ===
alertcondition(buySignal, title="UT Long", message="UT Long")
alertcondition(sellSignal, title="UT Short", message="UT Short")