Name
Hull移动平均振荡交易策略Hull-Moving-Average-Swing-Trading-Strategy
Author
ChaoZhang
Strategy Description
[trans]
该策略是基于Hull移动平均指标的短线交易策略。策略利用Hull移动平均线的金叉死叉形成买卖信号,属于趋势跟踪策略。
该策略主要基于Hull移动平均指标,Hull移动平均线由两个移动平均线组成。首先计算价格的中期移动平均线nma,周期为hullperiod。然后计算价格的快速移动平均线n2ma,周期为nma的一半。当n2ma上穿nma时发出买入信号,下穿nma时发出卖出信号。
为了过滤掉部分虚假信号,策略还引入了Hull线(Hull_Line)。Hull线是计算nma和n2ma之间差值的线性回归结果。当价格与Hull线发生背离时,策略会跳过买卖信号。
具体来说,策略规则如下:
-
计算nma,周期hullperiod
-
计算n2ma,周期为nma周期的一半
-
计算n2ma和nma的差值diff
-
对diff进行周期为sqrt(hullperiod)的移动平均,得到Hull线Hull_Line
-
当价格上穿Hull线时发出买入信号
-
当价格下破Hull线时发出卖出信号
-
如果价格与Hull线发生背离,跳过信号
-
以一定比例仓位入场,采用离场止损方式止损
该策略具有以下优势:
-
基于Hull移动平均,能够快速捕捉趋势,顺势而为
-
采用Hull线过滤虚假信号,提高信号质量
-
回撤和盈亏比良好,适合短线操作
-
参数调整灵活,可适应不同市场环境
-
采用反转止损,可以及时止损,控制风险
-
结合季节性,可避开特定时间段的系统性风险
该策略也存在一些风险:
-
跟踪趋势策略,无法做到全天候交易
-
当趋势反转时,会产生较大亏损
-
移动平均系统滞后,无法及时捕捉转折点
-
短线交易频繁,交易费用较高
-
参数设置不当可能导致震荡市收益下降
针对上述风险,可以采取以下措施加以控制:
-
采用马丁格尔止损策略,控制单笔亏损
-
优化参数,测试不同市场环境的参数健壮性
-
结合趋势判断指标,避免反转中的追涨杀跌
-
加大持仓时间,降低交易频率
该策略还可从以下几个方面进行优化:
-
结合动量指标,确定趋势的起始点位,更好的布局入场
-
增加机器学习模型,辅助判断趋势方向和力度
-
采用自适应参数设置,根据实时市场调整参数
-
配置多时间周期Hull系统,不同周期配置不同的仓位
-
结合交易量能量指标,避开量能不足的假突破
-
增加基于波动率的仓位管理模块,根据波动率动态调整仓位
Hull移动平均振荡交易策略整体是一个非常实用的短线跟踪策略。它利用Hull移动平均系统判断趋势方向,以达到顺势而为的目的。相比单一移动平均线系统,它具有更高的信号质量和 Parameters 灵活性。该策略优势在于快速捕捉趋势换向,以较低的回撤获利;劣势在于无法应对趋势反转。我们可以通过Parameter优化、止损策略改进、增加辅助模型等手段来控制风险,使策略在更多市场环境中稳定运行。
||
This strategy is a short-term trading strategy based on the Hull Moving Average indicator. The strategy uses the golden cross and dead cross of the Hull Moving Average lines to generate trading signals, belonging to a trend-following strategy.
This strategy is mainly based on the Hull Moving Average indicator. The Hull Moving Average line consists of two moving averages. First it calculates the median moving average line nma of the price, with a period of hullperiod. Then it calculates the fast moving average line n2ma, with a period of half of the nma's. When n2ma crosses above nma, a buy signal is generated. When n2ma crosses below nma, a sell signal is generated.
To filter out some false signals, the strategy also introduces the Hull Line (Hull_Line). The Hull Line is a linear regression result of the difference between nma and n2ma. When there is divergence between the price and the Hull Line, the strategy will skip the trading signal.
Specifically, the strategy rules are as follows:
-
Calculate the nma, with period hullperiod
-
Calculate the n2ma, with period half of the nma period
-
Calculate the difference diff between n2ma and nma
-
Moving average the diff with period sqrt(hullperiod),得到and get the Hull Line Hull_Line
-
When price crosses above Hull Line, a buy signal is generated
-
When price crosses below Hull Line, a sell signal is generated
-
If there is divergence between price and Hull Line, skip the signal
-
Enter with a certain percentage of the position, adopt exit stop loss
The advantages of this strategy include:
-
Based on Hull Moving Average, it can quickly capture the trend and follow the trend
-
Use Hull Line to filter false signals and improve signal quality
-
Good risk-reward ratio and drawdown, suitable for short-term trading
-
Flexible parameter tuning, adaptable to different market environments
-
Adopt reversal stop loss, can stop loss in time and control risks
-
Combine seasonality to avoid systemic risks in specific time periods
This strategy also has some risks:
-
Trend following strategy, cannot trade all day long
-
Larger losses when trend reverses
-
Lagging of moving averages, cannot timely capture turning points
-
High trading frequency leads to higher trading costs
-
Inappropriate parameter settings may lead to lower profitability in range-bound markets
To control these risks, we can take the following measures:
-
Adopt martingale stop loss strategy to control single loss
-
Optimize parameters and test robustness in different market environments
-
Combine trend judging indicators to avoid chasing trends during reversals
-
Increase holding time to lower trading frequency
This strategy can also be optimized in the following aspects:
-
Combine momentum indicators to locate the starting point of trends for better entry
-
Add machine learning models to assist in judging trend direction and strength
-
Adopt adaptive parameter setting to adjust parameters based on real-time market dynamics
-
Configure multi-timeframe Hull systems, with different position sizes for different timeframes
-
Combine volume indicators to avoid false breakouts with insufficient momentum
-
Add volatility-based position sizing model to dynamically adjust position sizes based on volatility
The Hull Moving Average Swing Trading Strategy is an efficient short-term trend following strategy overall. It uses the Hull Moving Average system to determine the trend direction for the purpose of following the trend. Compared with single moving average systems, it has higher signal quality and Parameters flexibility. The advantage of this strategy lies in quickly capturing trend changes with relatively small drawdowns. The weakness is the inability to cope with trend reversals. We can use Parameter optimization, stop loss strategies, adding auxiliary models etc. to control risks and make the strategy robust in more market environments.
[/trans]
Strategy Arguments
Argument | Default | Description |
---|---|---|
v_input_1 | 210 | HullMA Period |
v_input_2_open | 0 | Price data: open |
v_input_3 | true | From Month |
v_input_4 | true | From Day |
v_input_5 | 2020 | From Year |
v_input_6 | true | To Month |
v_input_7 | true | To Day |
v_input_8 | 9999 | To Year |
Source (PineScript)
/*backtest
start: 2023-09-06 00:00:00
end: 2023-10-06 00:00:00
period: 6h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
// Hull Moving Average Swing Trader by SEASIDE420
strategy("Hull Moving Average Swing Trader", shorttitle="HMA_Swing_Trader", default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=true, calc_on_every_tick=true, pyramiding=0)
hullperiod = input(title="HullMA Period", type=input.integer, defval=210, minval=1)
price = input(open, type=input.source, title="Price data")
FromMonth = input(defval=1, title="From Month", minval=1, maxval=12)
FromDay = input(defval=1, title="From Day", minval=1, maxval=31)
FromYear = input(defval=2020, title="From Year", minval=2017)
ToMonth = input(defval=1, title="To Month", minval=1, maxval=12)
ToDay = input(defval=1, title="To Day", minval=1, maxval=31)
ToYear = input(defval=9999, title="To Year", minval=2017)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
window() => true
n2ma = 2 * wma(price, round(hullperiod / 2))
nma = wma(price, hullperiod)
diff = n2ma - nma
sqn = round(sqrt(hullperiod))
n2ma1 = 2 * wma(price[1], round(hullperiod / 2))
nma1 = wma(price[1], hullperiod)
diff1 = n2ma1 - nma1
n1 = wma(diff, sqn)
n2 = wma(diff1, sqn)
Hull_Line = n1 / n1 * n2
Hull_retracted = if n1 > n2
Hull_retracted = Hull_Line - 2
else
Hull_retracted = Hull_Line + 2
c1 = Hull_retracted + n1 - price
c2 = Hull_retracted - n2 + price
c4 = n1 > n2 ? color.green : color.red
c2p = plot(c2, color=color.black, linewidth=1)
c3p = plot(price, color=color.black, linewidth=1)
fill(c3p, c2p, color=c4, transp=75)
//plot(cross(c1, c2) ? c1 : na, style=plot.style_circles, color=c4, linewidth=4)
if price < c2
strategy.close("BUY", when=window())
if price > c2
strategy.close("SELL", when=window())
if price > c2 and price[1] > c1
strategy.entry("BUY", strategy.long, when=window())
if price < c1 and price[1] < c2
strategy.entry("SELL", strategy.short, when=window()) // /L'-,
// ,'-. ` ```` / L '-,
// . _,--dMMMM\ ` ` ` '`.. / '-,
// : _,--, )MMMMMMMMM),. ` ,<> /_ '-,'
// ; ___,--. \MM( `-' )M//MM\ ,',.; .-'* ; .'
// | \MMMMMM) \MM\ ,dM//MMM/ ___ < ,; `. )`--' /
// | \MM()M MMM)__ /MM(/MP' ___, \ \ ` `. `. /__, ,'
// | MMMM/ MMMMMM( /MMMMP'__, \ | / `. `-,_\ /
// | MM /MMM---' `--'_ \ |-' |/ `./ .\----.___
// | /MM' `--' __,- \"" |-' |_, `.__) . .F. )-.
// | `--' \ \ |-' |_, _,-/ J . . . J-'-. `-.,
// | __ \`. | | | \ / _ |. . . . \ `-. F
// | ___ / \ | `| ' __ \ | /-' F . . . . \ '`
// | \ \ \ / | __ / \ | |,-' __,- J . . . . . \
// | | / |/ __,- \ ) \ / |_,- __,--' |. .__.----,'
// | |/ ___ \ |'. |/ __,--' `.-;;;;;;;;;\
// | ___ \ \ | | ` __,--' /;;;;;;;;;;;;.
// | \ \ |-'\ ' __,--' /;;;;;;;;;;;;;;\
// \ | | / | __,--' `--;;/ \;-'\
// \ | |/ __,--' / / \ \
// \ | __,--' / / \ \
// \|__,--' _,-;M-K, ,;-;\
// <;;;;;;;; '-;;;;
// :D
Detail
https://www.fmz.com/strategy/428614
Last Modified
2023-10-07 15:24:31