Python实现平滑平均K线(Smoothed Heikin Ashi)

本文介绍了SmoothedHeikinAshi,一种改进的平均K线技术,通过Python实现并展示了与常规HeikinAshi的对比,指出在捕捉大趋势时效果更好,但可能在震荡行情中表现一般,需配合其他指标优化回测。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

平滑平均K线(Smoothed Heikin Ashi)

对于平均K线(Heikin Ashi),交易者一般都比较熟悉,不熟悉的可以参见我写的文章Python实现Heikin Ashi(平均K线)。最近在tradeview上发现了Heikin Ashi的一种改进版本——平滑平均K线(Smoothed Heikin Ashi),据说效果要比常规的Heikin Ashi好几倍(本人未验证)。

计算公式

在这里插入图片描述
可以发现Smoothed Heikin Ashi就是对开盘价、最高价、最低价、收盘价的均价进行常规Heikin Ashi的计算,非常的简单。

Python实现

def smoothed_heikin_ashi(df, n=60, ma_type='EMA'):
    sha = pd.DataFrame(index=df.index, columns=['open', 'high', 'low', 'close'])
    alpha = 2 / (1 + n)
    if ma_type.lower() == 'sma':
        alpha = 1 / n
    sha['open'] = df['open'].ewm(alpha=alpha, adjust=False).mean()
    sha['high'] = df['high'].ewm(alpha=alpha, adjust=False).mean()
    sha['low'] = df['low'].ewm(alpha=alpha, adjust=False).mean()
    sha['close'] = df['close'].ewm(alpha=alpha, adjust=False).mean()
    return heikin_ashi(sha)

这里我默认使用EMA(60)对价格进行平均,当然也可以使用SMA(n, 1)进行平均。heikin_ashi()方法请参见我的这篇文章

绘制K线

使用东方财富300059的历史日K数据进行检验,使用mplfinance库绘制K线图。数据如下:
在这里插入图片描述

将原始K线、常规Heikin Ashi和Smoothed Heikin Ashi都绘制出来,方便比较。

import mplfinance as mf
sha = smoothed_heikin_ashi(data)
rha = heikin_ashi(data)
fig = mf.figure(style='charles')
ax0 = fig.add_subplot(3, 1, 1)
ax1 = fig.add_subplot(3, 1, 2)
ax2 = fig.add_subplot(3, 1, 3)
mf.plot(data, type='candle', ax=ax0, mav=(60,), axtitle='Original Kline')
mf.plot(rha, type='candle', ax=ax1, mav=(60,), axtitle='Regular Heikin Ashi')
mf.plot(sha, type='candle', ax=ax2, mav=(60,), axtitle='Smoothed Heikin Ashi')
mf.show()

结果如下:
在这里插入图片描述

小结

肉眼可见的Smoothed Heikin Ashi要更加的平滑,错误信号更少,能够非常好的刻画大趋势。但是对于震荡行情的情况,其表现也是不尽人意。
相信配合其他过滤指标进行回测,效果肯定比常规的Heikin Ashi要好。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值