本策略基于Hull移动平均线指标,在不同的时间轴上计算Hull MA,并比较不同时间轴上的Hull MA走势,以发现趋势的变化。当短周期Hull MA上穿长周期Hull MA时 generate买入信号; 当短周期Hull MA下穿长周期Hull MA时 generate卖出信号。
输入参数:Hull MA周期Period, HMA2的时间轴Resolution2, HMA3的时间轴Resolution3
计算当前K线上的Hull MA值HMA
在Resolution2时间轴上计算Hull MA值HMA2
在Resolution3时间轴上计算Hull MA值HMA3
比较HMA、HMA2、HMA3的大小关系
当HMA>HMA2>HMA3时,产生买入信号
当HMA
在界面左上方显示不同时间轴上的Hull MA值和信号
使用颜色区分涨跌状态
使用多个时间轴可以过滤假突破,避免被套。
可自定义时间轴参数,适用于不同周期。
实时显示信号,操作直观。
可视化Hull MA走势,形成当前趋势判断。
参数设置不当可能导致过于频繁交易。
大周期Hull MA有滞后性,可能错过趋势转折点。
牛熊转换时,策略会产生虚假信号。
突破类策略,容易被假突破套牢。
交易手续费未考虑,会影响实际收益。
可通过优化参数,组合其他指标作为过滤,适当放宽止损线来减少风险。
优化Hull MA周期参数,适应不同周期和波动率。
增加成交量指标判断,避免虚假突破。
增加震荡指标,确定趋势强度。
增加机器学习模型判断买卖时机。
结合情绪指标,发现市场热点。
调整止损策略,优化风险管理。
自定义买卖条件,组合其他指标信号。
增加基于价格通道、波段的交易策略。
本策略基于Hull MA指标比较不同时间轴上的均线走势,判断当前趋势方向,在趋势发生转折时generate买入卖出信号。相比单一均线,多时间轴Hull MA可有效过滤假突破。但该策略也存在参数设置、趋势判断等问题。通过整合更多指标、优化参数设置、改进止损策略等手段,可以增强策略Profitability并控制风险。
/*backtest
start: 2023-10-07 00:00:00
end: 2023-11-06 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//
strategy("wtfBUYorSELLffs",overlay=true,currency="USD",initial_capital=100000,default_qty_type=strategy.percent_of_equity,default_qty_value=100,commission_type=strategy.commission.percent,commission_value=0.1)
Period=input(title="Hull MA Period",type=input.integer,defval=6,minval=1)
Resolution2=input(title="HMA2 Resolution", type=input.resolution,defval="60")
Resolution3=input(title="HMA3 Resolution", type=input.resolution,defval="240")
Price=input(title="Source of Price",type=input.source,defval=open)
xOffset = input(40, title="Panel offset (X-Axis)")
yOffset = input(0, title="Panel offset (y-Axis)")
lightgray = #D3D3D3FF
pnlTextColor = color.silver
pnlColor = color.black
HMA = hma(Price,Period)
HMA2 = security(syminfo.tickerid, Resolution2, HMA,barmerge.gaps_off,barmerge.lookahead_off)
HMA3 = security(syminfo.tickerid, Resolution3, HMA,barmerge.gaps_off,barmerge.lookahead_off)
HUP = HMA > HMA[1]
H1UP = security(syminfo.tickerid, Resolution2, HUP,barmerge.gaps_off,barmerge.lookahead_off)
H2UP = security(syminfo.tickerid, Resolution3, HUP,barmerge.gaps_off,barmerge.lookahead_off)
int barSize = timeframe.isdaily ? timeframe.multiplier*86400000 :
timeframe.isseconds? timeframe.multiplier*1000 :
timeframe.isminutes? timeframe.multiplier*60000 : (time[0]-time[1])
int lapos_x = timenow + barSize*xOffset
float lapos_y = highest(20) + yOffset*syminfo.mintick * syminfo.pointvalue
f_draw_infopanel(_x, _y, _line, _text)=>
_rep_text = ""
for _l = 0 to _line
_rep_text := _rep_text + "\n"
_rep_text := _rep_text + _text
// var label _la = na
// label.delete(_la)
// _la := label.new(
// x=_x, y=_y,
// text=_rep_text, xloc=xloc.bar_time, yloc=yloc.price,
// color=pnlColor, style=label.style_labelup, textcolor=pnlTextColor, size=size.normal)
// f_draw_infopanel(lapos_x, lapos_y, 8, "╚═══════════════════════╝")
f_draw_infopanel(lapos_x, lapos_y, 6, "HMA3 on TF " + Resolution3 + " = " + tostring(HMA3,"#.####") + (H2UP ? " BUY" : " SELL"))
f_draw_infopanel(lapos_x, lapos_y, 4, "HMA2 on TF " + Resolution2 + " = " + tostring(HMA2,"#.####") + (H1UP ? " BUY" : " SELL"))
f_draw_infopanel(lapos_x, lapos_y, 2, "HMA1 on TF " + timeframe.period + " = " + tostring(HMA,"#.####") + (HUP ? " BUY" : " SELL"))
f_draw_infopanel(lapos_x, lapos_y, 0, "╔═════════ HMA(" + tostring(Period,"#") +") ════════╗")
change_color=HMA>HMA3?color.green:color.red
change_color2=HMA2>HMA3?color.lime:color.yellow
plot1=plot(HMA3,color=change_color2,title="3 Hull MA Line",linewidth=2,transp=75)
plot2=plot(HMA2,color=change_color,title="2 Hull MA Line",linewidth=2,transp=75)
plot3=plot(HMA,color=color.white,title="Hull MA Line",linewidth=2,transp=75)
fill(plot1,plot3,color=change_color,transp=90)
fill(plot2,plot3,color=change_color2,transp=75)
if (H2UP and H1UP and HUP)
strategy.entry("BUY",strategy.long)
if (not H2UP and not H1UP and not HUP)
strategy.entry("SELL",strategy.short)