pine scripttradingview alertsautomationtradingview

How to Create TradingView Alerts with Pine Script (Complete Guide)

Learn how to set up custom alerts in TradingView using Pine Script. From simple price alerts to complex multi-condition signals sent to webhooks — this guide covers it all.

·5 min read

Why TradingView Alerts Matter

You can't watch charts 24/7. TradingView alerts solve this — they notify you the moment your conditions are met, so you can act without being glued to a screen.

With Pine Script, you go far beyond simple price alerts. You can create alerts for:

  • Custom indicator signal triggers
  • Multi-condition confluences
  • Breakouts from dynamically calculated levels
  • Webhook messages to trigger automated trades

Types of TradingView Alerts

1. Manual Price Alerts

Set directly from the chart — right-click a price level, add an alert. No Pine Script required. Good for one-off notifications but can't encode complex logic.

2. Indicator-Based Alerts

Triggered when a Pine Script condition becomes true. This is where custom scripts shine — you can encode exactly when you want to be alerted.

3. Webhook Alerts

Send a JSON message to any URL when an alert fires. Used to trigger automated trading bots, send messages to Discord/Telegram, or log signals to a database.


How to Add Alerts to a Pine Script Indicator

Step 1: Define Your Alert Condition

//@version=6
indicator("Alert Example", overlay=true)

fastMA = ta.ema(close, 9)
slowMA = ta.ema(close, 21)

bullCross = ta.crossover(fastMA, slowMA)
bearCross = ta.crossunder(fastMA, slowMA)

plot(fastMA, color=color.blue)
plot(slowMA, color=color.orange)

Step 2: Create Alert Events with alertcondition()

alertcondition(bullCross, title="Bullish Cross", message="EMA 9 crossed above EMA 21 — potential long signal on {{ticker}}")
alertcondition(bearCross, title="Bearish Cross", message="EMA 9 crossed below EMA 21 — potential short signal on {{ticker}}")

alertcondition() registers an alert type in the script — it doesn't fire an alert itself. Users set the alert from the TradingView UI.

Step 3: Set the Alert in TradingView

  1. Apply the indicator to your chart
  2. Click the Alert button (clock icon) or press Alt+A
  3. In the Condition dropdown, select your indicator
  4. Choose your alertcondition (e.g., "Bullish Cross")
  5. Set the notification method (popup, email, push, webhook)
  6. Click Create

Dynamic Alert Messages

Pine Script alert messages support placeholders that get filled with real values when the alert fires:

PlaceholderValue
{{ticker}}Symbol name (e.g., BTCUSDT)
{{exchange}}Exchange name
{{close}}Closing price
{{time}}Bar time
{{interval}}Chart timeframe

Example:

alertcondition(
  bullCross,
  title="Bull Cross",
  message="🟢 Bull cross on {{ticker}} at {{close}} ({{interval}} chart)"
)

This produces a message like: 🟢 Bull cross on BTCUSDT at 67842.50 (1h chart)


Using alert() Instead of alertcondition()

For more control — especially webhook messages — use alert() directly:

if bullCross and barstate.isconfirmed
    alert('{"action": "buy", "symbol": "' + syminfo.ticker + '", "price": "' + str.tostring(close) + '"}', alert.freq_once_per_bar_close)

The second argument controls frequency:

  • alert.freq_once_per_bar — fires once per bar (even while bar is forming)
  • alert.freq_once_per_bar_close — fires only on bar close (recommended, avoids repainting)
  • alert.freq_all — fires every time the condition is true

Always use alert.freq_once_per_bar_close for trading signals to prevent duplicate alerts and ensure the signal is confirmed.


Webhook Alerts for Automated Trading

Webhook alerts send a POST request to a URL with your custom message as the body. This is how traders connect TradingView to:

  • 3Commas — automated bot trading
  • Alertatron — trade execution
  • Discord/Telegram bots — signal channels
  • Custom servers — your own trading infrastructure

Setting Up a Webhook Alert

  1. In the alert creation dialog, select Webhook URL
  2. Enter your server's endpoint URL
  3. Set the message to valid JSON your server expects

Example webhook message for a trading bot:

{
  "action": "buy",
  "symbol": "{{ticker}}",
  "price": "{{close}}",
  "timeframe": "{{interval}}"
}

Common Alert Mistakes to Avoid

Alerting on Unconfirmed Bars

If you alert on the current bar's close before the bar closes, you'll get signals that repaint. Always use barstate.isconfirmed or alert.freq_once_per_bar_close.

Too Many Alert Conditions

TradingView has a limit on active alerts (50 for Pro, 400 for Premium). Design your indicators to combine conditions into fewer, higher-quality alerts.

Not Testing the Alert Logic

Always test your alert conditions with Bar Replay before going live. A bug in alert logic can fire false signals or miss real ones.


Example: Complete Indicator with Alerts

//@version=6
indicator("RSI Alert System", overlay=false)

rsiLen    = input.int(14, "RSI Length")
obLevel   = input.int(70, "Overbought")
osLevel   = input.int(30, "Oversold")

rsi = ta.rsi(close, rsiLen)

enterOB = ta.crossover(rsi, obLevel)
exitOB  = ta.crossunder(rsi, obLevel)
enterOS = ta.crossunder(rsi, osLevel)
exitOS  = ta.crossover(rsi, osLevel)

plot(rsi, color=color.blue)
hline(obLevel, color=color.red)
hline(osLevel, color=color.green)

alertcondition(enterOB, "Entered Overbought", "RSI entered overbought on {{ticker}}")
alertcondition(exitOS,  "Exited Oversold",    "RSI exited oversold on {{ticker}} — watch for long")

Summary

Pine Script alerts turn passive indicators into active notification systems. Use alertcondition() for standard alerts users configure themselves, or alert() for dynamic messages and webhook payloads. Always confirm alerts on bar close to avoid repainting signals.

Need a custom indicator with built-in alert conditions? Get a quote from TraderOSHQ — we build every indicator with production-ready alert logic included.

TraderOSHQ

Need a custom Pine Script indicator?

Professional Pine Script v6 development with 3–5 day delivery and lifetime support. Starting from $49.

Get a Quote