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

求Pine Script v5脚本:高亮X周期移动平均线起始回溯K线/竖线

高亮X周期移动平均线对应回溯K线的Pine Script v5脚本

当然可以实现,下面的脚本会高亮指定周期移动平均线的起始计算K线(以50MA为例,对应回溯第50根K线——也就是索引为49的K线,因为Pine Script中bar_index从0开始计数):

//@version=5
indicator("高亮第50根K线", overlay = true)

// 定义需要高亮的K线索引(第50根K线索引为49,从零开始计数)
highlightCandleIndex = 49  

// 判断当前K线是否为目标高亮K线
highlightCondition = bar_index == highlightCandleIndex

// 设置高亮颜色(黄色,50%透明度)
highlightColor = color.new(color.yellow, 50)  

// 在目标K线下方绘制三角形标记作为高亮
plotshape(series = highlightCondition, color = highlightColor, style = shape.triangleup, location = location.belowbar)

// 可选:添加对应周期的均线作为参考
plot(ta.sma(close, 50), color=color.blue, title="50周期均线")

自定义调整说明

  • 适配其他周期均线:比如要高亮20MA对应的起始K线,只需把highlightCandleIndex改为19即可
  • 改用竖线高亮:替换plotshape为vline函数
    if highlightCondition
        vline(bar_index, color=highlightColor, width=2)
    
  • 直接高亮K线实体:使用barcolor函数
    barcolor(highlightCondition ? highlightColor : na)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 11:42:16