How webhook automation works
- The alert fires. A price level, indicator condition or strategy order on your TradingView chart triggers an alert.
- TradingView sends a request. It posts your alert message to the webhook URL you set.
- Your server checks it. It confirms the request is genuine and the instruction is valid.
- Your server calls the broker. It places the order through your broker's API.
- The broker checks the order. Margin and risk checks run before the order reaches the exchange.
What TradingView requires
| Requirement | Detail |
|---|---|
| Plan | A paid plan. The free Basic plan does not include webhooks |
| Security | Two-factor authentication turned on for your TradingView account |
| Ports | Port 80 (HTTP) or 443 (HTTPS) only |
| Network | IPv4 addresses only |
| Response time | Your server must reply within 3 seconds, or the request is cancelled |
| Sending IPs | 52.89.214.238, 34.212.75.30, 54.218.53.128 and 52.32.178.7 |
| Message format | Sent as JSON if the message is valid JSON, otherwise as plain text |
Write the alert message
Send a JSON message with only what your server needs. Placeholders in double braces are replaced with live values when the alert fires.
{
"secret": "replace-with-a-long-random-string",
"symbol": "NIFTY26OCTFUT",
"action": "{{strategy.order.action}}",
"price": "{{close}}",
"sent": "{{timenow}}"
}Useful placeholders:
| Placeholder | Value |
|---|---|
{{ticker}} | The chart's symbol |
{{close}} | Closing price of the bar |
{{time}} | Time the bar opened |
{{timenow}} | Time the alert fired |
{{interval}} | The chart's timeframe |
{{strategy.order.action}} | buy or sell, for strategy alerts |
{{strategy.order.contracts}} | Quantity of the strategy order |
{{strategy.position_size}} | Position size after the order |
TradingView's symbols differ from your broker's. Nifty's continuous futures chart is NIFTY1! on TradingView, while Zerodha calls the October 2026 contract NIFTY26OCTFUT. Put your broker's symbol in the message, as above, or map one to the other on your server.
A strategy that sends alerts
Strategy alerts send one alert per order. This Pine Script strategy buys when the 9-period EMA crosses above the 21-period EMA and exits when it crosses back.
//@version=6
strategy("EMA crossover", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")Add an alert on the strategy, paste the JSON message above and enter your webhook URL. {{strategy.order.action}} becomes buy on entry and sell on exit. Strategies calculate on closed bars by default, which stops signals that appear and vanish within a bar. For indicator alerts, choose "Once per bar close" for the same reason.
Build the receiving server
This Flask server accepts alerts, checks the secret and the symbol, and places the order through Zerodha's Kite Connect API. Other brokers' APIs work in a similar way. Our Python and Kite Connect guide covers the login and order details.
import hmac
import os
from flask import Flask, abort, request
from kiteconnect import KiteConnect
app = Flask(__name__)
kite = KiteConnect(api_key=os.environ["KITE_API_KEY"])
kite.set_access_token(os.environ["KITE_ACCESS_TOKEN"]) # renew every trading day
ALLOWED = {"NIFTY26OCTFUT": 65} # symbols this server may trade, with quantity
@app.post("/tradingview")
def tradingview():
data = request.get_json(silent=True) or {}
if not hmac.compare_digest(str(data.get("secret", "")), os.environ["WEBHOOK_SECRET"]):
abort(403)
symbol, action = data.get("symbol"), data.get("action")
if symbol not in ALLOWED or action not in ("buy", "sell"):
abort(400)
order_id = kite.place_order(
variety=kite.VARIETY_REGULAR,
exchange=kite.EXCHANGE_NFO,
tradingsymbol=symbol,
transaction_type=kite.TRANSACTION_TYPE_BUY if action == "buy" else kite.TRANSACTION_TYPE_SELL,
quantity=ALLOWED[symbol],
product=kite.PRODUCT_NRML,
order_type=kite.ORDER_TYPE_MARKET,
market_protection=-1, # required for market orders through the API
)
return {"order_id": order_id}To run it for real:
- Use a cloud server with a static IP, and register that IP with your broker.
- Run the app with a production server such as Gunicorn behind Nginx, with an HTTPS certificate on port 443.
- Allow only TradingView's four IP addresses through the firewall.
- Log every alert and every broker response.
Security checklist
- Use HTTPS so the message is encrypted in transit.
- Include a long random secret in the message and compare it in constant time, as the example does.
- Accept only the symbols and quantities you expect, and cap the quantity.
- Never put broker passwords, two-factor codes or access tokens in an alert message.
- Ignore repeated alerts, for example by recording the bar time and action of each order.
- Keep two-factor authentication on for both TradingView and your broker.
Rules in India
An order your server places through your broker's API is an algo order under SEBI's retail algo framework.
- Static IP: orders must come from a static IP registered with your broker.
- Order rate: your own algo can run without exchange registration if it sends fewer than 10 orders a second, for your account or your immediate family's.
- Daily login: broker access tokens expire every day, so the server needs a new token each morning. An alert that arrives with an expired token places no order.
- Market orders: brokers apply market protection to market orders from algos, and Zerodha rejects API market orders sent without a market protection value.
- Sharing: if you let other people use your setup, you become an algo provider, which needs empanelment with the exchanges.
Some brokers offer their own webhook URLs for TradingView alerts. Otherwise you need a server like the one above, or a platform such as QuantPower, between TradingView and your broker's API. See SEBI's algo trading rules for the full framework.
Test before going live
- Send a test alert to a request-inspection service and check that the JSON is valid.
- Point the alert at your server and log the request without placing an order.
- Place orders with the smallest quantity during market hours.
- Check that exits work as well as entries.
- Watch the first full day with your broker's app open.
Common problems
| Problem | Likely cause | Fix |
|---|---|---|
| No request reaches the server | Free plan, or two-factor authentication is off | Upgrade the plan and turn on two-factor authentication |
| The server receives text, not JSON | The message is not valid JSON, often because of smart quotes or a missing comma | Check the message in a JSON validator |
| Requests time out | The server takes longer than 3 seconds | Reply at once and place the order in the background |
| Orders rejected for IP | The server's IP is not registered with the broker | Register the static IP |
| Orders stop after the first day | The access token expired | Log in each trading day and update the token |
| Duplicate orders | The alert fires more than once per bar | Use "Once per bar close" and ignore repeats |
Without running a server
If you would rather not build and maintain your own webhook server, QuantPower's TradingView algo trading receives your alerts and passes the orders to your broker account. You paste the webhook URL and alert message that QuantPower gives you into the alert. QuantPower is trading software, not a broker. It runs on your own computer or VPS, and the orders go to your broker through its official API, with your own API key, from the static IP you register with your broker, after your daily broker login with two-factor authentication, and within the limit for self-built algos of fewer than 10 orders a second. Keep that computer or VPS on and logged in to your broker during market hours. The rules are your own, and your funds and securities stay with your broker.
You can also set indicator rules directly in QuantPower's signal trading, backtest them, run them in paper trading and cap losses with an MTM stop loss.
Related guides
- Trading API: what a broker API does and how your code calls it
- Python for algo trading: login, orders and live data with Kite Connect
- Upstox API for algo trading: algo trading through Upstox's API
- TradingView India: alerts to orders through QuantPower
Start your free trial
Connect your broker, build a strategy and test it on paper before a single live order goes out.
Frequently asked questions
Are TradingView webhooks free?
No. Webhooks need a paid TradingView plan and two-factor authentication. The free Basic plan does not include them.
What is the difference between an API and a webhook?
Your code calls an API to ask for data or place an order. A webhook works the other way: another service calls your URL when something happens, such as an alert firing. A TradingView setup uses both: TradingView's webhook calls your server, and your server calls the broker's API.
Is TradingView webhook trading legal in India?
Yes, through your broker's API within SEBI's rules: a registered static IP, a daily login and, for your own algo, fewer than 10 orders a second without registration.
What happens if my server is down when an alert fires?
The order is not placed. Monitor the server and be ready to place or exit trades from your broker's app.
Can I trade options from a Nifty chart alert?
Yes. The alert can fire on the Nifty chart while your server chooses the option contract, such as the at-the-money strike of the nearest expiry, and places that order.
Sources
- SEBI, circular on safer participation of retail investors in algorithmic trading, 4 February 2025, and glide-path circular, 30 September 2025 (sebi.gov.in)
- NSE, implementation standards for retail algo trading, 5 May 2025, and operational modalities, 22 July 2025 (nseindia.com)
- TradingView Help Center, "How to configure webhook alerts" (tradingview.com), and TradingView plans page (tradingview.com), checked 20 October 2026
- Zerodha, Kite Connect API documentation and pricing (kite.trade)
- Kite Connect forum, "Preparing to comply with SEBI's retail algo rules (Static IP, ratelimits, order types)" (kite.trade), checked 20 October 2026
