TradingView to Dhan Copier: Simple DhanHQ Setup in 8 Steps

Pine strategies are good at knowing when to trade. Placing that trade in an Indian account is another matter. For TradingView to Dhan, TPcopier sells a Windows program, the Indian TvCopier. It takes each alert as it fires and sends the order to Dhan through DhanHQ v2, Dhan's trading API.

The program runs on your PC or VPS rather than on our servers. Since 1 April 2026, SEBI's framework for retail algo trading lets a broker accept an API order only from a static IP registered to that client. So the order has to leave a machine you control. The TradingView automation page for Indian brokers shows how the alert reaches that machine.

Dhan is one of the simpler brokers to connect. You paste two values, and you replace the token when it expires. The parts that need care are Dhan-specific, and this page covers each one. Dhan's market orders carry no protection band, oversize orders need splitting, and its error codes mean nothing until someone translates them.

What TradingView to Dhan needs, at a glance

What the software asks for Where it comes from How long it lasts
Access token DhanHQ dashboard: Profile > DhanHQ Trading API Until the expiry Dhan gave it
Client id Your Dhan client number, shown beside your name It does not change
Static IP The IP your Dhan API access is registered to As long as your connection keeps it

For the Dhan side, such as token lifetime, check Dhan's own DhanHQ v2 documentation. The software needs both the token and the client id. If either is missing, the Accounts page shows "keys missing" and the software skips that account when alerts arrive.

Where the alert goes on its way to Dhan

TradingView sends the alert straight to the software, with nothing in between. The software takes it on port 80, because TradingView only sends webhooks to port 80 or 443, and places the order with Dhan itself. The dashboard stays private on your PC, and the order leaves from the static IP Dhan knows. If TradingView cannot reach your computer, nothing arrives, as step 6 explains.

You control the address from the software's TradingView page. The Webhook URL there looks like http://<your public IP>/tv/<a long secret token>, with Copy and Regenerate buttons. Only TradingView's own servers can place an order through it. An order from any other address is refused, and the journal says where it came from. Still, treat the URL as a password. Regenerate gives you a fresh one and kills the old one at once, so paste the new one into your TradingView alerts afterwards. One URL serves every strategy, and the source field keeps them apart on the Sources page.

Set up TradingView to Dhan in 8 steps

  1. Take the demo. On tpcopier.com, the Indian copier page has a Get the free demo button. After sign-up, the Indian TvCopier card in your account gives you the key and the Windows download.

  2. Install it on the static-IP machine and activate it with the key. The program asks for nothing else on its first screen.

  3. Register the IP with Dhan. Copy the address from the Static IP band at the top of the Dashboard into your Dhan API set-up.

TradingView to Dhan: the program's Dashboard with the Static IP band Dhan must have on file The Dashboard; the Static IP band is the address Dhan sees (example).

  1. Add Dhan. Go to Accounts > + Connect a broker > Dhan (DhanHQ) and paste the access token and client id. Press Save this account, then Test the connection. Dhan answers "connected" with your available funds in rupees, which proves both values are right.

Dhan (DhanHQ) account form with access token and client id in the Indian TvCopier A new Dhan account: two boxes, and the hints say where each comes from (example).

  1. Open port 80. On the program's TradingView page, press Allow port 80 in Windows Firewall, and Allow access if Windows asks about the network. At home, forward port 80 on your router to this computer. On a VPS, open it in the provider's firewall too.

  2. Read the checks. The same page shows whether the software is listening on port 80, whether the firewall rule is there, and your public address. They run on your PC only. On a home Jio or Airtel line TradingView usually cannot reach the PC at all, because the address is shared, so use a Windows VPS with a static IP. Then copy the address under 1 The webhook URL.

  3. Create the TradingView alert. Put the URL under Notifications > Webhook URL, following TradingView's webhook guide. For the Message, copy the Pine strategy sample from 2 The message on the program's TradingView page and change the contract. The message has to be JSON, because the program refuses plain text.

Ready alert messages in the program, including a Pine strategy body for TradingView to Dhan Ready message bodies with Copy buttons; the last one is for a Pine strategy.

  1. Check the Sources page after the first alert. Each new source name adds a row there, switched on. Open the row to set its size or tick Trade it on for the Dhan account alone.

Sources page of the program with example strategies and their switches One row per strategy name, each with its own switch, size and accounts (example).

Alerts from a Pine strategy

Here is an example, not a recommendation. A strategy on NIFTY trades the 24500 put, and TradingView fills in the direction and size.

{"action": "{{strategy.order.action}}", "symbol": "NIFTY", "strike": 24500, "option_type": "PE", "lots": {{strategy.order.contracts}}, "source": "nifty-fade"}

Two words behave differently here than in Pine. SELL is an order to sell, and the software places it as a trade of its own. On a contract you do not hold, it opens a short. With Let SELL open a short switched off on the account, the software refuses it instead.

EXIT is the close. It reads what Dhan says you hold in that contract and cancels any entry still working on it. Then it closes exactly that, never the size the entry asked for. So if your strategy's closing fill would arrive as "sell", send the close as its own alert:

{"action": "EXIT", "symbol": "NIFTY", "strike": 24500, "option_type": "PE", "source": "nifty-fade"}

Sometimes TradingView sends a placeholder unfilled, because it was misspelt or because this alert type has no such value. In that case the software refuses the alert with a sentence naming it, and nothing reaches Dhan.

What the order looks like at Dhan

Dhan's API does not accept trading symbols. Instead, every order names a numeric securityId plus a segment such as NSE_FNO, NSE_EQ, BSE_FNO or MCX_COMM. Both come from Dhan's scrip master, a CSV the software downloads and reads by column name. If Dhan ever renames a column the software needs, it stops with "the Dhan scrip master has no ... column - its format has changed". That beats guessing at a different instrument.

Product Intraday goes as INTRADAY. Delivery / carry goes as CNC on shares and as MARGIN on options, currency and MCX, because CNC is a cash-market product only. The order types are LIMIT, MARKET, STOP_LOSS and STOP_LOSS_MARKET, and validity is DAY or IOC. For an AMO, the software sets Dhan's after-market flag and times it for the open.

Dhan sometimes answers a rejected order with a normal-looking reply and an order id. So the software also reads the order status. It logs a REJECTED, CANCELLED or EXPIRED order as "Dhan refused the order", never as placed. That way a refused stop never counts as protection.

Dhan has no protection band, so keep the limit switch on

Some brokers take a protection band with a market order. Dhan's order has no such field, so a market order here is a plain one. What keeps you inside the April 2026 rules is the account switch Convert market signals into protective limits. It is on from the start, and it turns an alert without a price into a LIMIT 0.5% through the last traded price.

There is one honest gap in TradingView to Dhan. If the software cannot read Dhan's last price as it builds the order, it falls back to a market order rather than drop the trade. Put a price in the alert if you never want that. Then the order is a LIMIT at your number. Also, Refuse if the price has moved more than can turn the entry away when the market has already run from it.

Freeze quantity: split only after Dhan says so

The exchange refuses a single F&O order above its freeze quantity. The software first sends every order to Dhan's normal endpoint. Only when Dhan refuses it for the freeze does the software resend it through the endpoint Dhan publishes for splitting. The log then adds "over the exchange freeze quantity, so Dhan split it".

A timeout is different, and the software never resends after one. By then the first order may already be at the exchange, and a second one would be a position nobody asked for.

Dhan's DH codes in plain words

Code What it means What to do
DH-901 Token invalid or expired Generate a new one and paste it on Accounts
DH-902 Token not allowed to do that Check API access and the segments enabled at Dhan
DH-903 Account blocked or not activated for trading Take it up with Dhan
DH-904 Rate limit Nothing; it clears by itself in a second
DH-905 Values in the request refused Check the alert's price and size
DH-906 Order refused: margin, price band, or not tradable now Check funds and the contract
DH-907 No market data for this instrument Retry later, or put a price in the alert
DH-908 Dhan internal error Nothing was wrong with the request
DH-909 Dhan could not be reached Check the connection

In the Signal Feed, the software adds these meanings next to Dhan's own message.

FAQ

What do I paste into the software for TradingView to Dhan?

Your DhanHQ access token and your Dhan client id, both from the DhanHQ dashboard. Then press Test the connection. A working pair shows your available funds.

Do I need a new Dhan token every day?

Only when yours expires. The software tells you when: "Dhan refused the access token - it has expired or belongs to a different client id", or DH-901 on an order. Dhan's own API documentation is the place to check how long a token can last.

Can Dhan receive market orders from TradingView alerts?

Yes, if you switch off protective limits on that account. But Dhan's market order carries no protection band. So keep the switch on, or put a price in the alert.

What happens if my alert is bigger than the freeze quantity?

Dhan refuses the plain order, and the software resends it once through Dhan's splitting endpoint. The pieces add up to exactly what you asked for.

Can I trade Dhan and Zerodha from the same alert?

Yes. Every account that is switched on receives the alert with its own size and rules. TradingView to Zerodha covers the Zerodha side.

Run a week on one Dhan account

Start with the free demo and a single Dhan account set to one lot. Then read every line in the Signal Feed for the first few sessions. The demo key becomes your lifetime key when you buy. There are no refunds, though, so test first.

Create a TPcopier account and see pricing. If your signals come from a channel, see Telegram to Dhan. For other brokers, read TradingView to Fyers and the Indian brokers overview. The Indian TvCopier setup guide covers the program screen by screen.

Risk warning: trading options and shares carries a high risk of losing money and is not suitable for everyone. Nothing here is investment advice.