> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quantnomad.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhook Alerts & Automation

> Send TradingView indicator alerts to bots, servers, and external services with webhooks: requirements, JSON message format, security, and testing.

> [!NOTE]
>
> **General TradingView information.** This section describes standard TradingView behavior, not a QuantNomad-specific feature. TradingView updates its interface regularly, so menu names and positions may differ slightly from what you see. When in doubt, check the [TradingView Help Center](https://www.tradingview.com/support/).

A webhook makes TradingView send an HTTP request to a URL of your choice every time an alert fires. It's the standard way to connect indicator signals to trading bots, messaging tools, spreadsheets, or your own code.

## How it works

```mermaid theme={null}
flowchart LR
  A[Indicator signal] --> B[TradingView alert fires]
  B --> C[HTTP POST to your webhook URL<br/>body = alert message]
  C --> D[Receiving service<br/>parses message and acts]
```

When the alert fires, TradingView sends an **HTTP POST** request to the URL. The request body is the alert message, after placeholders such as `{{ticker}}` have been replaced.

## Requirements

* A TradingView plan that includes webhook alerts. See [TradingView pricing](https://www.tradingview.com/pricing/).
* Two-factor authentication on your TradingView account, if TradingView prompts for it when you enable webhooks.
* A receiving URL reachable from the internet. TradingView only accepts ports 80 and 443 in webhook URLs.
* A receiver that responds quickly. TradingView cancels the request if the server takes longer than about three seconds, so acknowledge first and do slow work afterwards.

Check TradingView's [webhook documentation](https://www.tradingview.com/support/solutions/43000529348-about-webhooks/) for current requirements, timeouts, and the IP addresses webhooks are sent from.

## Set up a webhook alert

**1. Get the URL**

Copy the webhook URL from the receiving service, or set up an endpoint on your own server.

**2. Write the message**

Use the format the receiving service expects. If the message is valid JSON, TradingView sends it with a JSON content type. Otherwise it's sent as plain text.

**3. Attach the webhook**

In the alert's **Notifications** tab, enable **Webhook URL** and paste the URL.

**4. Test**

Trigger a test alert and confirm the receiving service got the expected message.

## JSON message template

Your message must be editable for this to work. Scripts that use `alert()` calls send their own fixed message. For strategies such as UT Bot v2 and UT Bot Pro, use **Order fills only** alerts, which let you write the message and use strategy placeholders:

```json theme={null}
{
  "source": "tradingview",
  "indicator": "UT Bot v2",
  "action": "{{strategy.order.action}}",
  "order_id": "{{strategy.order.id}}",
  "symbol": "{{exchange}}:{{ticker}}",
  "interval": "{{interval}}",
  "price": "{{strategy.order.price}}",
  "fired_at": "{{timenow}}"
}
```

* `{{strategy.order.action}}` is `buy` or `sell`, so one alert covers both directions.
* Keep placeholder values in quotes so the message is always valid JSON.
* Include `fired_at` so the receiver can reject delayed or duplicate messages.

## A minimal receiver

A small example of a server that receives and logs webhook alerts. It's a starting point for testing, not a production trading system.

```python webhook_receiver.py theme={null}
from flask import Flask, request, abort
import hmac, os

app = Flask(__name__)
SECRET = os.environ["WEBHOOK_SECRET"]

@app.post("/tradingview/<token>")
def tradingview(token):
    # Reject requests that don't know the secret path token
    if not hmac.compare_digest(token, SECRET):
        abort(404)
    alert = request.get_json(silent=True)
    if alert is None:
        abort(400)
    print(alert["indicator"], alert["action"], alert["symbol"], alert["price"])
    return "", 204
```

## Security

> [!WARNING]
>
> Anyone who knows your webhook URL can send requests to it. Treat it like a password.

* Include a long, random secret in the URL path or in the message, and reject requests without it.
* Never put exchange API keys or passwords in the alert message.
* Validate every field before acting on it, and reject unexpected symbols or values.
* Make the receiver idempotent: the same alert received twice should not place two orders.

## Before automating real trades

* Paper trade the full chain (indicator → alert → webhook → execution) first.
* Use **Once Per Bar Close** triggers to avoid acting on signals that later disappear. See [Confirmed vs Unconfirmed Signals](https://docs.quantnomad.com/guides/confirmed-signals.md).
* Monitor the alert log and your receiver's logs. Webhooks can be delayed or fail.
* Add limits in the execution layer: maximum position size, maximum orders per day, and a way to stop everything quickly.

> [!WARNING]
>
> **Educational use only.** QuantNomad indicators are analysis tools, not financial advice. Signals can be wrong, past behavior does not predict future results, and trading involves substantial risk of loss. Read the full [Risk Disclaimer](https://docs.quantnomad.com/support/disclaimer.md).

## Related

* [UT Bot v2 alerts](https://docs.quantnomad.com/free-indicators/ut-bot-v2/alerts.md)
* [UT Bot Suite alerts & automation](https://docs.quantnomad.com/premium-indicators/ut-bot-suite/alerts.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.