英文:
How can I stop pinescript from label repainting?
问题
以下是您的翻译内容:
我在编程世界中相当新,目前正在尝试在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 the 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)
希望这对您有所帮助!
英文:
I am quite new in programming world, and currently I am trying to compile an indicator in Pinescript which would plot today's bar high/low labels on a chart, next to respective lines. But as I apply my script, it keeps repainting the label on each successive candle. How can I make it so that it would keep the label only on THE LAST progressing candle?
Thank you for any help!
Here's my script:
//@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)`
答案1
得分: 0
你要么删除旧标签,要么只是移动你的标签。
// 添加文本标签以显示当前日的高点和低点
如果 barstate.islast
lbl_tdh = 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)
lbl_tdl = 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)
label.delete(lbl_tdh[1])
label.delete(lbl_tdl[1])
英文:
You either delete the old label or just move your label.
// Add text labels to show the current day's high and low
if barstate.islast
lbl_tdh = 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)
lbl_tdl = 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)
label.delete(lbl_tdh[1])
label.delete(lbl_tdl[1])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论