Trend Trading Strategy Based on Dynamic Moving Average
Overview
This strategy generates trading signals based on the dynamic moving average to go long when stock prices rise and close positions when prices fall. By combining the advantages of momentum indicators and moving averages, it aims at tracking medium-term price trends for steady profits.
Principle
The strategy mainly relies on three Hull Moving Average (HMA) variants – regular HMA, Weighted HMA (WHMA) and Exponential HMA (EHMA). As the code shows, it allows users to switch between the three Hull MAs.
The formula for HMA is:
HMA = WMA(2*WMA(close, n/2)-WMA(close, n), sqrt(n))
Where WMA is the Weighted Moving Average and n is the period parameter. Compared to SMA, HMA responds faster to price changes.
The formulas for WHMA and EHMA are similar. HMA is chosen as the default option.
After calculating the HMA, the strategy uses the midline value of HMA as trading signals. It goes long when the price crosses above the HMA midline and closes positions when the price falls below the line. Thus it tracks medium-term trends using the HMA midline for profits.
Advantages
Compared to traditional MA strategies, this strategy has the following edges:
- Faster response and stronger trend-following ability for timely entries and stops
- Lower unnecessary trade frequency, avoiding chasing surges and stops
- Flexible HMA parameters for adapting to more market environments
- Switchable HMA variants to expand applicability
Risks
There are also some risks:
- Generating multiple false signals during range-bound markets, increasing trade frequency and slippage costs
- Missing trend reversal points if HMA parameters are not set properly, leading to greater loss risks
- Liquidity risk and huge slippage when trading low liquidity stocks
Solutions:
- Optimize HMA parameters for best values
- Add other indicators to determine trend reversal points
- Select liquid stocks with large average daily volume
Improvements
The strategy can also be enhanced from the following aspects:
- Add volume or other filters to ensure signal reliability
- Combine MACD, KDJ for better timing, improving win rate
- Adjust HMA periods based on real-trade backtests
- Switch to WHMA or EHMA that performs the best for specific stocks
- Add stop loss mechanisms to control single trade loss
Summary
The dynamic MA trading strategy integrates the fast response of HMA to effectively track medium-term price trends. By opening long positions at appropriate timing and closing stops, it has demonstrated good backtest results. Further improvements in parameter tuning and stock filtering would lead to more steady excess returns. It is an easy-to-implement, risk-controllable quantitative strategy.
/*backtest
start: 2022-12-14 00:00:00
end: 2023-12-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy('Position Investing by SirSeff', overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0)
strat_dir_input = input.string(title='Strategy Direction', defval='long', options=['long', 'short', 'all'])
strat_dir_value = strat_dir_input == 'long' ? strategy.direction.long : strat_dir_input == 'short' ? strategy.direction.short : strategy.direction.all- 1

