TradingView is a pretty powerful charting tool and there are quite a lot of features. I receive quite a lot of questions about alerts in TradingView. There is quite a lot of ways to send alerts from it, so I decided to create a small article explaining it. Here are 5 ways to send alerts from TradingView:
1. Alert from the screener.
In TradingView there is a pretty nice built-in screener, you can find it under the product tab:
You can set up certain filters and if you’re satisfied with the results you can create an alert and receive regular alerts with results of this screener:
When I’m wiring this article these alerts are not functional. It seems like TradingView wants to update is, so I’m waiting for more interesting and advanced features:
2. Alert without coding from the chart
In TradingView you can create a custom alert from the chart even without coding. For that, you can basically use anything plotted on your chart and use basic conditions to form these alerts. To create one click on a new alert on the top of your screen:
In the first section “Condition” you can select variables you want to use and what operation should be used for the signal. So with the current setup you can check if the price crossed over the Upper and receive alerts when it is happening:
There are 13 different operations you can use:
Because you can use everything plotted on your chart you can cover quite a lot of cases. For everything more advanced you have to code your custom alert.
3. Alertcondition function
This is the oldest and the less flexible way to fire alerts in TradingView. It works only from indicators, and it’s not dynamic. But it’s quite easy to use it and in simple cases might be pretty useful. Here is a typical syntax of these alerts:
alertcondition(ta.crossover(close, upper), "Cross Upper", "Cross Upper")
alertcondition(ta.crossunder(close, lower), "Cross Lower", "Cross Lower")
The first parameter is your condition, the second alert name, and the third is the default message. When you add these function calls and then add them to the chart in the alert creation dialog you should see all the alerts you created this way:
With these alerts you had to specify alert frequency as well:
4. Alerts from strategy
Let’s look at the following strategy code in Pine Script:
//@version=5
strategy("Bollinger Bands Strategy", overlay=true)
source = close
length = input.int(20, minval=1)
mult = input.float(2.0, minval=0.001, maxval=50)
[basis, upper, lower] = ta.bb(source, length, mult)
if (ta.crossover(close, lower))
strategy.entry("BBandLE", strategy.long, stop=lower, alert_message = "Current close " + str.tostring(close))
else
strategy.cancel(id="BBandLE")
if (ta.crossunder(close, upper))
strategy.entry("BBandSE", strategy.short, stop=upper, alert_message = "Current close " + str.tostring(close))
else
strategy.cancel(id="BBandSE")
Apply it to your chart and go to the Alert creation dialog. In the first input, you should be able to select your strategy name:
When you choose it TradingView will send you an alert on every order fill. You can also customize your alert with certain placeholders. During the alert execution, Pine Script will replace them with the corresponding values. Here is a default example of an alert message with placeholders:
Bollinger Bands Strategy (20, 2): order {{strategy.order.action}} @ {{strategy.order.contracts}} filled on {{ticker}}. New strategy position is {{strategy.position_size}}
There is a special placeholder: {{strategy.order.alert_message}}. It’s different because it is dynamic and you can precompute it in the code and pass its value to the alert_message parameter of every order.
5. Alert function
Alert function is the most recent and most advanced way to send alerts from Pine Script. First, it works both from indicators and strategy, second it is completely dynamic and you can compose any alert messages in the code.
It’s quite easy to use these functions. You have to specify 2 parameters: alert message and frequency. Next every time Pine Script will see one of these functions it will fire an alert. To fire an alert base on the condition you can wrap it in “if” statement, as here for example:
if ta.crossover(close, upper)
alert("Cross Upper: " + str.tostring(close), freq = alert.freq_once_per_bar)
if ta.crossunder(close, lower)
alert("Cross Lower: " + str.tostring(close), freq = alert.freq_once_per_bar)
This code covers 2 alerts: when price crossover higher and when price crossunder lower. When creating the alert you have to create only 1 for both. Select your script name and then “any alert() function call”
As I mentioned you can use the alert function in strategies as well and even you can mix it with standard strategy alerts. When creating alerts for this kind of strategy you’ll see the following options:
So that was a quick introduction to alerts in TradingView. If you want to know more about Pine Script check out my courses.
Follow me on TradingView and YouTube.