Automation April 2026 · 14 min read

Dhan TradingView Webhook Setup: Step-by-Step Guide (2026)

Automate your options trading directly from TradingView to Dhan using free webhooks. This guide walks through every step — from webhook generation and JSON configuration to Pine Script integration and live execution.

Bhavin Javia

Bhavin Javia

Founder, BotJockie · 22+ yrs software · 5+ yrs algo dev

Dhan TradingView Webhook Tutorial — click to play

Manual options trading on TradingView is painful. You spot a high-probability setup, it unfolds perfectly on your chart, but by the time you've switched to Dhan and placed the order manually, the entry is 5% gone. Or you're glued to the screen at 9:15 AM instead of doing literally anything else with your morning.

Dhan's free TradingView webhook integration solves this. Your strategy triggers a TradingView alert → the alert automatically sends order details to Dhan → your position is live in seconds. No manual entry, no missed fills, no emotion. This tutorial covers the complete setup — webhook URL, JSON schema, TradingView alert configuration, and Pine Script integration — specifically for options trading on NSE.

If you prefer watching over reading, the video above walks through the same process live. Otherwise, keep scrolling.

1Access the Dhan Webhooks panel

Log into your Dhan trading account at web.dhan.co.

  1. Click the Orders tab in the top navigation.
  2. Look for the Webhooks sub-tab — it sits alongside Today, Super, Flash, Baskets, Forever, and SIPs.
  3. You'll see a section labeled "TradingView" with the description "Execute trades directly on TradingView.com using Free Webhooks by Dhan". This is your control panel.
  4. Click Manage to open the full configuration view.
Dhan Orders page with Webhooks tab active, showing the TradingView integration card
Figure 1: Dhan Webhooks panel under Orders. The status indicator shows whether your webhook is currently active.

2Generate your webhook URL

Inside the Manage view, you'll find a section titled "Your Webhook URL for TradingView".

⚠️ Important Each webhook URL is bound to a unique secret token. When you generate a new URL, the old one expires immediately and all alerts pointing to it will stop firing. Always update your TradingView alerts with the new JSON when you regenerate.
  1. Click the green Generate New button.
  2. Confirm the warning prompt: "Generating new URL will disable all existing alerts. Continue?"
  3. Dhan creates a unique HTTPS endpoint, typically formatted as:
    https://tv-webhook.dhan.co/tv/alert/{hash}/{token}
  4. Click Copy URL to copy it to your clipboard.
  5. Set Token Validity from the dropdown on the right. 30 days is the default and works for most setups — you can regenerate when it expires.
Dhan webhook URL display showing the generated HTTPS endpoint with a 30-day token validity dropdown
Figure 2: Your generated webhook URL. Token validity is configurable — 30 days is the default.
Good to know The Dhan TradingView webhook is free — there's no subscription cost. You only need an active Dhan trading account. On the TradingView side, webhooks require at least the Essential plan (formerly Pro).

3Configure order details in Dhan

Scroll down to "Enter Order Details for Execution". You'll see tabs for Options Trading, Futures, Equity, Commodity, Multi Segment, and Basket. For this guide, we're focused on the default Options Trading tab.

Add your option scrip

Click + Add Scrip in the top-right of the order table. Fill in the row:

⚠️ Lot size matters Dhan accepts quantity in lots, not contracts. Entering "1" means 1 lot — which is 65 contracts for NIFTY (revised by SEBI from 75 earlier), with similar lot sizes for BANKNIFTY, FINNIFTY, and other F&O instruments. Always verify the current lot size on the NSE/Dhan before trading, as SEBI revises them periodically. If you enter "65" expecting a single lot, you'll end up with 65 lots — a costly mistake. Always start with 1 lot for testing.
Dhan order configuration table with NIFTY 28 Apr 24150 CE, Intraday product, 1 lot, Market order
Figure 3: Order Details table configured for a NIFTY 24150 CE Intraday buy at Market price for 1 lot. You can add multiple rows for multi-leg setups.

Multi-leg orders

For strategies that trade multiple strikes simultaneously (iron condors, straddles, strangles, hedged positions), click + Add Scrip again to add additional rows. Each row becomes a separate leg in the generated JSON. For example:

This creates a bull call spread in a single webhook trigger.

4Generate the webhook JSON

Once your order row(s) are configured, click the green Generate JSON button at the bottom-right of the table. A JSON Output for Execution panel appears below with the full payload. For the NIFTY 24150 CE example above, the JSON looks like this:

{
  "secret": "DcWgD",
  "alertType": "multi_leg_order",
  "order_legs": [
    {
      "transactionType": "B",
      "orderType": "MKT",
      "quantity": "1",
      "exchange": "NSE",
      "symbol": "NIFTY",
      "instrument": "OPT",
      "productType": "I",
      "sort_order": "1",
      "price": "0",
      "option_type": "CE",
      "strike_price": "24150.0",
      "expiry_date": "2026-04-28"
    }
  ]
}

Each field in the options JSON:

Dhan JSON Output panel showing the complete multi_leg_order JSON with all options fields, Copy JSON Object button below
Figure 4: JSON output for a NIFTY options buy. Click Copy JSON Object to copy the entire payload.
⚠️ Critical Copy the entire JSON block including every brace, bracket, quote, and comma. Even a single missing character will cause the alert to fail silently — Dhan simply won't execute the order, and TradingView won't warn you.

5Create the TradingView alert

Open your TradingView chart for the instrument your strategy trades (e.g., NIFTY 5-minute chart). Apply your indicator or Pine Script strategy first — the alert will be created on top of that.

Open the alert dialog

  1. Click the Alert (bell with +) icon in the right-hand toolbar, or press Alt+A (Windows) / ⌥A (Mac).
  2. In the Condition dropdown, select your indicator or strategy.
  3. Set the specific condition (crossover, strategy alert, etc.) that should trigger the order.
  4. Give the alert a clear name — e.g., "NIFTY 24150 CE Buy".

Paste the webhook URL

In the Notifications tab of the alert dialog:

  1. Tick Webhook URL.
  2. Paste your Dhan webhook URL from Step 2 into the field.

Paste the JSON as the alert message

Back in the Settings or Message section of the alert:

  1. Clear the Message text box completely.
  2. Paste the JSON you copied from Dhan in Step 4.
  3. The message field must contain only the JSON — no comments, no extra text. TradingView sends this exact string as the HTTP POST body.

Click Create to save the alert. It will now fire whenever your condition is met and send the order to Dhan for execution.

6Dynamic alerts: equity/futures vs options

The JSON from Dhan is static — it executes the same order every time the alert fires. For strategies that need dynamic behaviour (different sides, different quantities, different strikes), you'll need to build custom JSON templates using TradingView's alert placeholder syntax. How complex that gets depends entirely on what you're trading.

Equity and futures: simple two-template setup

For equity (instrument: EQ) and futures (instrument: FUT), dynamic automation is straightforward. The same symbol handles both sides of the trade — you go long or short on the same contract. A single template with {{strategy.order.alert_message}} swapping between "B" and "S" is enough.

Custom JSON template for equity/futures:

{
  "secret": "DcWgD",
  "alertType": "multi_leg_order",
  "order_legs": [
    {
      "transactionType": "{{strategy.order.alert_message}}",
      "orderType": "MKT",
      "quantity": "{{strategy.order.contracts}}",
      "exchange": "NSE",
      "symbol": "RELIANCE",
      "instrument": "EQ",
      "productType": "I",
      "sort_order": "1",
      "price": "0"
    }
  ]
}

Matching Pine Script:

//@version=6
strategy("Equity Auto", overlay=true)

fastMA = ta.sma(close, 9)
slowMA = ta.sma(close, 21)

if ta.crossover(fastMA, slowMA)
    strategy.entry("Long", strategy.long, alert_message="B")

if ta.crossunder(fastMA, slowMA)
    strategy.entry("Short", strategy.short, alert_message="S")

When crossover fires, {{strategy.order.alert_message}} resolves to "B", Dhan receives a buy order on RELIANCE. On crossunder, it resolves to "S" — same contract, opposite direction. One alert, one JSON template, and you're done.

Template substitution happens before the POST TradingView resolves template variables before sending the HTTP request to Dhan. So by the time Dhan receives the JSON, it's already a valid static payload with real values — Dhan itself doesn't parse TradingView syntax.

Options: four separate templates required

Options automation is fundamentally different. You can't just flip "B" to "S" on the same contract, because going "long" and "short" in an options strategy typically means trading different instruments — a call for bullish signals, a put for bearish signals. And closing each position requires a separate exit order on that specific contract.

That means a complete options strategy needs four distinct alert JSON templates:

Each template needs its own set of resolved values: the correct strike, the correct expiry, the correct option type (CE vs PE), and the correct side (B for entry, S for exit). TradingView's built-in variables alone can't carry all this information — you need to expose your own custom placeholders from Pine Script, for symbol, quantity, strike, expiry, option type, and the "opposite option type" needed for hedges or straddles.

Pine Script strategy input dialog showing separate JSON alert templates for Long Entry and Short Entry with custom placeholders for api_secret, quantity, exchange, symbol, option, strike, expiry, and opposite_option
Figure 5: Long Entry and Short Entry alert templates from a production Pine Script strategy. Each uses custom placeholders like {{api_secret}}, {{symbol}}, {{strike}}, {{expiry}}, {{option}}, and {{opposite_option}} — all computed inside Pine Script and injected at alert-fire time.
Pine Script strategy input dialog showing Long Exit and Short Exit JSON alert templates with transactionType set to S for closing positions
Figure 6: Matching Long Exit and Short Exit templates. Notice transactionType is "S" (sell to close) and the Short Exit uses {{opposite_option}} to close the put that was opened on Short Entry.

Beyond the four templates, your Pine Script also needs to:

This is where most DIY automation attempts stall. The JSON schema is straightforward; the Pine Script architecture to populate it reliably is not.

Options automation

Let us build your options auto-trading system

We've built this exact four-template architecture for dozens of options strategies — with dynamic strike selection, expiry resolution, position tracking, and built-in failsafes. You bring the strategy logic; we handle the automation plumbing. Works with Dhan and every major Indian broker.

Book Free Strategy Call →

7Test before going live

⚠️ Paper trade first Always test your webhook during market hours with the smallest possible quantity (1 lot) before committing real capital. The fastest way to burn money is a misconfigured webhook that fires 50 lots when you meant 1.

End-to-end test procedure:

  1. Set up the alert with your webhook URL and JSON.
  2. Use a condition that will fire soon — e.g., price crossing a line one tick away from current price. This lets you verify execution without waiting for a real setup.
  3. Watch your Dhan Orders tab. A new order should appear within 1–3 seconds of the alert firing.
  4. Confirm the order details match your JSON exactly — same symbol, strike, expiry, side, and quantity.
  5. If execution is correct, delete the test alert and configure your real strategy alert.

Troubleshooting

If the alert fires on TradingView (check the alert log via the bell icon) but no order appears in Dhan, check in this order:

Done for you

Want this built for you?

Book a free 20-minute strategy call. We'll design a custom Pine Script strategy tailored to your trading style, connect it to Dhan with full automation, and walk you through testing end-to-end.

Book Free Strategy Call →

Wrap-up

Dhan's free TradingView webhook is one of the cleanest broker integrations available to Indian retail traders. No intermediary service, no monthly subscription, no custom server — just a URL, a JSON, and an alert. For static orders or simple equity/futures automation, setup takes under 10 minutes and a single JSON template. For options, the automation layer grows into a proper four-template architecture with dynamic strike selection, expiry resolution, and position tracking — which is exactly the kind of custom build we do day in and day out.

The principles are the same whether you're automating one NIFTY call or a full iron condor. Get the JSON schema right, match the secret, test with small size, and scale up only after you've confirmed three or four live executions match your expectations.

Free download

Get the free Algo Toolkit

25-point backtest validation checklist, Pine Script v6 risk management framework, and 3 strategy templates. Everything you need to deploy robust automated strategies. No card required.

Get Free Toolkit →