如何阻止 pinescript 重新绘制标签?

问题描述 投票:0回答:0

我是编程界的新手,目前我正在尝试在 Pinescript 中编译一个指标,该指标将在图表上的各个行旁边绘制今天的柱高/低标签。但是当我应用我的脚本时,它会不断地在每个连续的蜡烛上重新绘制标签。我怎样才能让它只在最后一根进行中的蜡烛上保留标签?

感谢您的帮助!

这是我的脚本:

//@version=4
study("Day High/Low with Labels", overlay=true)

t = time("1440", session.extended) // 1440=60*24 is the number of minutes in a whole day. You may use "0930-1600" as second session parameter
//plot(t, style=linebr) // debug
is_first = na(t[1]) and not na(t) or t[1] < t
plotshape(is_first, color=color.red, style=shape.arrowdown)

var float day_high = na
var float day_low = na

if is_first and barstate.isnew
day_high := high
day_low := low
else
day_high := day_high[1]
day_low := day_low[1]

if high > day_high
day_high := high

if low < day_low
day_low := low


plot(day_high, color=color.green)
plot(day_low, color=color.red)

// Add text labels to show the current day's high and low
if barstate.islast
label.new(bar_index, day_high, "TDH", xloc=xloc.bar_index, yloc=yloc.price, color=color.rgb(0, 143, 74), textcolor=color.white, style=label.style_label_down, size=size.normal)
label.new(bar_index, day_low, "TDL", xloc=xloc.bar_index, yloc=yloc.price, color=color.rgb(255, 44, 44), textcolor=color.white, style=label.style_label_up, size=size.normal)`
pine-script trading
© www.soinside.com 2019 - 2024. All rights reserved.