Pine 脚本如何添加标签而不是绘图

Pine script how to add labels instead of plot

我是 Pine 脚本的初学者,正在尝试新事物。以下是将每日枢轴作为步进线添加到图表的片段。但是,我想在每个值而不是行上添加标签。恳请您帮助实现这一目标。

sd = input(true, title="Show Daily Pivots?")

//Pivot Range Calculations - Mark Fisher
pivot = (high + low + close ) / 3.0 
bc = (high + low ) / 2.0 
tc = (pivot - bc) + pivot
r1 = (pivot * 2) - low
s1 = (pivot * 2) - high
r2 = pivot + (high - low)
s2 = pivot - (high - low)
r3 = r1 + (high - low)
s3 = s1 - (high - low)
r4 = r3 + (r2 - r1)
s4 = s3 - (s1 - s2)

//Daily Pivot Range 

dtime_r1 = security(syminfo.tickerid, 'D', r1[1])
dtime_r2 = security(syminfo.tickerid, 'D', r2[1])
dtime_r3 = security(syminfo.tickerid, 'D', r3[1])
dtime_r4 = security(syminfo.tickerid, 'D', r4[1])
dtime_s1 = security(syminfo.tickerid, 'D', s1[1])
dtime_s2 = security(syminfo.tickerid, 'D', s2[1])
dtime_s3 = security(syminfo.tickerid, 'D', s3[1])
dtime_s4 = security(syminfo.tickerid, 'D', s4[1])

offs_daily = 0 

plot(sd and dtime_r1 ? dtime_r1 : na, title="Daily r1",style=plot.style_stepline, color=color.green,linewidth=1)
plot(sd and dtime_r2 ? dtime_r2 : na, title="Daily r2",style=plot.style_stepline, color=color.green,linewidth=1)
plot(sd and dtime_r3 ? dtime_r3 : na, title="Daily r3",style=plot.style_stepline, color=color.green,linewidth=1)
plot(sd and dtime_r4 ? dtime_r4 : na, title="Daily r4",style=plot.style_stepline, color=color.green,linewidth=1)
plot(sd and dtime_s1 ? dtime_s1 : na, title="Daily s1",style=plot.style_stepline, color=color.red,linewidth=1)
plot(sd and dtime_s2 ? dtime_s2 : na, title="Daily s2",style=plot.style_stepline, color=color.red,linewidth=1)
plot(sd and dtime_s3 ? dtime_s3 : na, title="Daily s3",style=plot.style_stepline, color=color.red,linewidth=1)
plot(sd and dtime_s4 ? dtime_s4 : na, title="Daily s4",style=plot.style_stepline, color=color.red,linewidth=1)

像这样?

//@version=4
study("My Script", overlay=true)

sd = input(true, title="Show Daily Pivots?")

f_new_label(_title, _color) => label.new(na, na, _title, color=_color, style=label.style_label_left)

var label_r1 = f_new_label("r1", color.green)
var label_r2 = f_new_label("r2", color.green)
var label_r3 = f_new_label("r3", color.green)
var label_r4 = f_new_label("r4", color.green)

var label_s1 = f_new_label("s1", color.red)
var label_s2 = f_new_label("s2", color.red)
var label_s3 = f_new_label("s3", color.red)
var label_s4 = f_new_label("s4", color.red)

f_label_move(_label, _value) =>
    if sd
        label.set_xy(_label, bar_index, _value)
        label.set_text(_label, array.join(array.copy(array.slice(str.split(label.get_text(_label),""),0,2)),"") + " : " + tostring(round(_value,2)))
    else
        label.set_xy(_label, na, na)

//Pivot Range Calculations - Mark Fisher
pivot = hlc3
bc = hl2
tc = (pivot - bc) + pivot
r1 = (pivot * 2) - low
s1 = (pivot * 2) - high
r2 = pivot + (high - low)
s2 = pivot - (high - low)
r3 = r1 + (high - low)
s3 = s1 - (high - low)
r4 = r3 + (r2 - r1)
s4 = s3 - (s1 - s2)

//Daily Pivot Range 
[dtime_r1,dtime_r2,dtime_r3,dtime_r4,dtime_s1,dtime_s2,dtime_s3,dtime_s4] = security(syminfo.tickerid, 'D', [r1[1],r2[1],r3[1],r4[1],s1[1],s2[1],s3[1],s4[1]])

if barstate.islast
    f_label_move(label_r1, dtime_r1)
    f_label_move(label_r2, dtime_r2)
    f_label_move(label_r3, dtime_r3)
    f_label_move(label_r4, dtime_r4)
    
    f_label_move(label_s1, dtime_s1)
    f_label_move(label_s2, dtime_s2)
    f_label_move(label_s3, dtime_s3)
    f_label_move(label_s4, dtime_s4)