在 Pine Script 中,尝试将计算中的变量值打印到 alert() 函数

In Pine Script, trying to print variable value from calculation to alert() function

我在 pine 脚本上有以下行:

differencevalue = math.abs(val-val_1)
plot(differencevalue, title="dvalue")

在指标 window 上成功绘制。

我还有提醒功能:

alert("{{dvalue}} LONG -> "+ sym, alert.freq_once_per_bar)

但我无法使用此警报功能来打印“differencevalue”的值。

警报的其余部分有效,但打印“differencevalue”..

{{dvalue}}

我希望得到一些反馈。

Alert() 函数不受占位符的限制,您可以在其中使用任何变量。

本文来自 TradingView 博客 post:

Also it’s worth remembering that there’s no limit on the number of variables that can be used in the dynamic alert message and that placeholders are no longer necessary, as any variable used in a script can also be used in the new alert() function calls, as long as it is in string format.

你可以试试这个:

differencevalue = math.abs(val-val_1)
plot(differencevalue, title="dvalue")
alert(str.tostring(differencevalue) + "LONG ->" + sym)