Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k 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 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...