Overview
The Dual Weighted Moving Average Trend Following Strategy with Adaptive Trailing Stop-Loss is a quantitative trading approach based on technical analysis. Its core logic utilizes crossover signals from two Weighted Moving Averages (WMAs) of different periods to identify trend reversal points, combined with an ATR (Average True Range) filter and an adaptive trailing stop-loss mechanism to optimize entry timing and risk management. This strategy is designed for the 5-minute timeframe, suitable for medium to short-term traders, effectively capturing market trend changes while protecting profits.
Strategy Principles
The core principles of this strategy include several key components:
Dual Weighted Moving Average Crossover System: The strategy employs 8-period and 21-period Weighted Moving Averages (WMAs) as trend indicators. When the shorter-period WMA crosses above the longer-period WMA, a long signal is generated; conversely, when the shorter-period WMA crosses below the longer-period WMA, a short signal is generated.
ATR Decline Filter: To improve entry quality, the strategy incorporates an ATR filtering mechanism. Trade signals are only triggered when the ATR decreases for 3 consecutive periods (indicating that market volatility is weakening). This filter can be optionally enabled.
Adaptive Trailing Stop-Loss Mechanism: The strategy employs a two-stage trailing stop-loss mechanism:
- First, the trailing stop-loss feature is only activated when profits reach a preset trigger threshold (default 1.2%)
- Once activated, the stop-loss level is set at a certain percentage pullback from the highest/lowest price (default 0.6%)
- This mechanism allows trades more breathing room in the initial stage while protecting gains after profitability
Maximum Drawdown Protection: To prevent excessive losses in a single trade, the strategy includes a maximum drawdown protection mechanism (default 5%). If losses exceed this threshold before the trailing stop-loss is activated, positions are automatically closed.
The strategy logic clearly differentiates between long and short position handling and continuously updates peak and trough prices during position holding to accurately execute the trailing stop-loss.
Strategy Advantages
Trend Identification Capability: Through crossovers of WMAs with different periods, the strategy effectively identifies trend reversal points, avoiding frequent trading in ranging markets. Weighted moving averages assign higher weights to recent prices, making signals more sensitive to market changes.
Adaptive Risk Management: The strategy's two-stage trailing stop-loss mechanism is highly innovative, allowing for small price fluctuations while strictly protecting profits after a trend is established. This mechanism solves the rigidity problem of traditional fixed stop-losses.
ATR Filtering Mechanism: By only entering the market when volatility is decreasing, the strategy can avoid highly unstable market environments, improving signal quality. This approach helps avoid false breakouts and market noise.
Maximum Drawdown Control: The strategy sets a clear maximum loss limit for individual trades, effectively controlling risk exposure and protecting capital safety.
Flexible Parameter Adjustment: The strategy provides multiple adjustable parameters (WMA periods, trigger percentages, retracement percentages, etc.), allowing traders to optimize according to different market environments and personal risk preferences.
Strategy Risks
False Breakout Risk: Despite using the ATR filter, the strategy may still generate false signals during severe market fluctuations. Moving average crossovers may not be reliable enough, especially before and after major news or events.
Parameter Sensitivity: Strategy performance is highly dependent on parameter settings. Different markets and time periods may require different parameter combinations; incorrect parameters may lead to overtrading or missing important opportunities.
Slippage and Liquidity Risk: Strategies executed on 5-minute timeframes may face higher slippage risk, especially in less liquid markets. This could affect the actual execution performance of the strategy.
Trend Reversal Delay: Since the strategy is based on moving average crossovers, signals are inherently lagging and may not enter at the initial stage of a trend or exit quickly at the end of a trend.
Over-reliance on ATR Filter: A 3-day consecutive decrease in ATR doesn't always indicate a genuine reduction in volatility; sometimes it may be just a temporary phenomenon, leading to missed favorable trading opportunities.
Solutions include: optimizing parameter settings, combining with other technical indicators or fundamental analysis, testing strategy performance under different market conditions, and considering additional confirmation signals.
Strategy Optimization Directions
Dynamic Parameter Adjustment: The current strategy uses fixed WMA periods and stop-loss parameters. An important optimization direction is to introduce adaptive parameters, such as automatically adjusting WMA periods based on market volatility, or dynamically adjusting stop-loss trigger conditions according to different market states (trending/ranging).
Improved ATR Filter: The current ATR filter only considers consecutive declines; it can be optimized to consider the relative level or rate of change of ATR, or even use ATR to set dynamic stop-loss levels instead of fixed percentages.
Incorporate Volume Analysis: By combining volume indicators (such as OBV or Chaikin Money Flow), the reliability of trend confirmation can be improved, avoiding false breakouts caused by low trading volume.
Time Filter: Add time filtering functionality to avoid high volatility periods at market open and close, or pause trading during specific high volatility times (such as economic data releases).
Multi-timeframe Analysis: Integrate trend confirmation signals from longer timeframes (such as 15 minutes or 1 hour), trading only in the direction of the larger trend to improve win rates.
Profit-Taking Mechanism Optimization: The current strategy relies on trailing stop-loss for exits; consider adding profit-taking mechanisms based on support/resistance levels or price targets to secure profits at strong resistance levels.
Backtesting Optimization: Comprehensively backtest performance in different market environments, particularly optimizing parameters separately for trending and ranging markets; different parameter sets may be needed for different market conditions.
These optimization directions primarily focus on improving signal quality, reducing false breakout risk, optimizing capital management, and adapting to different market conditions, which can effectively enhance the overall robustness of the strategy.
Summary
The Dual Weighted Moving Average Trend Following Strategy with Adaptive Trailing Stop-Loss is a well-designed quantitative trading system that combines traditional moving average crossover strategies with modern risk management techniques. The strategy identifies trend changes through crossovers of 8 and 21-period WMAs and improves signal quality with an ATR filter. Its most innovative aspect is the two-stage adaptive trailing stop-loss mechanism, which protects capital while giving trends sufficient room to develop.
The strategy's advantages lie in its clear logical structure, comprehensive risk control, and flexible parameter settings, but it also faces risks such as high parameter sensitivity and signal lag. By introducing dynamic parameter adjustments, improving ATR application methods, and integrating multi-timeframe analysis, the strategy's performance and adaptability can be further enhanced.
For quantitative investors pursuing medium to short-term trend trading, this strategy provides an ideal framework for finding trading opportunities in different market environments while effectively managing risk. Correctly understanding the strategy principles and making appropriate adjustments based on one's trading style will help fully realize the potential of this strategy.
Strategy source code
/*backtest
start: 2024-07-07 00:00:00
end: 2025-07-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("Reverscope 5M", overlay=true)
wmaLen1 = input.int(8, title="WMA 1 Periyodu")
wmaLen2 = input.int(21, title="WMA 2 Periyodu")
trail_trigger_pct = input.float(1.2, title="Tetikleme Oranı (%)")
trail_offset_pct = input.float(0.6, title="Geri Çekilme Oranı (%)")
max_dd_pct = input.float(5.0, title="Maksimum Zarar (%)")
use_atr_filter = input.bool(true, title="ATR Düşüş Filtresi Aktif")
atr_period = input.int(8, title="ATR Periyodu")
trail_trigger = trail_trigger_pct / 100
trail_offset = trail_offset_pct / 100
max_dd = max_dd_pct / 100
var float entry_price = na
var float peak_price = na
var float trough_price = na
var bool is_long = false
var bool triggered = false
wma1 = ta.wma(close, wmaLen1)
wma2 = ta.wma(close, wmaLen2)
atr = ta.atr(atr_period)
// ATR 3 barda üst üste düşüyor mu?
atrFalling = atr < atr[1] and atr[1] < atr[2] and atr[2] < atr[3]
atrFilterPass = not use_atr_filter or atrFalling
plot(wma1, "WMA 1", color=color.yellow, linewidth=3)
plot(wma2, "WMA 2", color=color.red, linewidth=3)
longSignal = wma1[1] < wma2[1] and wma1[2] >= wma2[2]
shortSignal = wma1[1] > wma2[1] and wma1[2] <= wma2[2]
plotshape(longSignal and atrFilterPass, title="Long", location=location.belowbar, color=color.lime, style=shape.triangleup, size=size.small, offset=-1)
plotshape(shortSignal and atrFilterPass, title="Short", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small, offset=-1)
if longSignal and atrFilterPass
strategy.close("Short")
strategy.entry("Long", strategy.long)
entry_price := close
is_long := true
peak_price := close
trough_price := close
triggered := false
if shortSignal and atrFilterPass
strategy.close("Long")
strategy.entry("Short", strategy.short)
entry_price := close
is_long := false
peak_price := close
trough_price := close
triggered := false
if strategy.position_size != 0
profit = is_long ? (close - entry_price) / entry_price : (entry_price - close) / entry_price
drawdown = is_long ? (entry_price - close) / entry_price : (close - entry_price) / entry_price
if not triggered and drawdown > max_dd
strategy.close_all(comment="Max DD")
if is_long
peak_price := math.max(peak_price, close)
if not triggered and profit > trail_trigger
triggered := true
if triggered and close < peak_price * (1 - trail_offset)
strategy.close_all(comment="Trailing Stop")
else
trough_price := math.min(trough_price, close)
if not triggered and profit > trail_trigger
triggered := true
if triggered and close > trough_price * (1 + trail_offset)
strategy.close_all(comment="Trailing Stop")
Strategy parameters
The original address: Dual Weighted Moving Average Trend Following Strategy with Adaptive Trailing Stop-Loss
Top comments (1)
This strategy feels like it’s got trust issues… but in a good way 😂 Two weighted moving averages to double-check the trend, plus a trailing stop that actually adapts instead of ghosting you the second price wobbles. Honestly, it’s like having a cautious co-pilot who actually knows what they’re doing. Definitely giving this a shot before my next “confident but clueless” trade 😅