You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于PineScript绘制连续Heikin Ashi蜡烛组最高收盘价水平射线

修正后的Heikin Ashi同色蜡烛组射线指标(PineScript)

核心逻辑

要实现需求,关键是先识别Heikin Ashi蜡烛的颜色切换节点,再跟踪每个同色蜡烛组内的最高收盘价,最后在颜色切换时,针对前一组的最高值绘制水平射线。

完整代码

//@version=5
indicator("Heikin Ashi Group High Ray", overlay=true)

// 计算Heikin Ashi的开收盘价
haClose = ta.heikinashi_close
haOpen = ta.heikinashi_open

// 判断当前Heikin Ashi蜡烛颜色
isGreen = haClose > haOpen
isRed = haClose < haOpen

// 检测颜色切换:当前烛颜色与前一根不同
colorChanged = isGreen != isGreen[1]

// 跟踪当前同色蜡烛组的最高收盘价
var float currentGroupHigh = na
if colorChanged
    currentGroupHigh := haClose
else
    currentGroupHigh := math.max(currentGroupHigh, haClose)

// 在颜色切换时,绘制前一组的最高收盘价射线
if colorChanged[1]
    // 前一组的最高值是切换前的currentGroupHigh
    line.new(bar_index[1], currentGroupHigh[1], bar_index, currentGroupHigh[1], extend=extend.right, color=isGreen[1] ? color.green : color.red, width=2)

代码关键说明

  • Heikin Ashi计算:用内置函数ta.heikinashi_close和ta.heikinashi_open直接获取标准Heikin Ashi数据,避免手动计算误差。
  • 颜色切换检测:通过对比当前烛与前一根烛的颜色,确定同色组的结束点。
  • 组内最高值跟踪:每个同色组开始时初始化最高值,后续每根烛更新为组内最大值。
  • 射线绘制:在颜色切换的下一根烛(确保组已结束),用line.new绘制从组最后一根烛位置向右延伸的射线,绿烛组用绿色射线,红烛组用红色射线。

内容的提问来源于stack exchange,提问作者Mike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 19:07:35