TradingView Pine Script Alert Tutorial (With Phone Call Example)
You've written a Pine Script that spots exactly what you're looking for. RSI crosses into oversold territory. Moving average flip. Custom breakout condition. It paints perfectly on historical bars. You run it live, go about your day, and the signal fires while you're away from your screen. You miss the trade.
The script isn't the problem. Delivery is.
Most Pine Script tutorials stop at getting the signal to appear on a chart. This one goes further: how to make your script fire a webhook alert, and how to route that webhook to a phone call so you act the moment the signal triggers.
The Three Alert Mechanisms in Pine Script
Before writing any code, you need to know which alert mechanism applies to your situation. There are three, and they are not interchangeable. Mixing them up is the most common reason custom alerts fail silently.
alertcondition() — The One That Doesn't Fire Itself
This is the biggest source of confusion for Pine Script beginners. alertcondition() does not trigger alerts. What it does is register a named condition in TradingView's "Create Alert" dialog, so a user can select it manually when setting up an alert.
If you've added alertcondition() to your indicator and nothing is happening, this is why. The function is working correctly. It just doesn't fire anything on its own. You still have to go into TradingView, open the alert dialog, choose your condition, and hit save.
Use alertcondition() when you want to expose a condition to other users of your published indicator. For firing alerts from your own script automatically, use alert() instead.
alert() — The One That Actually Fires
alert() is the function you want for most custom setups. It fires immediately when execution reaches the call, which you control by wrapping it in an if block. The message is a series string, meaning you can embed live calculated values directly into the payload.
This works in both indicator and strategy type scripts.
strategy.entry() / strategy.exit() with alert_message=
For strategy scripts, the correct approach for webhook alerts is to pass the payload as an alert_message= parameter on your strategy.entry() or strategy.exit() calls. When the strategy alert fires, TradingView sends that string to your webhook URL.
Do not call alert() separately alongside strategy entries. It causes duplicate alerts. Use one approach or the other.
Writing an Indicator with alert()
Here's a complete working indicator that fires a webhook alert when RSI crosses below 30. The payload is formatted as JSON: TradeAlert.Pro reads the text field and reads it aloud in your phone call.
//@version=5
indicator("RSI Phone Alert", overlay=false)
rsiLength = input.int(14, title="RSI Length")
rsiSource = input.source(close, title="Source")
rsiValue = ta.rsi(rsiSource, rsiLength)
plot(rsiValue, "RSI", color=color.purple)
hline(30, "Oversold", color=color.red)
hline(70, "Overbought", color=color.green)
oversoldCross = ta.crossunder(rsiValue, 30)
if oversoldCross
alertMsg = '{"text": "RSI oversold on ' + syminfo.ticker + ' — current RSI: ' + str.tostring(rsiValue, "#.##") + '"}'
alert(alertMsg, alert.freq_once_per_bar)
The alert.freq_once_per_bar argument means the alert fires once when the condition first becomes true on a bar. Without it, a fast-moving market could trigger the call dozens of times on a single candle. For phone call delivery, once per bar is almost always the right choice.
The message string is constructed dynamically: syminfo.ticker gives the current symbol, and str.tostring() converts the RSI float to a readable string. When the call comes through, it reads: "RSI oversold on AAPL, current RSI: 28.43." Enough to act on, nothing you don't need.
Writing a Strategy with Webhook Alerts
For strategy scripts, attach the alert payload directly to your entry and exit calls using alert_message=. Here's a moving average crossover strategy wired for phone call delivery:
//@version=5
strategy("MA Cross Phone Alert", overlay=true)
fastLength = input.int(9, title="Fast MA")
slowLength = input.int(21, title="Slow MA")
fastMA = ta.ema(close, fastLength)
slowMA = ta.ema(close, slowLength)
plot(fastMA, "Fast MA", color=color.blue)
plot(slowMA, "Slow MA", color=color.orange)
longCondition = ta.crossover(fastMA, slowMA)
shortCondition = ta.crossunder(fastMA, slowMA)
if longCondition
strategy.entry("Long", strategy.long,
alert_message='{"text": "BUY signal: ' + syminfo.ticker + ' fast MA crossed above slow MA. Price: ' + str.tostring(close, "#.##") + '"}')
if shortCondition
strategy.entry("Short", strategy.short,
alert_message='{"text": "SELL signal: ' + syminfo.ticker + ' fast MA crossed below slow MA. Price: ' + str.tostring(close, "#.##") + '"}')
When you create the alert on this strategy in TradingView's dialog, set the Message field to {{strategy.order.alert_message}}. That placeholder tells TradingView to send the alert_message string you defined in the code, rather than a generic message.
Connecting the Webhook to TradeAlert.Pro
Add your Pine Script indicator or strategy to the chart, then:
- Click the clock icon in TradingView's right toolbar to open Alerts
- Hit "Create Alert"
- In the Condition dropdown, select your indicator or strategy
- Open the Notifications tab
- Check "Webhook URL" and paste in your TradeAlert.Pro webhook URL
- Save the alert
When the condition fires, TradeAlert.Pro receives the JSON payload, extracts the text field, and calls your phone. You pick up, you hear the message, you decide whether to act.
Your TradeAlert.Pro webhook URL is in your dashboard after you connect your phone number. If you haven't done that yet, the setup takes about two minutes.
The 2FA Requirement
TradingView requires two-factor authentication on your account before webhooks work. If 2FA is not enabled, alerts fire as normal but the webhook request is silently dropped. No error, no indication anything went wrong.
Enable 2FA in your TradingView account settings before testing your webhook. It is the most common reason a correctly-written alert produces no call.
Building More Useful Alert Messages
Because alert() accepts a series string, you can embed any calculated value from your script directly into the payload. Some useful patterns:
str.tostring(close, "#.##") // price to 2 decimal places
str.tostring(rsiValue, "#.##") // indicator value
str.tostring(volume, "#,###") // volume with thousands separator
syminfo.ticker // symbol name
syminfo.description // full instrument name
timeframe.period // chart timeframe
A more detailed message might look like this:
alertMsg = '{"text": "' + syminfo.ticker + ' RSI hit ' + str.tostring(rsiValue, "#.##") + ' on the ' + timeframe.period + ' chart. Close: ' + str.tostring(close, "#.##") + '"}'
alert(alertMsg, alert.freq_once_per_bar)
The resulting phone call would read: "TSLA RSI hit 27.81 on the 15 chart. Close: 312.44." That is enough information to open your platform and make a decision immediately.
Alert Frequency Options
The second argument to alert() controls how often the alert can fire:
alert.freq_once_per_bar— fires once when the condition first becomes true on a bar. Best for most real-time setups.alert.freq_once_per_bar_close— fires only when the condition is true at the bar's official close. More reliable for end-of-bar signals; avoids alerts that trigger intrabar and then disappear.alert.freq_all— fires on every tick where the condition is true. Useful for very specific setups, but can generate a large volume of calls in a fast market.
For phone call delivery, stick with alert.freq_once_per_bar unless you have a specific reason to use bar close.
Common Mistakes
Using alertcondition() and expecting it to fire: It won't. Switch to alert() inside an if block.
Calling alert() in a strategy alongside strategy.entry(): This fires two alerts per signal. Remove the alert() call and use alert_message= on the entry instead.
Forgetting 2FA: Webhooks will silently fail. Enable it before your first test.
Sending plain text instead of JSON: TradeAlert.Pro parses the text field from a JSON payload. Wrap your message in {"text": "..."} format.
Not testing before going live: Use TradingView's "Test Alert" button in the alert dialog to fire a one-time test call before you rely on the alert in a live session. The technical webhook guide covers testing and troubleshooting in detail.
TradeAlert.Pro sends your TradingView alerts as a phone call — you pick up, you act. Free to try, no credit card needed.
Next Steps
Pine Script gives you three alert mechanisms: alertcondition() registers a condition in the dialog but does not fire itself; alert() fires from within your indicator or strategy logic; and strategy.entry/exit with alert_message= handles strategy webhooks. For most custom signal setups, alert() inside an if block is the right tool.
Structure your payload as JSON with a text field, enable 2FA, paste your TradeAlert.Pro webhook URL into the Notifications tab, and your script will ring your phone the moment the condition fires.
If you want to set up alerts on standard indicators without writing any Pine Script, setting up an alert for any indicator covers that process in full. For the complete guide to getting TradingView alerts as phone calls, including account setup and plan options, that post has everything you need to get started.