Free trial
Menu
Learn guide

Step-by-Step Webhook Automation Guide

A TradingView webhook sends an HTTP request to a URL you choose every time an alert fires. This guide explains API vs webhook, what TradingView requires, how to write the alert message, how to build a small server that turns alerts into orders through your broker's API, and the rules that apply in India since April 2026.

QuantPower Research · Updated 3 Nov 2026 · 7 min read

Key point
Webhooks need a paid TradingView plan and two-factor authentication. Your server must answer on port 80 or 443 within three seconds, and to trade in India it must send orders through your broker's API from a registered static IP.

How webhook automation works

  1. The alert fires. A price level, indicator condition or strategy order on your TradingView chart triggers an alert.
  2. TradingView sends a request. It posts your alert message to the webhook URL you set.
  3. Your server checks it. It confirms the request is genuine and the instruction is valid.
  4. Your server calls the broker. It places the order through your broker's API.
  5. The broker checks the order. Margin and risk checks run before the order reaches the exchange.
Flow from a TradingView alert through a webhook and your server to your broker's API and risk checks (illustration)

What TradingView requires

RequirementDetail
PlanA paid plan. The free Basic plan does not include webhooks
SecurityTwo-factor authentication turned on for your TradingView account
PortsPort 80 (HTTP) or 443 (HTTPS) only
NetworkIPv4 addresses only
Response timeYour server must reply within 3 seconds, or the request is cancelled
Sending IPs52.89.214.238, 34.212.75.30, 54.218.53.128 and 52.32.178.7
Message formatSent 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.

JSON
{
  "secret": "replace-with-a-long-random-string",
  "symbol": "NIFTY26OCTFUT",
  "action": "{{strategy.order.action}}",
  "price": "{{close}}",
  "sent": "{{timenow}}"
}

Useful placeholders:

PlaceholderValue
{{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.

Pine Script
//@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.

Python
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

  1. Use HTTPS so the message is encrypted in transit.
  2. Include a long random secret in the message and compare it in constant time, as the example does.
  3. Accept only the symbols and quantities you expect, and cap the quantity.
  4. Never put broker passwords, two-factor codes or access tokens in an alert message.
  5. Ignore repeated alerts, for example by recording the bar time and action of each order.
  6. 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

  1. Send a test alert to a request-inspection service and check that the JSON is valid.
  2. Point the alert at your server and log the request without placing an order.
  3. Place orders with the smallest quantity during market hours.
  4. Check that exits work as well as entries.
  5. Watch the first full day with your broker's app open.

Common problems

ProblemLikely causeFix
No request reaches the serverFree plan, or two-factor authentication is offUpgrade the plan and turn on two-factor authentication
The server receives text, not JSONThe message is not valid JSON, often because of smart quotes or a missing commaCheck the message in a JSON validator
Requests time outThe server takes longer than 3 secondsReply at once and place the order in the background
Orders rejected for IPThe server's IP is not registered with the brokerRegister the static IP
Orders stop after the first dayThe access token expiredLog in each trading day and update the token
Duplicate ordersThe alert fires more than once per barUse "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.

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
Trading involves substantial risk. The code here is for learning. Test it with small quantities before relying on it, and check your broker's and TradingView's current documentation.