Heikin Ashi与考夫曼自适应移动平均线交易策略(HLC3/Kaufman Strategy)是一个结合Heikin Ashi K线和考夫曼自适应移动平均线(KAMA)的量化交易策略。该策略通过Heikin Ashi K线来确定交易方向,再利用考夫曼自适应移动平均线作为辅助指标进行交易信号过滤。
该策略主要由以下几个部分组成:
计算Heikin Ashi开盘价、收盘价。这些价格反映了K线实体的中间价格,可以过滤掉部分噪声。
计算考夫曼自适应移动平均线(KAMA)。KAMA能够动态调整自己的平滑度,在市场突发大幅波动时不会产生太多滞后。
比较Heikin Ashi收盘价与KAMA的大小关系来确定买入和卖出信号。当Heikin Ashi收盘价上穿KAMA时产生买入信号;当Heikin Ashi收盘价下穿KAMA时产生卖出信号。
可以添加ADX指标来判断趋势强弱,避免在震荡市场中产生错误信号。
该策略最大的优势在于结合了Heikin Ashi K线和KAMA的双重过滤,可以大大减少噪声交易和错误信号。具体优势如下:
Heikin Ashi与考夫曼自适应移动平均线交易策略是一种双重滤波的趋势跟踪策略。它结合了Heikin Ashi K线的去噪功能和KAMA对趋势变化的快速跟踪优势,能够有效过滤噪声交易、减少错误信号,适合追踪中长期趋势。该策略可以通过参数优化、辅助指标确认等手段进一步增强稳定性和盈利能力。
/*backtest
start: 2022-12-12 00:00:00
end: 2023-12-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
//Heikin/Kaufman by Marco
strategy("HLC3/Kaufman Strategy ",shorttitle="HLC3/KAU",overlay=true)
res1 = input(title="Hlc3 Time Frame", defval="D")
test = input(1,"Hlc3 Shift")
sloma = input(20,"Slow EMA Period")
//Kaufman MA
Length = input(5, minval=1)
xPrice = input(hlc3)
xvnoise = abs(xPrice - xPrice[1])
Fastend = input(2.5,step=.5)
Slowend = input(20)
nfastend = 2/(Fastend + 1)
nslowend = 2/(Slowend + 1)
nsignal = abs(xPrice - xPrice[Length])
nnoise = sum(xvnoise, Length)
nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2)
nAMA = nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
//Heikin Ashi Open/Close Price
//ha_t = heikinashi(tickerid)
//ha_close = request.security(ha_t, period, nAMA)
//mha_close = request.security(ha_t, res1, hlc3)
bha_close = request.security(syminfo.ticker, timeframe.period, nAMA)
bmha_close = request.security(syminfo.ticker, res1, hlc3)
//Moving Average
//fma = ema(mha_close[test],1)
//sma = ema(ha_close,sloma)
//plot(fma,title="MA",color=black,linewidth=2,style=line)
//plot(sma,title="SMA",color=red,linewidth=2,style=line)
bfma = ema(bmha_close[test],1)
bsma = ema(bha_close,sloma)
plot(bfma,title="MA",color=black,linewidth=2,style=line)
plot(bsma,title="SMA",color=red,linewidth=2,style=line)
//Strategy
//golong = crossover(fma,sma)
//goshort = crossunder(fma,sma)
golong = crossover(bfma,bsma)
goshort = crossunder(bfma,bsma)
strategy.entry("Buy",strategy.long,when = golong)
strategy.entry("Sell",strategy.short,when = goshort)