Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

pine script - Pinescript: Use text variable in Alerts

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...