Overview
This strategy is a trend tracking system that combines the Directional Movement Index (DMI) and the Average True Range (ATR). The core of the strategy is to identify the direction and strength of the market trend through the DI+ and DI- indicators, and dynamically adjust the stop-loss and take-profit positions using the ATR. The reliability of trading signals is further improved by introducing the trend-filtered moving average as an auxiliary confirmation. The strategy design fully considers market volatility and has good adaptability.
Strategy Principle
The strategy operates based on the following core mechanisms:
- Use DI+ and DI- indicators to measure trend direction and strength. When DI+ is higher than DI- and the difference exceeds the threshold, it indicates that an upward trend is established; otherwise, a downward trend is confirmed.
- Introduce trend-filtered moving average (SMA) as a trend confirmation tool. The signal is triggered only when the price and the moving average position confirm each other.
- Use the ATR indicator to dynamically calculate stop loss and take profit positions to ensure that risk management can adapt to different market environments.
- Strictly follow time limits when executing transactions and avoid trading too frequently.
Strategy Advantages
- Strong dynamic adjustment capability - Adaptation to market fluctuations is achieved through ATR.
- Perfect risk control - a dynamic stop loss and take profit mechanism based on volatility is set up.
- High signal reliability - Reduce false signals through cross-validation of multiple indicators.
- Flexible and adjustable parameters - Strategy parameters can be optimized according to different market characteristics.
- Clear execution logic - clear entry and exit conditions, easy to operate in real time.
Strategy Risks
Risk of volatile market - continuous stop loss may occur in the range-bound market.
Suggestion: add oscillation indicator filter or adjust parameter threshold.Slippage risk - You may face large slippage during volatile trading.
Suggestion: loosen the stop loss position appropriately to leave room for slippage.False breakout risk - there may be misjudgment at the trend turning point.
Recommendation: Combine indicators such as trading volume for signal confirmation.Parameter sensitivity - Different parameter combinations have different performances.
Suggestion: Find a parameter range with strong stability through backtesting.
Strategy Optimization Direction
Signal optimization - ADX indicator can be introduced to evaluate trend strength, or volume confirmation mechanism can be added.
Position Management - Dynamically adjust position size based on trend strength to achieve more sophisticated risk control.
Time frame - Multiple time period analysis can be considered to enhance signal reliability.
Market adaptability - Adaptive parameter adjustment mechanisms can be developed based on the characteristics of different varieties.
Summary
This strategy achieves dynamic trend tracking and risk control by combining trend indicators and volatility indicators. The strategy design focuses on practicality and operability, and has strong market adaptability. Through parameter optimization and signal improvement, the strategy still has room for further improvement. It is recommended that investors fully test it in actual application and make targeted adjustments according to specific market characteristics.
Strategy source code
/*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=5
strategy("Strategy using DI+ and DI- (finally fully revised with chart stop loss and take profit levels)", overlay=true)
// Input parameters
diLength = input.int(title="DI length", defval=14)
adxSmoothing = input.int(title="ADX Smoothing", defval=14)
trendFilterLength = input.int(title="Trend filter moving average length", defval=20)
strengthThreshold = input.int(title="Trend strength threshold", defval=20)
atrLength = input.int(title="ATR length", defval=14)
atrMultiplierStop = input.float(title="ATR stop Loss multiple", defval=1.5)
atrMultiplierTakeProfit = input.float(title="ATR take profit multiple", defval=2.5)
// Calculate DI+ and DI-
[diPlus, diMinus, _] = ta.dmi(diLength, adxSmoothing)
// Calculate trend filtered moving average
trendFilterMA = ta.sma(close, trendFilterLength)
// Determine trend direction and strength
strongUpTrend = diPlus > diMinus + strengthThreshold and close > trendFilterMA
strongDownTrend = diMinus > diPlus + strengthThreshold and close < trendFilterMA
// Calculate ATR
atr = ta.atr(atrLength)
// Trailing stop loss and take profit prices (declared using var, updated only on entry)
var float longStopPrice = na
var float longTakeProfitPrice = na
var float shortStopPrice = na
var float shortTakeProfitPrice = na
// Entry Logic
longCondition = strongUpTrend
shortCondition = strongDownTrend
if (longCondition)
strategy.entry("Long order", strategy.long)
longStopPrice := close - atr * atrMultiplierStop // Calculate and update the stop loss price when entering the market
longTakeProfitPrice := close + atr * atrMultiplierTakeProfit // Calculate and update the take profit price when entering the market
if (shortCondition)
strategy.entry("Short order", strategy.short)
shortStopPrice := close + atr * atrMultiplierStop // Calculate and update the stop loss price when entering the market
shortTakeProfitPrice := close - atr * atrMultiplierTakeProfit // Calculate and update the take profit price when entering the market
// Exit logic (using time limits and ATR)
inLongPosition = strategy.position_size > 0
inShortPosition = strategy.position_size < 0
lastEntryTime = strategy.opentrades.entry_bar_index(strategy.opentrades - 1)
if (inLongPosition and time > lastEntryTime)
strategy.exit("Long order exit", "Long order", stop=longStopPrice, limit=longTakeProfitPrice)
if (inShortPosition and time > lastEntryTime)
strategy.exit("Short order exit", "Short position", stop=shortStopPrice, limit=shortTakeProfitPrice)
// Plotting DI+, DI- and trend-filtered moving averages
plot(diPlus, color=color.green, title="DI+")
plot(diMinus, color=color.red, title="DI-")
plot(trendFilterMA, color=color.blue, title="Trend Filtered Moving Average")
// Draw stop loss and take profit lines (using plot function)
plot(strategy.position_size > 0 ? longStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=2, title="Long order stop loss")
plot(strategy.position_size > 0 ? longTakeProfitPrice : na, color=color.green, style=plot.style_linebr, linewidth=2, title="Long order take profit")
plot(strategy.position_size < 0 ? shortStopPrice : na, color=color.red, style=plot.style_linebr, linewidth=2, title="Short order stop loss")
plot(strategy.position_size < 0 ? shortTakeProfitPrice : na, color=color.green, style=plot.style_linebr, linewidth=2, title="Short order take profit")
Strategy Parameters
The original address: Dynamic Volatility-Adjusted Trend Following Strategy Based on DI Indicators with ATR Stop Management