In this post, we are going to look at Tradingview alerts, how to create them and address some questions you might be asking yourself about them. With that in mind, I think the best place to start is to create simple script an alert in the code. Then we can look at how to subscribe to it and some final points to be aware of.
Creating Alerts
Creating an alert is nice and easy. There is a built-in function we can call that is appropriately named alertcondition()
. The function itself has 3 input parameters which are well explained in the pine script reference manual. Having said that, it will not will hurt cover them again here:
condition
: This is the condition that triggers the alert. For example,close
is greater than a certain value.title
: This is an optional parameter but in my opinion, it should be mandatory. If you do not provide a title, it becomes very hard to find the right alert when the time comes to subscribe to it.-
message
: This is again optional. It contains the message that appears on the alert. This can be used to remind you what the alert is signalling.
Briefly going back to the title parameter, an example of why adding a title to the alert is always a good idea is below. The image shows an indicator which contains 4 alerts, each without a title. How do you know which one to subscribe to?
Example Code
The following example code is a simple indicator that will plot two lines above and below the opening price of a bar. The distance between the lines is controllable by an input. This allows us to easily trigger an alert condition by moving the boundaries closer to price.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
//@version=3 study("Alert Tester", overlay=true) x = input(defval=0.00005, title='Min Pip Movement to trigger altert', type=float) upper = open + x lower = open - x alertcondition(high > upper, title='High > Upper Bound', message='The bar high has broken the upper boundary') alertcondition(low < lower, title='Low < Lower Bound', message='The bar low has broken the lower boundary') plot(upper, title='Upper Boundary') plot(lower, title='Lower Boundary') |
As you can see the default value is half a pipette. As such, this script should be used with a Forex pair for testing. Load the indicator up on a chart and you should see something like this:
Next, we need to create an alert. This is a pretty straightforward. A gallery below provides a step by step overview using the code. Before you follow that though, make sure you add the indicator to the chart. The indicator must be on the chart prior to creating the alert.
Some additional information that details the various preferences can be found on the Tradingview wiki here:
https://www.tradingview.com/wiki/Creating_and_Managing_Alerts
Note: The alert in this example is purposefully simple for testing the alertcondition()
function. However, in the real world, there is no point in creating an alert in the code to catch when price crosses a plotted line. This can be done without adding an alert condition in the code (see below). It is better to use the alertcondition()
function for more complex conditions.
Frequently (or not so frequently) Asked Questions
The following is a set of questions I asked myself when exploring alerts. Consider this an unofficial FAQ with answers derived from my testing. Given this, if anyone spots a mistake or flaw in the testing, please mention it in the comments below and I will take a look!
Why is the plot box / list of plots needed when creating an alert?
It is for creating further custom alerts inside the wizard. For example, you could trigger an alert when the upper boundary reaches a fixed level. Providing access to the plots allows end users to create their own custom alerts without touching the code. This also goes back to the note above about not needing to code alerts for simple conditions as they can be setup here without needing to add any further lines/complexity to your code.
For the purpose of this post, when creating one of our custom alerts (e.g. Low < Lower Bound
), it does not matter whether the Upper Bound
or Lower Bound
plot is selected. You can ignore this box.
Does the indicator need to be left on the chart?
No.
But as mentioned above, it does have to be on screen when you create the alert.
Does the chart need to be left on screen?
It also does not need to be. You can go away and browse other charts. An alert will pop up when the condition is met.
Are the default indicator values used for all alerts?
No, you can change the parameters and create an alert using that custom parameter set. Tradingview will remember the settings and monitor that. You can test this by:
- Add the indicator to the chart
- Edit the parameters (to something other than the default values)
- Create the alert.
- Remove and re-add the indicator
- Edit the alert
A note about email alerts
Be wary about relying on email alerts for time-sensitive entries. Depending on your email client and service provider, you might experience a delay in receiving the mail.
hello, can you put me through setting an alert for an indicator on tradingview? i am getting errors.
Hi Olu!
Welcome to the blog – What errors are you getting?
hello. please i need help with pine editor. i want to set alerts for when the red and blue arrow show on the charts using ‘pivot reversal strategy’ indicator. cant seem to find my way
Hi Olu – Unfortunately, Tradingview decided that the
alert()
function is not available when creating a strategy().At the start of a script you have a
study()
orstrategy()
call which decides whether you are coding an indicator or a backtest. Certain functions and variables are only available to the strategy and vice versa. Thealert()
function is only available in indicatorsThe first line of the pivot reversal strategy is this:
strategy("Pivot Reversal Strategy", overlay=true)
If you just want entry alerts, you can convert the script to an indicator and create an alert for “le”.
le := swh_cond ? true : (le[1] and high > hprice ? false : le[1])
Note that you will need to remove all the strategy specific stuff like
strategy.entry
Good Luck!
Thank you so much
did you manage to apply this alert? if so could you help, i need a dummy guide 🙂
Was you able to code I’m the alert?
Would also like to know if you manage to get it to work? Im also looking for email alert on pivot reversal strat. But cant find my way…
hello. please i need help with pine editor. i want to set alerts for when the red and blue arrow show on the charts using ‘blue sky day 90% strategy ’ indicator. cant seem to find my way
Hi Sinusomanal,
The blue sky day script is a strategy script. As such, you can not create alerts from a strategy script. You must port the whole script first to a study script and then use the
alertcondition()
function to allow users to create alerts from it.Note that the author does not provide the source code either so I don’t think you will be able to get the alerts you are looking for.
Hi,
What is integer function in pine script ?
Example:
x=123.4
I want return : 123
like excel function INT()
Thank you
Thanks for the article.
I have alerts set on a study script. The alerts normally get triggered whenever the conditions are met. However, occasionally the same alerts do not get triggered at all even though the conditions are met. Have you ever had this issue?
Thank you!
Hi Vicky
Yes – I have seen this occasionally. Tradingviews alert system is not the most robust. Once the condition is met, there is nothing more you can do.
I have noticed that it is more prevalent during times of high load.
I tested a basic script. While I am in a 5m renko chart, I created an alarm. However, even though there is no point for triggering alarm, it is raising the alarm. Very strange behaviour? Do you have any opinion regarding the issue?
My script is like below:
//@version=3
study(“My Script”)
gecici = ((close[1] open[2])) ? 1:0
alertcondition(gecici,message=’yeniden poz ac’)
plot(gecici,color=blue)
I don’t have much problems setting up the custom alerts myself, but i am stuck on “one server side alert limit” for a free account. is there a way to setup a nonserver side alert(s) using pine script? it seems like there should be a way… anyway that’s where i’m stuck on. any ideas would be helpful?
I think the message is misleading. I am not aware of any nonserver side alerts. Everything on Tradingview is configured through their platform.
—Hi, do you mind, can I ask a question?
–I get lots of alerts when I qualify
//Body Filter
dai = ema (close,2000)
body = ema (close,9)
abody = ema(close, 90)
lower=input(50)
mac = sma(close, 10)
len = abs(close – mac)
sma = sma(len, 100)
max = max(open, close)
min = min(open, close)
up = close sma * 1 and min < min[1] and fastrsi abody
down = crossover(body,dai)
alertcondition(up, title=”up”, message = “LONG”)
alertcondition(down, title=”short”, message = “sell”)
–I want to get only 1 alert, and repeat when a sell alert is made.
what should I do???
Hi Hoang,
You might need this article: https://backtest-rookies.com/2018/05/25/tradingview-simulating-positions-in-a-study/
🙂