Overview
This strategy utilizes a dual-period combination of Hull Moving Averages (HMA) to construct a complete trend-following trading system. Specifically, the strategy uses HMA 200 as the entry signal indicator, while HMA 150 is used for dynamic take-profit signal generation. Buy or sell signals are triggered when the price breaks through the HMA 200, and take-profit is executed when the price has a specific crossover relationship with the HMA 150. The strategy also includes configurable backtesting date ranges, allowing traders to evaluate strategy performance within specific time periods. This design captures medium to long-term trends while timely securing profits when trends weaken, forming a balanced quantitative trading system.
Strategy Principles
The core of this strategy is based on two Hull Moving Averages (HMA) with different periods: HMA 200 and HMA 150. The HMA is an advanced moving average indicator that significantly reduces lag while maintaining smoothness compared to traditional moving averages. The entry logic is based on the crossover relationship between the price and the slower HMA 200 line: a buy signal is generated when the closing price crosses above the HMA 200; a sell signal is generated when the closing price crosses below the HMA 200.
The take-profit logic uses the faster HMA 150 as a dynamic reference point: for long positions, take-profit is triggered when the price crosses below the HMA 150; for short positions, take-profit is triggered when the price crosses above the HMA 150. This design allows the take-profit level to adjust dynamically with the market, rather than using fixed profit targets.
The code implements a configurable backtesting date range feature, allowing traders to analyze strategy performance for specific historical periods by setting start and end dates, enabling more precise evaluation of strategy performance under different market conditions. The strategy also includes visualization components that intuitively display HMA lines, entry signals, and take-profit signals on the chart, making it easy for traders to understand market conditions and strategy decision points.
Strategy Advantages
Reduced Lag: HMA has lower lag compared to traditional moving averages, making entry and exit signals more timely, responding faster to market changes, and reducing potential opportunity costs.
Dual-Period Balanced Design: The strategy uses different periods of HMA for entry and take-profit, forming a balanced approach - the longer period (200) for robust trend direction identification, and the shorter period (150) for more sensitive profit protection, achieving both trend capture and profit locking objectives.
Fully Automated Trading System: The strategy has clear entry and exit rules that can be fully automated, reducing emotional interference and improving trading discipline. The visual signals on the chart also make strategy decision points clear at a glance.
Flexible Backtesting Functionality: Configurable date ranges allow traders to test the strategy for specific historical periods, helping to analyze strategy performance under different market conditions and optimize parameter settings.
Clear and Concise Logic: The core logic of the strategy is simple and direct, easy to understand and modify, making it convenient for traders to customize and extend according to their needs, suitable for traders of all levels.
Trend-Following Advantage: As a trend-following strategy, it can achieve significant returns in strong trend markets, particularly excelling in markets with sustained unidirectional movements.
Strategy Risks
Poor Performance in Range-Bound Markets: Like all trend-following strategies, it may perform poorly in sideways consolidations or highly volatile markets, prone to generating frequent false signals and losing trades.
Lack of Stop-Loss Mechanism: The current strategy does not integrate a stop-loss mechanism, which may lead to significant drawdowns when trends reverse but take-profit conditions have not yet been triggered. In practical applications, appropriate stop-loss rules should be considered to limit maximum losses per trade.
Fixed Parameter Limitations: The HMA periods (200 and 150) are fixed and may not be suitable for all markets or timeframes. Different trading instruments and time periods may require different parameter settings for optimal results.
Premature Exit from Strong Trends: In strong trends, the take-profit mechanism based on HMA 150 may cause premature exits from profitable trades, missing out on potential profits. This is an inherent contradiction between dynamic take-profit methods and trend persistence.
Lack of Position Management: The strategy does not include position sizing adjustments or risk management functions, using the same capital proportion for all trades, which may lead to excessive risk exposure in certain situations.
Single Indicator Dependency: The strategy relies solely on the HMA indicator without using other technical indicators or filters to confirm signals, potentially increasing the risk of false signals.
Strategy Optimization Directions
Add Stop-Loss Mechanism: Implement dynamic or fixed stop-loss rules, such as ATR-based stops, percentage stops, or stops based on support/resistance levels, to limit maximum loss risk per trade. This is crucial for capital protection, especially in cases of sudden trend reversals.
Adaptive Parameter Design: Dynamically adjust HMA periods based on market volatility or other market characteristics, enabling the strategy to adapt to different market environments. For example, use longer periods in higher volatility and shorter periods in lower volatility.
Add Market Environment Filters: Implement mechanisms to detect range-bound or trending markets, avoiding trades in range-bound markets or adjusting strategy parameters accordingly. Indicators such as ADX or Bollinger Band width can be used to assess market conditions.
Integrate Volume Analysis: Add volume indicators to confirm trend strength, executing signals only when supported by volume, reducing losing trades caused by false breakouts.
Implement Intelligent Position Management: Adjust position size based on volatility, account size, or risk parameters to ensure balanced risk and long-term stable capital growth. For example, implement ATR-based position size calculations or fixed risk percentage methods.
Multi-Timeframe Analysis: Add trend analysis of higher timeframes, executing trades only when the higher timeframe trend direction is consistent, improving signal quality and success rate.
Implement Trailing Stops: Replace fixed take-profit levels with trailing stops, allowing profits to continue growing while protecting them, particularly effective in strong trends. Trailing stops can be implemented based on HMA indicators, ATR, or percentage retracements.
Summary
The Dual-Period Hull Moving Average Trend-Following Strategy with Dynamic Take-Profit Mechanism offers an intuitive and effective trend-following approach combined with a dynamic take-profit mechanism. By leveraging the low-lag properties of two different period Hull Moving Averages, the strategy achieves a balance between capturing trends and protecting profits. The strategy's main advantages include clear signal generation, reduced signal lag, and customizable backtesting periods, making it a practical tool for trend-following traders.
However, the strategy also has some limitations, including poor performance in range-bound markets, lack of stop-loss mechanisms, and fixed parameter limitations. By implementing the suggested optimization measures, such as adding stop-loss rules, adaptive parameter adjustments, market environment filtering, and intelligent position management, the strategy can evolve into a more robust trading system suitable for various market environments.
Ultimately, this dual-period strategy based on Hull Moving Averages provides quantitative traders with a solid foundation that can be further customized and expanded according to individual risk preferences and trading objectives. In practical applications, traders should always remember the importance of risk management and conduct thorough backtesting and paper trading verification before live trading.
Strategy source code
/*backtest
start: 2024-06-03 00:00:00
end: 2025-06-02 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=5
//@strategy HMA 200/150 Trading Strategy
//@description A trend-following strategy using HMA 200 for entry signals and HMA 150 for take profit signals. Buys when price closes above HMA 200, sells when price closes below HMA 200. Take profit for buys when price closes below HMA 150, and for sells when price closes above HMA 150. Includes date range inputs for backtesting.
//@author [TrendBlazeX]
strategy("HMA 200/150 Trading Strategy", overlay=true, margin_long=100, margin_short=100)
// Input for backtest period
var start_year = input.int(2023, "Start Year", minval=1900, maxval=2100, group="Backtest Period")
var start_month = input.int(1, "Start Month", minval=1, maxval=12, group="Backtest Period")
var start_day = input.int(1, "Start Day", minval=1, maxval=31, group="Backtest Period")
var end_year = input.int(2025, "End Year", minval=1900, maxval=2100, group="Backtest Period")
var end_month = input.int(12, "End Month", minval=1, maxval=12, group="Backtest Period")
var end_day = input.int(31, "End Day", minval=1, maxval=31, group="Backtest Period")
// Convert dates to timestamps
start_timestamp = timestamp(start_year, start_month, start_day, 0, 0)
end_timestamp = timestamp(end_year, end_month, end_day, 23, 59)
// Check if current bar is within the date range
in_date_range = time >= start_timestamp and time <= end_timestamp
// Calculate HMAs
hma200 = ta.hma(close, 200)
hma150 = ta.hma(close, 150)
// Define conditions for buy and sell signals
buySignal = ta.crossover(close, hma200) and in_date_range
sellSignal = ta.crossunder(close, hma200) and in_date_range
// Define take profit conditions
buyTakeProfit = ta.crossunder(close, hma150) and in_date_range
sellTakeProfit = ta.crossover(close, hma150) and in_date_range
// Strategy entry and exit
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.entry("Sell", strategy.short)
if (buyTakeProfit)
strategy.close("Buy", comment="TP Buy")
if (sellTakeProfit)
strategy.close("Sell", comment="TP Sell")
// Plot HMAs on chart
plot(hma200, color=color.blue, title="HMA 200", linewidth=2)
plot(hma150, color=color.orange, title="HMA 150", linewidth=2)
// Plot signals on chart
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
plotshape(buyTakeProfit, title="Buy TP", location=location.abovebar, color=color.yellow, style=shape.diamond, size=size.tiny)
plotshape(sellTakeProfit, title="Sell TP", location=location.belowbar, color=color.yellow, style=shape.diamond, size=size.tiny)
Strategy parameters
The original address: Dual-Period Hull Moving Average Trend-Following Strategy with Dynamic Take-Profit Mechanism
Top comments (1)
Great work on this strategy! Using dual-period Hull Moving Averages for trend confirmation is a smart move — it gives the system both responsiveness and smoothness. The dynamic take-profit mechanism is a nice touch too, allowing the strategy to adapt to changing market volatility. I appreciate how clearly you’ve explained the logic behind each component. Definitely worth backtesting and exploring further in live conditions. Looking forward to seeing more strategies like this!