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

FunctionPine Script VersionBest For
alert()v4 and laterDynamic 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:

How to Avoid Repainting Alerts

Repainting occurs when an alert fires intrabar and the signal disappears after the candle closes. To prevent this:

  1. Use alert.freq_once_per_bar_close instead of alert.freq_once_per_bar
  2. Only check signal conditions on confirmed bars: wrap your alert logic in if barstate.isconfirmed
  3. Avoid lookahead.on in request.security() calls
  4. 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:

  1. Build your alert message as JSON or HTML in Pine Script
  2. Click โฐ โ†’ Create Alert in TradingView
  3. Set Condition to "Any alert() function call"
  4. Enable Notifications โ†’ Webhook URL
  5. Paste your endpoint URL (e.g., Telegram bot API or PineConnector relay)

Pine Script Alert Limitations by Plan

TradingView PlanActive AlertsWebhooksCost/month
Free / Basic1โŒ No$0
Essential20โŒ No$15
Plus100โŒ No$30
Premium400โœ… 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.

See Pine Script Alerts in Action

Gold Scalpers uses production-grade alert() patterns with no repainting. Try free for 7 days.

Start Free Demo โ†’