求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
相关产品推荐
相关产品推荐

