Pine Script trading alerts are notifications triggered by custom logic in TradingView indicators or strategies. Pine Script โ TradingView's proprietary scripting language โ provides two alert mechanisms: the modern alert() function for dynamic messages with real-time data, and the legacy alertcondition() for static boolean triggers. Combined with TradingView's webhook system, Pine Script alerts can deliver entry, stop loss, and take profit data to Telegram, Discord, email, SMS, or trade automation services.
This guide covers the alert() function syntax, repaint prevention, webhook integration, and best practices used in production trading systems like Gold Scalpers.
The Two Pine Script Alert Functions
| Function | Pine Script Version | Best For |
|---|---|---|
alert() | v4 and later | Dynamic messages with real-time variables |
alertcondition() | v3 and later (legacy) | Static text alerts, simple boolean triggers |
The alert() Function: Modern Approach
The alert() function fires when conditions are met during script execution and accepts dynamically-built messages:
//@version=6
indicator("Custom Alert Example", overlay=true)
rsi = ta.rsi(close, 14)
if rsi < 30
msg = "BUY @ " + str.tostring(close) + " | RSI: " + str.tostring(rsi)
alert(msg, alert.freq_once_per_bar_close)
Key parameters:
- message: any string โ typically built from real-time variables
- frequency:
alert.freq_once_per_bar,alert.freq_once_per_bar_close, oralert.freq_all
How to Avoid Repainting Alerts
Repainting occurs when an alert fires intrabar and the signal disappears after the candle closes. To prevent this:
- Use
alert.freq_once_per_bar_closeinstead ofalert.freq_once_per_bar - Only check signal conditions on confirmed bars: wrap your alert logic in
if barstate.isconfirmed - Avoid
lookahead.oninrequest.security()calls - Test by examining bar history vs real-time behavior โ they should match exactly
Webhook Integration for Pine Script Alerts
To deliver Pine Script alerts to external services (Telegram, Discord, brokers), use TradingView's webhook system:
- Build your alert message as JSON or HTML in Pine Script
- Click โฐ โ Create Alert in TradingView
- Set Condition to "Any alert() function call"
- Enable Notifications โ Webhook URL
- Paste your endpoint URL (e.g., Telegram bot API or PineConnector relay)
Pine Script Alert Limitations by Plan
| TradingView Plan | Active Alerts | Webhooks | Cost/month |
|---|---|---|---|
| Free / Basic | 1 | โ No | $0 |
| Essential | 20 | โ No | $15 |
| Plus | 100 | โ No | $30 |
| Premium | 400 | โ Yes | $60 |
| Pro+ | 800 | โ Yes | $30 (annual billing) |
Note: Pricing accurate as of May 2026. Webhooks require Pro+ or higher.
Common Alert Patterns
Pattern 1: Single condition trigger
if ta.crossover(close, ema)
alert("Crossover: " + str.tostring(close), alert.freq_once_per_bar_close)
Pattern 2: Multi-filter signal (used by Gold Scalpers)
signal = isOversold and isVolumeSpike and isRangeFilter and twoGreens
if signal
msg = '{"action":"buy","entry":' + str.tostring(close) +
',"sl":' + str.tostring(slPrice) +
',"tp":' + str.tostring(tpPrice) + '}'
alert(msg, alert.freq_once_per_bar_close)
Pattern 3: Alert with HTML formatting (for Telegram)
msg = "๐ฏ BUY SIGNAL\n๐ Entry: " + str.tostring(close) + ""
alert(msg, alert.freq_once_per_bar_close)
Frequently Asked Questions
What is Pine Script?
Pine Script is TradingView's proprietary scripting language for creating custom indicators, strategies, and alerts. It runs on TradingView servers and supports real-time market data and technical analysis functions.
What's the difference between alert() and alertcondition()?
alert() fires alerts with dynamic messages built from real-time variables. alertcondition() uses static text defined at script load. Use alert() for entry/SL/TP messages, alertcondition() for simple boolean triggers.
Do alerts work on free TradingView accounts?
Yes, but limited to 1 active alert with no webhook URL support. Webhooks require Pro+ ($30/month).
Can Pine Script alerts execute trades automatically?
Not directly. Pine Script outputs webhook JSON that relay services (PineConnector, TradersPost) convert into broker orders.
How do I prevent repainting alerts?
Use alert.freq_once_per_bar_close, wrap logic in if barstate.isconfirmed, avoid lookahead.on.