问题
I wish to include a text variable in the alertcondition.
I am using alertcondition(scr_label!="" ,title="1.Screener ALert",message="Screener Alert:"+scr_label)
Here scr_label is a dynamic text variable and I want the alert to give me that as the alert message. However if fires an alert without any message.
How can I achieve this?
回答1:
Detailed description in the documentation
Help Center•Alerts•Alerts settings• How to use a variable value in alert
The ability to generate variable text in alerts is very limited. I couldn't output a string variable in the alerts. In the following snippet, a workaround is how to output a color type variable in an alert.
plot(ColorS == #FF8C00 ? 1 : -1, title="colorA", display=display.none)
alertcondition(cross(LagFF,LagFS) and ColorF==ColorS, title='LagF', message='LagF cross {{ticker}} {{interval}} Up/Down {{plot("colorA")}}' )
Leave a feature request with TradingView via their support ticketing system. I think it is possible to add a placeholder {{label}}.
[ADDED]
Now you can do it like this
if scr_label!=""
alert("Screener Alert:"+scr_label, alert.freq_once_per_bar_close)
来源:https://stackoverflow.com/questions/65825212/pinescript-use-text-variable-in-alerts