如何在延长线的某个点获取价值 - TradingView Pine 脚本

How to get value at a point of line extended - TradingView Pine script

我正在使用下面的代码画一条线:

//@version=4

simplesma = sma(close, 14)

var line3 = line.new(bar_index[0], high[0], bar_index, low, extend = extend.right)
line.set_xy1(line3, bar_index[5], simplesma[5])
line.set_xy2(line3, bar_index[3], simplesma[3])

该线已使用历史记录中的 2 个点绘制。

然后我用这段代码画了一个图

price_point = line.get_price(line3,bar_index)
plot(price_point, title='Price', color=#ffcc00, transp=30)

我正在尝试在标签上显示值,但以下代码不起作用:

var label3 = label.new(bar_index, high, text = "Value: "+ tostring(price_point, "#.########"), style = label.style_label_lower_left, color=#ffcc00, textcolor=#ff0000)
label.set_xy(label3,bar_index, price_point)

你能帮我在标签上显示吗?

变量 price_point 是当前柱 (bar_index) 的值。您不需要使用函数 tostring().

哦,我找到了。

var label3 = label.new(bar_index, high, text = "", style = label.style_label_lower_left, color=#ffcc00, textcolor=#ff0000)
label.set_xy(label3,bar_index, price_point)
label.set_text(label3, "Value: "+ tostring(price_point, "#.########"))