TradingView Webhook JSON Format: Alert Message Examples (2026)
A TradingView webhook sends the text of your alert message to a URL you choose every time the alert fires. If that text is valid JSON, the server receiving it can read the symbol, side and size and place a real order. This guide shows the JSON format that works, copy-ready alert message examples for strategies and indicators, and the mistakes that make webhooks fail silently.
How TradingView webhooks work
When you create an alert, open the Notifications tab and tick Webhook URL. TradingView then sends an HTTP POST request to that URL with the alert message as the request body. A few facts decide how you build the receiving side:
- Webhooks need a paid TradingView plan and two-factor authentication turned on in your account.
- TradingView only sends to ports 80 (HTTP) and 443 (HTTPS). A URL like
http://1.2.3.4:5000/webhookwill not be called. - If the message is valid JSON, TradingView sends it with the header
Content-Type: application/json. Otherwise it is sent astext/plain. - Your server must answer quickly. If it takes more than about 3 seconds, TradingView cancels the request, so place the order in the background and reply straight away.
- There is no retry. If your server is down when the alert fires, that signal is lost.
The basic JSON alert message
Keep the message small and give every field one clear job. This is a good starting format for a manual alert:
{
"secret": "change-me-long-random-string",
"symbol": "{{ticker}}",
"exchange": "{{exchange}}",
"action": "buy",
"qty": 1,
"price": {{close}},
"time": "{{timenow}}"
}
The parts in double curly braces are placeholders that TradingView replaces when the alert fires. {{ticker}} becomes for example AAPL, {{close}} the bar's closing price, and {{timenow}} the time the alert fired in UTC.
Notice that {{close}} has no quotes around it, so it arrives as a number. Text placeholders such as {{ticker}} must be inside quotes, or the JSON is invalid.
Alert message for a Pine Script strategy
For a strategy, use the strategy placeholders so one alert handles every entry and exit. TradingView fills them from the order the strategy just placed:
{
"secret": "change-me-long-random-string",
"symbol": "{{ticker}}",
"action": "{{strategy.order.action}}",
"qty": {{strategy.order.contracts}},
"position_after": {{strategy.market_position_size}},
"order_id": "{{strategy.order.id}}",
"comment": "{{strategy.order.comment}}",
"price": {{strategy.order.price}}
}
{{strategy.order.action}} is buy or sell. {{strategy.market_position_size}} is the strategy's position after the order, which is the safest value to act on: your server can compare it with the real broker position and only trade the difference. That keeps the account in sync even if one alert was missed.
Create the alert on the strategy itself and choose Order fills only or Order fills and alert() function calls as the condition.
Alert message from an indicator with alert()
Indicators can't use the strategy placeholders. Instead, build the JSON in Pine Script and send it with alert():
//@version=6
indicator("EMA cross webhook", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
msg(side) =>
'{"secret":"change-me","symbol":"' + syminfo.ticker +
'","action":"' + side + '","price":' + str.tostring(close) + '}'
if ta.crossover(fast, slow)
alert(msg("buy"), alert.freq_once_per_bar_close)
if ta.crossunder(fast, slow)
alert(msg("sell"), alert.freq_once_per_bar_close)
Then create one alert on the indicator with the condition Any alert() function call. Leave the message box alone: the text comes from the script. Using freq_once_per_bar_close stops the alert firing several times while a bar is still moving.
A minimal server that receives the webhook
This Python example uses Flask. It checks the secret, answers immediately, and hands the order to a background thread:
from flask import Flask, request, abort
import threading
app = Flask(__name__)
SECRET = "change-me-long-random-string"
def place_order(data):
# call your broker API here: IBKR, MT5 bridge, Binance...
print("order", data["action"], data["symbol"], data.get("qty"))
@app.post("/webhook")
def webhook():
data = request.get_json(silent=True)
if not data or data.get("secret") != SECRET:
abort(403)
threading.Thread(target=place_order, args=(data,)).start()
return "ok", 200
In production, run it behind a web server with HTTPS on port 443, log every alert you receive, and store the alert ID so the same signal is never traded twice.
Common mistakes
- Invalid JSON. A missing quote or a trailing comma turns the body into plain text and your server rejects it. Paste the message into a JSON validator with sample values before going live.
- Quoting numbers wrong.
"qty": "{{strategy.order.contracts}}"sends text, not a number. Either remove the quotes or convert it on the server. - Wrong port. Only 80 and 443 are called. Use a domain with HTTPS.
- Slow response. Placing the order before replying can take longer than TradingView waits. Reply first, trade after.
- No secret. Anyone who finds your URL could send orders. Always check a secret in the message.
- Alerts that expire. Alerts on lower plans can expire. Check the expiry date on every live alert.
- Repainting signals. Alerts that fire before the bar closes can disappear later on the chart. Fire on bar close unless your strategy needs intrabar entries.
Frequently asked questions
Can TradingView send webhooks on the free plan?
No. Webhook alerts need a paid plan, and two-factor authentication must be on.
Does TradingView retry a failed webhook?
No. If your server is offline or too slow, the alert is not sent again. That is why the server should run on a VPS and compare positions with the broker instead of trusting every single alert.
Can one webhook trade several accounts?
Yes. The server receives the alert once and can send the order to as many broker accounts as you configure, each with its own position size.
Do I need PineConnector or a similar service?
Not necessarily. Ready-made bridges are quick to start with but you pay monthly and work within their message format. A webhook server you own costs only a small VPS and does exactly what your strategy needs.
Want it built for you?
We build webhook bridges that connect TradingView to Interactive Brokers, MetaTrader 5 and crypto exchanges, with position checks, logging and 24/7 hosting. See TradingView to IBKR automation and custom trading bot development. Related: TradingView alerts to MT5 and TradingView Pine Script to IBKR.