DEV Community

FMZQuant
FMZQuant

Posted on

Dual HMA Momentum Breakout Trading Strategy: Volatility-Adaptive Trend Following System

Overview
The Dual HMA Momentum Breakout Trading Strategy is a high-precision trading system that combines trend following and volatility breakout logic. This strategy utilizes dual filtering through short-term and long-term Hull Moving Averages (HMA), along with strong candle pattern recognition, dynamic ATR-based stop losses, and R-multiple target setting to provide traders with a complete trading solution. Key features include: strict entry condition filtering, volatility-based risk management, volume-price confirmation, and a visual trading checklist. This strategy is suitable for traders seeking precise entries during strong directional market movements, supports both long and short trading, and enhances reliability through multiple technical indicator validation.

Strategy Principles
The core principle of this strategy is based on the synergistic confirmation of multiple technical indicators and strict entry conditions. First, market trend direction is determined by comparing the short-term HMA (20-period) with the long-term HMA (200-period); second, strong candle patterns are used as directional breakout confirmation; third, sufficient distance between price and short-term HMA is required to ensure adequate momentum; finally, volume filtering and price position judgment are combined to ensure entry only during high-quality breakouts.

Specifically, long entry requires the following conditions:

  1. Uptrend: HMA20 > HMA200 and SMA5 > HMA200
  2. Strong bullish candle: closing price higher than opening price and higher than the previous candle's high
  3. Sufficient distance from HMA: (close - HMA20) > (ATR * 0.5)
  4. Volume above average level: current volume > volume SMA
  5. Price above support/resistance midline

Short entry conditions are the opposite. The strategy also incorporates RSI and MACD as additional confirmation indicators, considering entry signals valid only when RSI is within a reasonable range of 30-70 and the MACD line is above the signal line.

For risk management, the strategy employs dynamic stop-loss settings based on ATR and uses R-multiples (risk-reward ratio) to set target prices. When price reaches 2R, the stop-loss moves to the entry price, achieving risk-free trading; when price reaches 3R, profits are realized.

Strategy Advantages

  1. Precise Entry Conditions: Through strict screening of multiple technical indicators and conditions, the quality of trading signals is greatly improved, reducing the possibility of false breakouts.

  2. Dynamic Risk Management: ATR-based stop-loss settings allow risk control to automatically adjust according to market volatility, better adapting to different market environments.

  3. Risk-Free Trading Mechanism: Moving stop-loss to entry price when profits reach a specific multiple protects gained profits, implementing the trading philosophy of "letting profits run."

  4. Volume-Price Combined Analysis: By combining price action with volume changes, the reliability of trading signals is enhanced, considering entry only when confirmed by volume.

  5. Intuitive Visual Interface: Through the checklist panel, oscillator panel, and price panel, traders can intuitively understand current market conditions and signal quality, improving decision-making efficiency.

  6. Strong Adaptability: Supporting both long and short trading, the strategy can be flexibly applied in different market environments, finding suitable trading opportunities in both bull and bear markets.

  7. Systematic Trading Process: From signal generation to position management, the entire trading process is highly systematized, reducing interference from subjective judgments.

Strategy Risks

  1. Trend Reversal Point Risk: Near market trend reversal points, HMA may produce lagging reactions, leading to false signals. The solution is to incorporate more market structure analysis and shorter-period indicators to confirm trend changes.

  2. False Signals in Low Volatility Environments: In low volatility environments, the distance condition between price and HMA may be difficult to meet, causing missed potential opportunities. Consider dynamically adjusting the ATR multiplier based on different market environments.

  3. Excessive Stop-Loss Risk: Using 1.5 times ATR as a stop-loss may result in distant stop points in some highly volatile markets. It is recommended to adjust the ATR multiplier based on specific trading instruments and timeframes, or set maximum stop-loss amount limits.

  4. Over-reliance on Technical Indicators: The strategy is primarily based on technical indicators, lacking consideration for fundamentals and market sentiment. Pure technical indicators may fail during major news events or abnormal market fluctuations. It is advisable to pause automated trading during important data releases or special market environments.

  5. Parameter Optimization Risk: Strategy effectiveness is highly dependent on parameter settings, and excessive optimization may lead to curve-fitting issues. It is recommended to use sufficiently long historical data for backtesting and verify strategy stability across different timeframes and market environments.

Strategy Optimization Directions

  1. Adaptive Parameter Adjustment: The current strategy uses fixed HMA periods and ATR multipliers; consider dynamically adjusting these parameters based on market volatility. For example, use shorter HMA periods and larger ATR multipliers in high-volatility markets, and vice versa in low-volatility markets. This can better adapt to different market environments.

  2. Add Market Environment Filtering: Introduce market environment recognition mechanisms, such as volatility indicators (e.g., ATR/SMA) or trend strength indicators, trading only in market environments suitable for strategy characteristics. This can avoid generating too many trading signals under unfavorable market conditions.

  3. Optimize Position Management: The current strategy uses fixed-proportion money management; consider dynamic position adjustment based on risk models, such as the Kelly formula or fixed risk percentage method, adjusting position size according to signal strength and expected win rate.

  4. Incorporate Multi-Timeframe Analysis: Integrate trend judgment from higher timeframes, only entering positions when the trend direction is consistent with higher timeframes, improving trading win rates.

  5. Add Machine Learning Models: Use machine learning techniques to optimize indicator weights or build models to predict which signals are more likely to produce successful trades, further enhancing the strategy's selectivity and precision.

  6. Enhance Profit Management: The current strategy adopts fixed R-multiple targets; consider dynamically adjusting profit targets based on market volatility or support/resistance levels, or implementing a staged profit-taking strategy, partially reducing positions at different price levels.

Summary
The Dual HMA Momentum Breakout Trading Strategy is a comprehensive trading system that integrates trend following, momentum breakout, and volatility adaptation techniques. Through strict entry condition screening and scientific risk management, this strategy performs excellently in strong directional markets, capturing high-quality trading opportunities. The strategy's visual interface and systematic trading process make trading decisions more intuitive and objective.

Despite its numerous advantages, the strategy still faces challenges such as trend reversal point risks and signal deficiencies in low-volatility environments. By introducing adaptive parameter adjustments, market environment filtering, multi-timeframe analysis, and other optimization measures, the strategy's stability and adaptability can be further enhanced. Most importantly, traders using this strategy should make reasonable parameter adjustments based on their trading style and risk tolerance, and conduct thorough backtesting and simulation trading before live trading.

Through continuous improvement and optimization, the Dual HMA Momentum Breakout Trading Strategy has the potential to become a powerful weapon in a trader's toolkit, helping traders seize opportunities in volatile markets and achieve stable trading returns.

Strategy source code

/*backtest
start: 2024-06-30 00:00:00
end: 2025-06-28 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("⚡ HMA PowerPlay Strategy ⚡", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=5)

// === COLOR SETTINGS ===
bgColor            = input.color(color.new(color.white, 0), "Checklist Background")
titleColor         = input.color(color.blue, "Title Text Color")
textColor          = input.color(color.black, "Text Color")
trueColor          = input.color(color.green, "✅ Check Color")
falseColor         = input.color(color.red, "❌ Cross Color")
bullStrengthColor  = input.color(color.green, "Bullish Strength Color")
bearStrengthColor  = input.color(color.red, "Bearish Strength Color")
oscPanelBgColor    = input.color(color.new(color.white, 0), "Oscillator Panel Background")
pricePanelBgColor  = input.color(color.new(color.white, 0), "Price Panel Background")

// === INPUTS ===
rr_target   = input.float(3.0, "Final Reward Target", minval=0.5)
rr_riskFree = input.float(2.0, "Risk-Free Trigger", minval=0.5)
atrMult     = input.float(1.5, "ATR Multiplier for SL", minval=0.1)
hmaLen      = input.int(20, "HMA Period")
volLen      = input.int(20, "Volume SMA Length")

// === INDICATORS ===
hma20   = ta.hma(close, hmaLen)
hma200  = ta.hma(close, 200)
atr     = ta.atr(14)
volSMA  = ta.sma(volume, volLen)
sma5    = ta.sma(close, 5)
rsiVal  = ta.rsi(close, 14)
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)

// === CANDLE STRENGTH ===
candleRange = high - low
bullishStrength = candleRange > 0 and close > open ? ((close - open) / candleRange) * 100 : na
bearishStrength = candleRange > 0 and close < open ? ((close - open) / candleRange) * 100 : na

// === ENTRY CONDITIONS ===
sezHigh = ta.highest(high, 200)
sezLow = ta.lowest(low, 200)
smoothHigh = ta.sma(sezHigh, 5)
smoothLow = ta.sma(sezLow, 5)
sezMidline = (smoothHigh + smoothLow) / 2
trendUp = hma20 > hma200 and sma5 > hma200
trendDown = hma20 < hma200 and sma5 < hma200
strongBullishCandle = close > open and close > high[1]
strongBearishCandle = close < open and close < low[1]
sufficientDistanceLong = (close - hma20) > (atr * 0.5)
sufficientDistanceShort = (hma20 - close) > (atr * 0.5)
volumeAboveAverage = volume > volSMA
longEntrySignal = trendUp and strongBullishCandle and sufficientDistanceLong and volumeAboveAverage and close > sezMidline
shortEntrySignal = trendDown and strongBearishCandle and sufficientDistanceShort and volumeAboveAverage and close < sezMidline

// === POSITION STATUS ===
hasPosition = strategy.position_size != 0
isLong = strategy.position_size > 0
isShort = strategy.position_size < 0

// === OSCILLATOR ENTRY CHECK ===
rsiValid = rsiVal > 30 and rsiVal < 70
macdMomentum = macdLine > signalLine
oscillatorEntryOk = rsiValid and macdMomentum

// === PRICE PANEL ===
weeklyClose = request.security(syminfo.tickerid, "W", close[1])
dailyClose = request.security(syminfo.tickerid, "D", close[1])
isAboveWeekly = close > weeklyClose
isAboveDaily = close > dailyClose

var table pricePanel = table.new(position.top_left, 2, 3, border_width=1, frame_color=pricePanelBgColor, frame_width=1)
table.cell(pricePanel, 0, 0, "Last Closed Candle", text_color=titleColor)
table.cell(pricePanel, 1, 0, "Close Price", text_color=titleColor)
table.cell(pricePanel, 0, 1, "Weekly", text_color=textColor)
table.cell(pricePanel, 1, 1, str.tostring(weeklyClose, "#.##"), text_color=isAboveWeekly ? trueColor : falseColor)
table.cell(pricePanel, 0, 2, "Daily", text_color=textColor)
table.cell(pricePanel, 1, 2, str.tostring(dailyClose, "#.##"), text_color=isAboveDaily ? trueColor : falseColor)

// === TRADE STATE ===
var bool inLong = false
var bool inShort = false
var float entryPrice = na
var float stopLoss = na
var float takeProfit = na
var float riskFreeLevel = na

if longEntrySignal and not inLong and not inShort
    entryPrice := close
    stopLoss := entryPrice - atr * atrMult
    takeProfit := entryPrice + (entryPrice - stopLoss) * rr_target
    riskFreeLevel := entryPrice + (entryPrice - stopLoss) * rr_riskFree
    strategy.entry("Long", strategy.long)
    inLong := true

if shortEntrySignal and not inShort and not inLong
    entryPrice := close
    stopLoss := entryPrice + atr * atrMult
    takeProfit := entryPrice - (stopLoss - entryPrice) * rr_target
    riskFreeLevel := entryPrice - (stopLoss - entryPrice) * rr_riskFree
    strategy.entry("Short", strategy.short)
    inShort := true

if inLong
    if high >= riskFreeLevel
        strategy.exit("Risk-Free Exit Long", from_entry="Long", stop=entryPrice)
    else
        strategy.exit("Final Exit Long", from_entry="Long", stop=stopLoss, limit=takeProfit)
    if strategy.position_size == 0
        inLong := false
        entryPrice := na
        stopLoss := na
        takeProfit := na
        riskFreeLevel := na

if inShort
    if low <= riskFreeLevel
        strategy.exit("Risk-Free Exit Short", from_entry="Short", stop=entryPrice)
    else
        strategy.exit("Final Exit Short", from_entry="Short", stop=stopLoss, limit=takeProfit)
    if strategy.position_size == 0
        inShort := false
        entryPrice := na
        stopLoss := na
        takeProfit := na
        riskFreeLevel := na

// === CHECKLIST TABLE ===
checkIcon(cond) => cond ? "✅" : "❌"
checkColor(cond) => cond ? trueColor : falseColor

// === PLOTS ===
plot(hma20, color=color.blue, title="HMA 20")
plot(hma200, color=color.gray, title="HMA 200")
plotshape(longEntrySignal, style=shape.triangleup, location=location.belowbar, color=color.green, title="Long Signal")
plotshape(shortEntrySignal, style=shape.triangledown, location=location.abovebar, color=color.red, title="Short Signal")
Enter fullscreen mode Exit fullscreen mode

Strategy parameters

The original address: Dual HMA Momentum Breakout Trading Strategy: Volatility-Adaptive Trend Following System

Top comments (1)

Collapse
 
quant_fmz_5544836beadc814 profile image
Rebecca Chow

Dual HMA with momentum and volatility adaptation? That’s like giving your trend-following strategy a turbo boost and GPS! 🚀 Curious to see how it handles choppy markets. Nice work!