Introducing: Webhooks as Order Type on Dhan. Now do Options Trading on TradingView.com

Hi Hardik,
I do trading via Pinescript strategy. Is there any way to place orders directly from the tradingview script on Dhan.

Hello @pyrasp

Yes, for sure. You can use webhooks for this particular purpose, wherein your Pinescript code generates alerts which in turn place orders via webhooks.

You can refer to this document that we made for users to get started: Dhan Webhooks

I have done it as per the webhooks document ,but still my orders are not getting recorded.

@pyrasp

Alright. What method are you using to generate alert via pinescript? Will it be possible to share a snippet of the same?

//@version=5

strategy(“Bollinger Bands Strategy”, overlay=true)

source = close

length = input.int(20, minval=1)

mult = input.float(2.0, minval=0.001, maxval=50)

basis = ta.sma(source, length)

dev = mult * ta.stdev(source, length)

upper = basis + dev

lower = basis - dev

buyEntry = ta.crossover(source, lower)

sellEntry = ta.crossunder(source, upper)

if (ta.crossover(source, lower))

strategy.entry(“BBandLE”, strategy.long, stop=lower, oca_name=“BollingerBands”, oca_type=strategy.oca.cancel, comment=“BBandLE”, alert_message=‘{“secret”:“VLOjz”,“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”:“19900.0”,“expiry_date”:“2023-09-21”}]}’)

else

strategy.cancel(id=“BBandLE”)

if (ta.crossunder(source, upper))

strategy.entry(“BBandSE”, strategy.short, stop=upper, oca_name=“BollingerBands”, oca_type=strategy.oca.cancel, comment=“BBandSE”, alert_message=‘{“secret”:“VLOjz”,“alertType”:“multi_leg_order”,“order_legs”:[{“transactionType”:“S”,“orderType”:“MKT”,“quantity”:“1”,“exchange”:“NSE”,“symbol”:“NIFTY1!”,“instrument”:“FUT”,“productType”:“I”,“sort_order”:“1”,“price”:“0”}]}’)

else

strategy.cancel(id=“BBandSE”)

//plot(strategy.equity, title=“equity”, color=color.red, linewidth=2, style=plot.style_areabr)

This is the code I am using.

Hello @pyrasp

The code looks good, can you confirm if the alerts are getting triggered in TradingView atleast? If yes, you should be able to find them under alerts section of TradingView as ‘triggered’.

Hello Hardik
Yes the alerts are getting triggered in trading view.

But the transaction is not taking place in my dhan account

Webhook url correctly set in alert window ?

Also can you please share your triggered alert log snapshot ?

@Hardik @Dhan_Cares

Today TV alerts fired as usual for me. But orders didn’t get executed on Dhan. Same for all my fellow traders. Please check.

@t7support

Can you tell me the segment you were placing order for?

We tried to fire orders for Nifty and Bank Nifty options. It didn’t fire any orders in Dhan even though TV generated alerts correctly with the correct order string.

Alright @t7support

The team is looking into this and I will update you shortly here.

Little ago my Bank nifty put exit signal came but it didn’t fire order in Dhan. I manually then closed it. Soon after that Bank Nifty call order fired correctly around 11 AM.

Looking forward to the update on what happened at the backend.

Nifty order didn’t got through now even though alert was generated. @Hardik pls let us know what is happening ?

Note that I haven’t changed any alert settings. These were firing well till yesterday.

Hello @t7support

We are debugging this at our end, to find the exact issue due to which orders are not getting punched in via Webhooks. I will update you as soon as we have the root cause.

Thanks @Hardik. Issue fixed ? Will orders fire correctly from Monday via webhook ?

@Hardik @PravinJ @Alok_Pandey @Dhan

Can you please update on whether the issue is fixed ?

Hello @t7support

Yes, we have deployed some fix. Although, do keep a check on your order status and let us know in case orders are not getting placed on Dhan.