Guide · Pine Script · Kite

Zerodha TradingView Pine Script: turning a strategy into Kite orders

A **Zerodha TradingView Pine Script** setup has three parts that people often blur together. Pine Script runs your rules on TradingView and fires an alert. A small app you control receives that alert. Then Zerodha's Kite Connect API places the order on your account. If you trade Indian markets from Dubai or Riyadh, each part has its own rules, and a missing one stops every order.

On this page
Zerodha TradingView Pine Script alert flow: a strategy fill on TradingView becomes a webhook, passes your app’s checks and reaches Kite Connect as an order
Each step runs on a different system, so each one can fail on its own.

Most traders who ask us about this already have a strategy that looks good on the chart. What they lack is the path from that chart to a real order at Zerodha.

Futures and options are leveraged and high risk, and you can lose more than you put in. Check with your broker which products your account may trade before you use real money.

What Pine Script does on TradingView

Pine Script is TradingView’s own language for indicators and strategies. A strategy script simulates orders on your chart through a broker emulator, and it has no access to your Zerodha account.

So the link between the two is an alert. TradingView’s help page says a strategy alert runs a copy of your strategy on its own servers, even with your browser closed. Each time the emulator fills one of the strategy’s orders, the alert fires.

The same page adds a few details. Orders on historical bars send nothing, and several alerts can fire inside one bar. Placeholders such as {{strategy.order.action}} and {{strategy.order.contracts}} fill in the side and size at that moment.

You can also attach your own text to each order. In Pine Script v6, the alert_message argument holds it, and the {{strategy.order.alert_message}} placeholder sends it out. Treat this as an untested sketch and match the fields to your receiving app:

//@version=6
strategy("EMA cross for Kite", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, alert_message = '{"action":"BUY","symbol":"RELIANCE","qty":10}')
if ta.crossunder(fast, slow)
    strategy.close("Long", alert_message = '{"action":"EXIT","symbol":"RELIANCE"}')

How the alert reaches your app

TradingView sends the alert as a webhook, which is an HTTP POST to a URL you type into the alert settings. Webhooks are a paid plan feature, as TradingView’s announcement says. Its help page adds the other rules you need:

  1. Webhook alerts work only with two factor login switched on.
  2. The URL must use port 80 or 443, and IPv6 is not supported.
  3. A valid JSON message goes out as application/json, while anything else is sent as plain text.
  4. TradingView cancels the request if your server takes longer than three seconds.

TradingView also publishes the four IP addresses that alerts come from, so your app can refuse posts from anywhere else. Put a long secret in the URL or the message too, because anyone who learns the URL could otherwise send fake orders.

The receiving app is the part you build or buy. It reads the message, checks it, applies your limits and calls Kite Connect. Our TradingView to MT5 webhook guide covers the same receiving side for MetaTrader.

What you need on the Zerodha side

Kite Connect is Zerodha’s trading API. You create an app in its developer console, which gives you an API key and a secret. Zerodha’s API page lists a free plan and a paid one, so check which features you need there before you pay.

The harder part is the login. The Kite Connect docs describe it in three steps.

Kite Connect daily login for a Zerodha TradingView Pine Script setup: API key login, request token, SHA-256 checksum, access token valid until 6 AM next day
This login has to happen once every trading day.

First you log in on Kite’s page with your API key, and Kite returns a request token that lasts only a few minutes. Your app then sends that token with a SHA-256 checksum of the key, the token and your secret. In return, it gets the access token used for every order.

That access token expires at 6 AM the next day, which the docs call a regulatory requirement. In Gulf time, that is 04:30 in the UAE and 03:30 in Saudi Arabia. A master logout from Kite Web also ends it early. As a result, your morning needs one Kite login before the 07:45 open in Dubai, or 06:45 in Riyadh.

The static IP rule in a Zerodha TradingView Pine Script setup

Zerodha’s support page says that from 1 April 2026 you need a static IP for API order placement. You may register up to two IPs, one primary and one optional backup, and exchange rules allow only one change per calendar week.

For Gulf traders, this rule causes more failed orders than anything else. Home and mobile lines often change their public address, and then Kite refuses orders from the new one. A small VPS with a fixed IP avoids that and keeps port 80 or 443 open.

Checklist for a Zerodha TradingView Pine Script setup: paid TradingView plan, two factor login, Kite Connect app, static IP, open port and a written broker reply
Tick every line before you send a real alert.

The last line matters for NRIs, because account rules differ between account types. Ask Zerodha in writing whether your account allows API orders and which segments it covers. Our guide to NRI trading in Indian stock market lists questions to send.

Timing limits between alert and order

A strategy alert fires when the emulator fills an order. Then the webhook, your app and Kite each add a little time, so on a fast candle your fill may differ from the chart price.

Zerodha TradingView Pine Script timing limits: 3 second webhook window, 15 alerts in 3 minutes, Kite token end and NSE open in Gulf time
Times shown in UAE and Saudi time.

Plan for these limits:

  • Your app must answer within three seconds, so it should accept the post first and place the order after.
  • A coding mistake can flood alerts, and TradingView stops any alert that triggers more than 15 times in 3 minutes.
  • Alerts expire on a set date, so note it in your calendar.

Also decide what happens to an alert that arrives while your app is offline. We suggest skipping a stale signal and checking the order book by hand.

Building it yourself or using a ready app

If you code, you can write the receiving app against the Kite Connect API yourself. Budget time for the parts beyond the order call, such as duplicate alerts, rejected orders, token expiry, a kill switch and readable logs.

If you would rather not, a ready Windows app is one option. Our TradingView to Zerodha automation app receives your alerts on your own PC or VPS and places them through Kite Connect or nine other Indian broker APIs. It covers NSE and BSE shares plus index and stock options, refuses futures alerts, and has a paper mode for a test day.

Either way, the Pine side has to send clean, consistent messages. If your strategy has no alert code yet, a Pine Script developer can add alert_message fields that match your app. After that, a Zerodha TradingView Pine Script setup needs one Kite login a day and a stable IP.

Sources

Frequently asked questions

Which IP addresses send TradingView webhooks?

TradingView's help page lists four: 52.89.214.238, 34.212.75.30, 54.218.53.128 and 52.32.178.7. Set your server or firewall to accept alert posts from these alone, and check the page now and then in case the list changes.

Do I need the paid Kite Connect plan for alert trading?

Zerodha's API page lists order placement and GTT under the free Personal plan. The Connect plan, shown at ₹500 a month, adds live WebSocket data and historical candles, which an alert-only app may not need. Plans change, so read the current page before you subscribe.

What happens to my alerts if I edit the strategy?

TradingView's help page says an existing alert keeps running the old version of your strategy. So after any change to inputs or code, delete the alert and create a new one, then send one test alert before the next session.

Can my family's accounts use the same static IP?

Zerodha's support page says family accounts can share one static IP through a single developer account. Each family member's client ID is added to the app. You may also register a second IP for a backup line.

Can I run this on an NRI account?

Your broker decides which products and API access your account allows. Ask Zerodha in writing before you connect any app, and keep the reply with your records.

WhatsApp · Email · Telegram

Tell us what you want to automate

Send your rules on WhatsApp. You get a clear quote, then a demo build to test before you pay in full.