如何使指标的值出现在警报消息中?

问题描述

正如标题所暗示的,我想了解有关如何使指标的值出现在警报消息中的信息。简而言之,我需要在消息中显示除了 eur / usd 的价格之外,还有触发警报时 atr 的值,以便我可以设置我的 SL 和 TP。如果您理解了这一点,甚至可以进行 eurusd 价格减去 2 * atr 之类的交易,那也太棒了,谢谢您的帮助

解决方法

使用 tostring 函数在警报消息中添加值。

参考手册中的示例:

//@version=4
study("`alert()` example","",true)
ma = sma(close,14)
xUp = crossover(close,ma)
if xUp
    // Trigger the alert the first time a cross occurs during the real-time bar.
    alert("Price (" + tostring(close) + ") crossed over MA (" + tostring(ma) +  ").",alert.freq_once_per_bar)
plot(ma)
plotchar(xUp,"xUp","▲",location.top,size = size.tiny)

与 atr 公式输出值的逻辑相同。

更多例子: https://kodify.net/tradingview/alerts/plot-alerts-text/