Skip to content
Pinescripter

Send TradingView Alerts to Discord With Pine Script

Connect a Pine Script alert to a Discord channel using an incoming webhook. Learn the JSON format Discord expects, how to include live chart values, and how to test the setup.

A chart alert being delivered to a chat channel

To send TradingView alerts to Discord with Pine Script, create a Discord incoming webhook, put its URL in TradingView’s alert settings, and send a JSON message containing a content field. Use alert() when you need dynamic values such as the symbol and price.

How does the TradingView-to-Discord alert path work?

Pine Script does not send an HTTP request to Discord. Instead, the script defines an alert and its message; TradingView sends that message to the webhook URL you enter when creating the alert. Discord’s incoming webhook receives the request and posts the message to the channel linked to that webhook. Pine Script itself does not talk to Discord or receive a response from it. Read more about Pine Script and webhooks.

The setup has three parts:

  1. Discord: Create an incoming webhook for the channel where you want alerts to appear, then copy its URL.

  2. Pine Script: Create a condition and build a message in the format Discord expects.

  3. TradingView: Create an alert for the script, enable its webhook option, and paste in the Discord webhook URL.

Think of the webhook URL as a destination with posting access. Keep it private: anyone who has the URL may be able to post through it. Do not paste it into a public script, screenshot, or message. If it is exposed, replace or remove the webhook in Discord and update the TradingView alert.

The key detail is that Discord expects a message payload with a content field. A message that is plain text or JSON with only custom fields may not post as intended. Discord documents the webhook message fields in its webhook reference.

A chart signal passing through a webhook to a chat channel

How do you format a Discord-ready JSON alert?

For a basic text post, the JSON body should look like this:

{
"content": "Alert message goes here"
}

The outer braces and quotes matter. The property name must be content, and its value must be a string. For a quick first test, use a fixed message like Test alert from TradingView in the Create Alert message field. This checks the destination and JSON format before you add Pine variables or more elaborate formatting.

For a dynamic Pine Script alert, build the JSON string in code. This Pine Script v6 example sends a message when the close crosses above a moving average, and waits for the bar to close:

//@version=6
indicator("Discord alert example", overlay = true)

average = ta.sma(close, 50)
crossUp = ta.crossover(close, average)

if crossUp and barstate.isconfirmed
message = '{"content":"' + syminfo.ticker +
' crossed above its average. Close: ' + str.tostring(close) + '"}'
alert(message, alert.freq_once_per_bar_close)

plot(average)

The example’s message is a JSON object, not just a text string. Pine assembles the content value from the current ticker and closing price, and alert() sends the completed string when the condition is true. The closed-bar check helps avoid sending a signal from a candle that later changes before it closes. For more on the choice between alert() and alertcondition(), see our guide to choosing between alertcondition() and alert().

Test the finished message with your exact script and chart. If you later add user-controlled text or other values, make sure the resulting string remains valid JSON; embedded quotation marks can break the payload.

Should you use alert() or alertcondition()?

Use alert() when the message needs values calculated by the script, such as a symbol, price, or a custom variable. Its message can be assembled at runtime, so it fits a dynamic JSON body. The script controls when that call runs and can set its frequency in code.

Use alertcondition() when you want a named condition that someone selects in TradingView’s alert dialog. It is useful for straightforward indicator alerts, but the message is fixed text with TradingView placeholders rather than a dynamically assembled Pine string. For a Discord payload that changes with each signal, alert() is usually the more direct choice. Our Pine Script alert-message placeholders guide explains what those placeholders can supply and where they work.

Whichever method you use, decide when the condition should count as a signal. If it should only be sent once a candle is complete, gate it with barstate.isconfirmed and choose a close-based alert frequency. The right timing depends on your script’s rules; an intrabar alert can be useful if you deliberately want earlier notification, but the condition may change before the bar closes. See our explanation of Pine Script alert frequency for the differences.

How do you create and test the alert?

Once your script is on the chart and the Discord webhook is ready, configure TradingView’s alert so it sends the script’s message to the webhook:

  1. Open the alert-creation dialog for your chart and select the relevant script condition. For a script using alert(), choose the option for alert function calls.

  2. Set the alert’s trigger and expiry to match your needs. If your code is designed to fire at bar close, avoid choosing a setup that contradicts that intent.

  3. Turn on the webhook URL option and paste the Discord incoming webhook URL. Use the URL exactly as Discord provides it.

  4. Check the message field. If the message is built by alert() in your script, do not replace it with unrelated plain text; the code supplies the payload when it fires.

  5. Save the alert and verify it in the destination Discord channel when the condition occurs.

TradingView’s alert system delivers the message to the configured webhook; Discord then posts it to the associated channel. The TradingView alert must exist and be active for this chain to run. Adding a script to a chart is not, by itself, the same as creating an alert.

For a first test, use a condition you can observe and a simple content message. Confirm that the post lands in the expected channel before adding more fields, mentions, or formatting. Avoid testing with a live trading action: a Discord notification is just a message, not proof that an order was placed or that the signal is profitable.

A JSON alert payload connecting a chart to a chat message

What information can you include in the Discord message?

A Discord alert can be more useful when it says what happened and identifies the chart context. With alert(), you can combine values available to the script into the content string. For example, include the ticker, timeframe, close, or a short description of the trigger. Keep the message readable: a concise signal description is easier to scan than a dump of every calculated value.

For a basic message, you might build text along these lines:

message = '{"content":"' + syminfo.ticker +
' signal on ' + timeframe.period +
'. Close: ' + str.tostring(close) + '"}'

Use values your script can actually access. If you need a custom calculated value, build it into the message in Pine rather than expecting Discord or the webhook to infer it. TradingView placeholders are a separate mechanism: TradingView replaces supported tokens in alert messages, but they are not Pine variables that your script can read. Our guide to adding alerts to a complex Pine Script indicator covers adding alert logic without unnecessarily changing the indicator’s existing behavior.

Be careful with characters that have special meaning in JSON, especially quotation marks and backslashes. A malformed body may fail even if the signal condition is correct. Start with a plain text value, confirm it posts, and then add one field at a time.

Why is the TradingView alert not posting to Discord?

Check the message format, destination, and trigger separately rather than changing everything at once.

  • No post appears: Confirm the alert is active, the webhook option is enabled, and the URL is the Discord incoming webhook for the intended channel.

  • Discord rejects or ignores the body: Make sure the message is valid JSON and includes a content field. Check the quotes and braces, and ensure Pine is not producing an empty or broken string.

  • The message arrives without the expected values: Check that your script builds the message from the variables you intend to send. If using placeholders, verify the exact supported spelling and whether that placeholder applies to the alert mechanism you selected.

  • The alert never fires: Inspect the condition on the chart. A valid webhook cannot post if the script’s trigger does not become true. Confirm your alert is set to the right script and condition.

  • It fires before a bar closes or appears to disappear from the chart: Review the script’s confirmation logic and alert frequency. Intrabar conditions can change while a bar is forming.

  • It stopped working after a script change: Check that the alert still reflects the script and settings you intend to run. Alert configuration and a later workspace edit are not automatically the same thing; recreate or adjust the alert when its saved behavior no longer matches your current script.

A simple way to isolate the cause is to temporarily test a fixed content message. If that posts, the Discord URL and basic delivery path are likely working, so focus next on the dynamic Pine string or trigger. If it does not, review the webhook destination and TradingView alert configuration before debugging the signal logic.

How can you keep alerts reliable and secure?

Treat the Discord post as a notification, not as a complete monitoring or execution system. A message can tell you that a condition fired; it does not establish that a trade was filled, that an external service acted on the message, or that the signal will remain valid. If you use the notification as part of a larger workflow, check each handoff independently.

Keep the webhook URL private, and use a dedicated channel so messages are easy to spot. Include enough context to identify the signal—such as the ticker, timeframe, and a short reason—without putting sensitive information into the message. Test after changing the script’s condition, JSON construction, or alert settings.

Finally, check whether the script’s trigger matches what you mean by an alert. For a signal intended only after a candle closes, use confirmed-bar logic and close-based frequency. For a deliberately intrabar signal, understand that the condition can change before the candle completes. Our guide to building a repaint-free Pine Script alert system explains how alert mechanisms and timing choices affect that behavior.

The simplest dependable workflow is to start with one clear condition, send a minimal Discord content message, and confirm the complete path. Add dynamic values only after that first message works, then retest the finished version before relying on it.

Frequently asked questions

Does a Discord webhook need a bot?
Discord’s incoming webhooks can post messages to a channel without a bot user. Create an incoming webhook for the channel and use its URL as the TradingView alert destination.
What JSON does Discord need for a basic message?
Use a JSON object with a `content` field whose value is the message text, for example `{"content":"Test alert"}`. Keep the JSON valid and use the field Discord expects.
Can I include the symbol and price in a Pine Script alert?
Yes. With `alert()`, build the message string from values available in Pine, such as `syminfo.ticker` and `close`, then wrap the text in a JSON object with a `content` field.
Should I use alert() or alertcondition() for Discord?
Use `alert()` when you need a message assembled dynamically from script values. Use `alertcondition()` when you want a named condition selected in the alert dialog and a fixed message or supported placeholders.
Why does my TradingView alert not appear in Discord?
Check that the alert is active, its webhook option is enabled, the URL is correct, and the message is valid JSON with a `content` field. Also verify that the script condition actually fires.
Do I need to recreate an alert after editing Pine Script?
Review the alert after changing the script. If the saved alert’s condition, message, or behavior no longer matches your current code, update or recreate it and test the new setup.

This article was drafted with AI assistance from Pinescripter's own information and current sources.

  • A higher-timeframe trend chart aligned with a lower-timeframe entry chart

    Pine Script Multi Time Frame Strategy: Build and Test

    Learn how to combine a confirmed higher-timeframe trend filter with lower-timeframe entries in Pine Script v6, then check the strategy for repainting and weak test assumptions.

    Siddhant Chaudhary ·

  • Candlestick chart showing price approaching a limit order level

    Pine Script Strategy Limit Order Backtest

    A limit order backtest depends on more than the limit price in your code. Learn how to place Pine Script limit entries, interpret fills, and test assumptions carefully.

    Siddhant Chaudhary ·

  • Illustration of a trading position being built through successive entries

    Pine Script Strategy Pyramiding: Entries and Limits

    Pyramiding lets a Pine Script strategy add entries in the same direction. Learn how to set the limit, what strategy.entry() does, and how to check the resulting trades and exposure.

    Siddhant Chaudhary ·