
The Multi-Level Dynamic Trend Tracking Quantitative Strategy is an advanced trend following system based on Hull Moving Average (HMA), combining intelligent entry signal identification with dynamic take-profit and stop-loss mechanisms. The core of this strategy lies in utilizing HMA indicators of different periods (100, 200, 500, 1000) to construct entry signals, while employing a three-layer protection mechanism: hard stop-loss before trigger, intelligent trailing stop-loss after trigger, and trend direction filtering, forming a complete trading system. The strategy precisely captures the starting points of trends and intelligently locks in profits when the market reverses, achieving efficient capital management and risk control.
The core logic of this strategy can be divided into four key components:
Entry Signal Generation Mechanism:
Trigger Mechanism:
Intelligent Trailing Stop-Loss Mechanism:
Hard Stop-Loss Protection:
The strategy employs strict single position control (no pyramiding), ensuring controllable risk. The system automatically records entry price, highest/lowest price, and trigger status, achieving fully automated capital management.
Analyzing the code implementation of this strategy reveals the following significant advantages:
Multi-level Trend Confirmation: The system formed by four HMA lines of different periods creates a strict multiple confirmation mechanism, significantly improving the reliability of entry signals and reducing losses from false breakouts.
Adaptive Risk Management: The strategy features a two-stage stop-loss mechanism (hard stop-loss before trigger and trailing stop-loss after trigger), enabling timely loss-cutting in severely adverse markets while maximizing returns in trending markets, adapting to different market environments.
Precise Profit Locking: The dynamic trailing stop-loss mechanism automatically tracks new price highs/lows, implementing the classic trading concept of “letting profits run” while locking in most profits without manual intervention.
High Customizability: Three key parameters (trigger threshold, trailing margin, maximum loss) can be customized by users, adapting to different instruments, volatility levels, and risk preferences.
Visual Support: The strategy includes built-in visualization of HMA indicators and trend cloud layers, allowing traders to intuitively understand current trend status and the rationality of entry points.
Despite its sophisticated design, the strategy still has the following potential risks:
Range-Bound Market Risk: In range-bound markets without clear trends, HMA crossover signals may generate frequent false signals, leading to consecutive stop-losses. The solution is to add additional filtering conditions, such as volatility indicators or trend strength confirmation.
Parameter Sensitivity: Strategy performance highly depends on the settings of three key parameters. Inappropriate parameters may lead to premature stop-losses or missing most profits. It is recommended to optimize parameters for different instruments and time periods through historical backtesting.
Slippage and Trading Cost Impact: In live trading environments, slippage and trading costs may significantly affect strategy performance, especially for settings with smaller trailing margins. These factors should be considered in backtesting, and parameters should be adjusted accordingly.
Trend Reversal Point Delay: Although Hull Moving Averages react faster than traditional moving averages, they still have a certain lag, which may lead to larger drawdowns when trends suddenly reverse. Consider combining more sensitive short-term indicators to optimize exit timing.
Single Technical Indicator Dependence: The strategy mainly relies on the HMA indicator series, lacking multidimensional market analysis. It may underperform under certain specific market conditions. It is recommended to cross-validate with other types of indicators such as momentum or volume indicators.
Based on strategy principles and risk analysis, optimization can be pursued in the following directions:
Adaptive Parameter System:
Multi-Timeframe Analysis:
Volume Verification Mechanism:
Intelligent Partial Profit-Taking:
Machine Learning Optimization:
Counter-Trend Protection Mechanism:
The Multi-Level Dynamic Trend Tracking Quantitative Strategy is an advanced quantitative trading strategy that combines multi-period Hull Moving Average indicators with an intelligent profit-taking and stop-loss system. It improves entry signal reliability through strict trend confirmation mechanisms while achieving a balance between capital protection and profit maximization through a multi-level risk control system (including hard stop-loss before trigger and dynamic trailing stop-loss after trigger).
The core advantages of this strategy lie in its adaptability and systematic profit management method, which can maintain relatively stable performance in different market environments. However, the strategy also has risks such as parameter sensitivity and single indicator dependence, requiring traders to optimize through methods such as adding auxiliary indicator verification, building adaptive parameter systems, and multi-timeframe analysis.
By reasonably setting parameters and combining market environment analysis, this strategy can serve as a core component of a medium to long-term trend following system, helping traders capture major trending opportunities while controlling risk, achieving steady capital growth.
/*backtest
start: 2025-01-01 00:00:00
end: 2025-07-04 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Samil Dogru SmartTrailing v1.1", overlay=true, pyramiding=0,
default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// === PARAMETRELER ===
triggerPerc = input.float(1.2, "Tetikleme Eşiği (%)", step=0.1)
trailPerc = input.float(0.8, "Trailing Marj (%)", step=0.1)
hardStopPerc = input.float(2.5, "Maksimum Zarar (%) (Tetiklenmeden önce)", step=0.1)
// === HMA'lar (giriş için referans) ===
hma100 = ta.hma(close, 100)
hma200 = ta.hma(close, 200)
hma500 = ta.hma(close, 500)
hma600 = ta.hma(close, 600)
isBull = hma500 > hma600
longCond = ta.crossover(hma100, hma200) and isBull and hma100 > hma500 and hma200 > hma500
shortCond = ta.crossunder(hma100, hma200) and not isBull and hma100 < hma500 and hma200 < hma500
// === GİRİŞLER ===
if (longCond)
strategy.entry("Long", strategy.long)
if (shortCond)
strategy.entry("Short", strategy.short)
// === DURUM DEĞİŞKENLERİ ===
var float entryPrice = na
var float maxSinceEntry = na
var bool triggered = false
// === POZİSYON AÇILDIĞINDA BAŞLAT ===
if strategy.opentrades > 0
if na(entryPrice)
entryPrice := strategy.position_avg_price
maxSinceEntry := close
triggered := false
else
// Güncel zirve/dip güncellemesi
if strategy.position_size > 0
maxSinceEntry := math.max(maxSinceEntry, close)
if strategy.position_size < 0
maxSinceEntry := math.min(maxSinceEntry, close)
// Tetikleme kontrolü
longTriggerPrice = entryPrice * (1 + triggerPerc / 100)
shortTriggerPrice = entryPrice * (1 - triggerPerc / 100)
if strategy.position_size > 0 and close >= longTriggerPrice
triggered := true
if strategy.position_size < 0 and close <= shortTriggerPrice
triggered := true
// Çıkış kontrolü (trailing)
if triggered
if strategy.position_size > 0
trailStop = maxSinceEntry * (1 - trailPerc / 100)
if close <= trailStop
strategy.close("Long", comment="TRAIL EXIT LONG")
if strategy.position_size < 0
trailStop = maxSinceEntry * (1 + trailPerc / 100)
if close >= trailStop
strategy.close("Short", comment="TRAIL EXIT SHORT")
else
// Tetiklenmeden önce sert zarar çıkışı (hard stop)
if strategy.position_size > 0 and close <= entryPrice * (1 - hardStopPerc / 100)
strategy.close("Long", comment="HARD STOP LONG")
if strategy.position_size < 0 and close >= entryPrice * (1 + hardStopPerc / 100)
strategy.close("Short", comment="HARD STOP SHORT")
// === POZİSYON KAPANDIĞINDA RESET ===
if strategy.opentrades == 0
entryPrice := na
maxSinceEntry := na
triggered := false
// === GÖRSEL ===
plot(hma100, title="HMA 100", color=color.white, linewidth=2)
plot(hma200, title="HMA 200", color=color.yellow, linewidth=3)
p1 = plot(hma500, title="HMA 500", color=color.green, linewidth=2)
p2 = plot(hma600, title="HMA 600", color=color.red, linewidth=2)
fill(p1, p2, color=isBull ? color.new(color.green, 70) : color.new(color.red, 70), title="HMA Cloud")