How to use pine script alertcondition?

 The alertcondition() function in pinescript can be used to create option in drop down menu of alert creation window of TradingView pinescript platform. It only create option and therefore does not set, create or can be used to trigger alert.

Before we understand fully on how pinescript altercondition can be used, we must understand how manually alert can be set in tradingview platform using alert creation window.

Setting Alert in TradingView 

Step 1 : Open the chart of scrip for which you want to set alert in tradingview platform. Here, I have opened the chart of GOOG.

Step 2 : Open alert creation window by pressing "Alt +A" or alternatively you can click on the alert icon on right panel with icons as shown below:


Step 3 :  The below is alert creation window for "GOOG" script, here you can fill all details for creation of alert. You will find that in this window you don't have many options for setting up alert, but still this is a powerful tool. 


You have many option for receiving alert, the list of options are not visible on above image so the scrolled down image showing all the option is shown below:


Here, you can see we have several options like to notify on app or show pop-up or send email and webhook url, you can also play sound or receive alert on SMS. If you are a long term investor you won't be checking prices very often and receiving prices on email can work for you. If you are a intraday trader, probably you keep your tradingview account open on app or on computer then you can choose to receive alert as pop-up with sound or on app.

Step 4 : Just click create button and your alert will be saved and can be viewed, reviewed, edited by clicking alert icon or pressing alt+A.


Using PineScript's Function alertcondition

As discussed above, pinescript does not offer many options for settingup alert conditions. Most of the alert conditions are relating to price. If you want to set an alert for extremely high volume activity. There is no option in Alert creation window that we opened by pressing alt +A. In such cases, where you don't have option in the window , you can use alertcondition functions in pinescript to create option in the window. 

For example, I want to receive alert when volume is highest among last 60 bars. The code can be as under :

//@version=4
study("Demo Alertcondition",overlay=true)
volAlert = volume == highest(volume,60)
alertcondition(volAlert,"Volume highest 60 bars","Highest volume among last 60 bars found")
plot(close)
After you add the above code to the chart, again open alert creation window and you will find the option you were looking for. 


If you want to learn more on pinescript, goto out resource section.

Resources

Highest Rated Udemy Course on PineScript - Grab your Seat Now 

Udemy Discount Coupon Code : UDEMY-JAN23 (Valid upto 30th Nov 2023)

Learn more about coding on tradingview in PineScript through Books on pinescript available on amazon and kindle.


200+ pages book100 pages book200+ pages book


Point and Figure Charts : A Time-Tested Tool for Technical Analysis

In the dynamic world of financial markets, investors and traders constantly seek tools that can provide valuable insights into market trends...