本策略基于Alan Hull提出的Hull移动平均指标,属于趋势跟踪策略。该指标可以有效减少移动平均线的滞后效应,对价格变化响应更灵敏。策略使用Hull移动平均判断趋势方向,并结合额外过滤条件发出交易信号。
计算短周期和长周期两组Hull移动平均。短周期判断具体交易方向,长周期判断大趋势方向。
当短周期Hull MA上穿下穿时,判断趋势发生转折。结合大趋势方向过滤噪音交易。
增加价格突破Hull MA的条件,确保突破成功。
增加价格变化率条件,避免不理想的突破 Entry。
设置止损和止盈条件,控制风险。
相比普通移动平均线,该策略具有以下优势:
Hull MA响应价格变化更迅速,可以及时捕捉趋势转折。
双 Hull MA结构可以判断大、小两个时间维度的趋势。
价格突破与变化率条件可有效过滤假突破。
动态止损止盈可锁定利润,控制风险。
该策略也存在以下风险:
参数设定不当可能错过价格趋势转折。
大趋势判断错误可能导致逆势交易。
停止损失设定过宽可能带来较大亏损。
交易次数过于频繁,增加交易成本和滑点风险。
可从以下几个方面进行优化:
优化 Hull MA 周期,平衡敏感性和平滑性。
优化 Entry 和 Exit的参数,找到最优数值。
测试不同品种参数健壮性,提高策略适应性。
结合量能指标,避免背离造成的风险。
增加条件,提高策略的稳定性。
该策略整体来说,利用 Hull MA 的响应迅速性实现对趋势的及时跟踪,在控制风险的前提下,具有较强的盈利能力。但需要注意参数优化,并防范一些较难避免的系统性风险。
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-12 22:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
//SeaSide420
strategy("SS420FX", overlay=true, default_qty_type=strategy.percent_of_equity, max_bars_back=720, default_qty_value=100, calc_on_order_fills= true, calc_on_every_tick=true, pyramiding=0)
q=input(title="HullMA Short",defval=14)
z=input(title="HullMA Long",defval=14)
dt = input(defval=0.0010, title="Decision Threshold", type=float, step=0.0001)
SL = input(defval=-50000.00, title="Stop Loss in $", type=float, step=1)
TP = input(defval=100000.00, title="Target Point in $", type=float, step=1)
ot=1
n2ma=2*wma(close,round(q/2))
nma=wma(close,q)
diff=n2ma-nma
sqn=round(sqrt(q))
n2ma1=2*wma(close[1],round(q/2))
nma1=wma(close[1], q)
diff1=n2ma1-nma1
sqn1=round(sqrt(q))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
z2ma=2*wma(close[11],round(z/2))
zma=wma(close[11],z)
ziff=n2ma-nma
zqn=round(sqrt(z))
z2ma1=2*wma(close[12],round(z/2))
zma1=wma(close[12], z)
ziff1=n2ma1-nma1
zqn1=round(sqrt(z))
z1=wma(diff,sqn)
z2=wma(diff1,sqn)
z1e=z1>z2?green:black
z2e=z1>z2?black:red
z3e=z1>z2?green:red
n1e=plot(z1, title="HMA1", color=z1e, linewidth=2, offset=2)
n2e=plot(z2, title="HMA2", color=z2e, linewidth=2, offset=2)
fill(n1e, n2e, color=z3e, transp=80)
confidence=(security(syminfo.tickerid, 'D', close)-security(syminfo.tickerid, 'D', close[1]))/security(syminfo.tickerid, 'D', close[1])
closelong = n1<n2 and close<n2 and confidence<dt or strategy.openprofit<SL or strategy.openprofit>TP
if (closelong)
strategy.close("Long")
closeshort = n1>n2 and close>n2 and confidence>dt or strategy.openprofit<SL or strategy.openprofit>TP
if (closeshort)
strategy.close("Short")
longCondition = n1>n2 and z1>z2 and strategy.opentrades<ot and confidence>dt and close>n1
if (longCondition)
strategy.entry("Long",strategy.long)
shortCondition = n1<n2 and z1<z2 and strategy.opentrades<ot and confidence<dt and close<n1
if (shortCondition)
strategy.entry("Short",strategy.short)