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

K thanks @Hardik. Appreciate the response.

@Hardik Bank nifty fired correctly…Nifty didn’t. This is not just me. But same for a bunch of fellow traders. There is still problem at Dhan end. Please fix.

Hello @t7support

Got it. Yes, there was a key which was not getting updated at our end, hence the issue. We are deploying the fix today post market, so this will be resolved.

Banknifty, Finnifty all firing. Only Nifty is the problem… :grimacing:


This is the screenshot showing that I have placed my webhook url.

My webhook url is https://tv-webhook.dhan.co/tv/alert/b51ffb011f9b41bd8f056fb9e3dfc9c0/LREO88329A


Please refer this image also. Today also, the alerts didnt get triggered on Dhan. Please let me know what could be the problem

Hello @pyrasp

Can you also paste the JSON message from any of the triggered alert, so as to check the JSON structure.

Hi Hardik attaching the screenshot of the same. The alerts are going in trading view but money is not getting deducted in dhan

Today I activated smart transfer in my bank account too. Will that help?

Hello @pyrasp

Got this. We were facing issues with orders in NIFTY today. This will be resolved tomorrow. Let us know in case you still face issue there.

No. There is no relation to this and webhook orders. As long as there are funds in your account, orders will get placed from any platform.

May I please know what was changed at your end to cause this issue ? It was firing alright few days ago. Suddenly stopped working. These kind of issues catches us off guard.

@Hardik Nifty fired today. Thanks :pray:

Hi,
Is there a way to connect the json string generated by the strategy I am using with the json string generated on Dhan.

Hello @pyrasp

Not exactly. You can customise your own strategy generated alert JSON to match that of Dhan JSON, so that your orders are placed, via PineScript.

Dear All,

Not sure if this helps. I have created a simple indicator which has ability to trade auto strike price via dhan webhook. you can customize and design it further to suite your trading style.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradeWiseWithEase
// ProfileInfo := https://in.tradingview.com/u/TradeWiseWithEase/#published-scripts

//@version=5
indicator(title = "Dummy AutoStrike Indicator", shorttitle = "BE-Dummy", overlay = true)
import TradeWiseWithEase/BE_CustomFx_Library/113 as BEL
type ProfileInfo
    string SymbolInfo
    int    SymbolLot
    int    SymbolStrike
    string SymbolExc

var ProfileInfo BNFProfile  = ProfileInfo.new("BANKNIFTY", 1, 100, "NSE")
var ProfileInfo N50Profile  = ProfileInfo.new("NIFTY", 1, 50, "NSE")
var ProfileInfo FINProfile  = ProfileInfo.new("FINNIFTY", 1, 50, "NSE")
var ProfileInfo SNXProfile  = ProfileInfo.new("SENSEX", 1, 100, "BSE")
var ProfileInfo MIDProfile  = ProfileInfo.new("MIDCPNIFTY", 1, 25, "NSE")
var ProfileInfoArray        = array.new<ProfileInfo>()
if barstate.isfirst
    ProfileInfoArray.push(BNFProfile)
    ProfileInfoArray.push(N50Profile)
    ProfileInfoArray.push(FINProfile)
    ProfileInfoArray.push(SNXProfile)
    ProfileInfoArray.push(MIDProfile)

var string Key              = input.string(
 defval                     = "Api Key Input",
 title                      = "Dhan API Key")

var string LoadProfile      = input.string(
 defval                     = "BANKNIFTY",
 options                    = ['BANKNIFTY', 'NIFTY', 'FINNIFTY', 'SENSEX', 'MIDCPNIFTY'], 
 title                      = "Load Profile")

var GetUserProfile          = ProfileInfo.new()             
if barstate.isfirst
    for [index, echProfile] in ProfileInfoArray
        if echProfile.SymbolInfo == LoadProfile
            GetUserProfile  := echProfile

var int StrikeInt           = GetUserProfile.SymbolStrike

var int   Qty               = input.int(
 defval                     = 1,
 title                      = "Lots",
 minval                     = 1)

var string SymbolName       = LoadProfile

var string CWE              = input.string(
 defval                     = "2023-10-04",
 tooltip                    = "Format may be different from the default values. Plz check Orders ==> Webhooks Tab of Dhan HQ Website",
 title                      = "Current Week Expiry")

var string SymCWE           = SymbolName + "_" + CWE

var string BrokerName       = "DHANHQ"

var string Exc              = GetUserProfile.SymbolExc

var string ProdType         = input.string(
 defval                     = "CNC",
 options                    = ['INTRADAY', "CNC"], 
 title                      = "Product Type")

var string GroupString      = "SL & TGT"

var float  UserSL           = input.float(
 defval                     = 1,
 minval                     = 0,
 inline                     = "UserINPUT",
 group                      = GroupString,
 title                      = 'SL')

var float  UserTGT          = input.float(
 defval                     = 1,
 minval                     = 0, 
 inline                     = "UserINPUT",
 group                      = GroupString, 
 tooltip                    = "Set SL & TGT IN Absolute Points like Bracket Order\n\nNote: If Entry Price is 100 and SL is set to 10 then Stop Loss shall be trigerred when LTP crosses 90. Similarly for TGT, If Entry Price is 100 and TGT is set to 10 then Target Alert shall be trigerred when LTP crosses 110.",
 title                      = 'TGT')

LTP                         = close
varip ExitAlertArray        = array.new_string(0)
varip EntryAlertArray       = array.new_string(0)
varip EntrySymbols          = array.new_string(0)
varip int Direction         = 0
varip float SLPrice         = 0
varip float TGTPrice        = 0


if barstate.isnew and barstate.isrealtime and Direction == 0
    Direction               := 1
    [Leg1Value, Leg1Sym, Leg1Alert] = BEL.NLB_Cal_TradingAlert(BrokerName, true, "ATM", 0, StrikeInt, true, "c", LTP, 0.0, BrokerName, Exc, SymCWE, 0, "SELL", str.tostring(Qty), "M")
    [Leg2Value, Leg2Sym, Leg2Alert] = BEL.NLB_Cal_TradingAlert(BrokerName, true, "OTM", 1, StrikeInt, true, "c", LTP, 0.0, BrokerName, Exc, SymCWE, 0, "BUY", str.tostring(Qty * 2), "M")
    EntrySymbols            := array.from(Leg1Sym, Leg2Sym)
    EntryAlertArray         := array.from(Leg1Alert, Leg2Alert)
    SLPrice                 := UserSL == 0 ? na : LTP - UserSL
    TGTPrice                := TGTPrice == 0 ? na : LTP + TGTPrice
    alert(BEL.ArrayCombiner(EntryAlertArray,BrokerName, Key), alert.freq_once_per_bar)

SLCross                     = ta.crossunder(LTP, SLPrice) and Direction == 1 and not na(SLPrice)
TGTCross                    = ta.crossover(LTP, TGTPrice) and Direction == 1 and not na(TGTPrice)

if Direction== 1 and (SLCross or TGTCross)
    [Leg1Value, Leg1Sym, Leg1Alert] = BEL.NLB_Cal_TradingAlert(BrokerName, false, "", 0, StrikeInt, true, "c", LTP, 0.0, BrokerName, Exc, EntrySymbols.get(0), 0, "BUY", str.tostring(Qty), "M")
    [Leg2Value, Leg2Sym, Leg2Alert] = BEL.NLB_Cal_TradingAlert(BrokerName, false, "", 0, StrikeInt, true, "c", LTP, 0.0, BrokerName, Exc, EntrySymbols.get(1), 0, "SELL", str.tostring(Qty * 2), "M")
    ExitAlertArray          := array.from(Leg1Alert, Leg2Alert)
    alert(BEL.ArrayCombiner(ExitAlertArray,BrokerName, Key), alert.freq_once_per_bar)

Main to understand is with

BEL.NLB_Cal_TradingAlert formula

here is the breakdown on how to set things up.

  1. Bot Type := DHANHQ
  2. To Calculate Option Strike := if set to true then Strike price shall be calculated basis further inputs, else set this parameter to false
  3. What type of Option you need := you can specify either ATM, ITM, OTM. if you have set the 2nd parameter to false you may use “”
  4. How much Deep strike := you need to specify the number of Deep strike for instance if you need 2 ITM then type 2. if you have set the 2nd parameter to false you may use 0
  5. StrikeGap := for BNF its 100 and Nifty 50 etc
  6. Is this leg for Calls or Puts := if set to true it calculates strike for Calls else it will treat for Puts
  7. “C” - Keep the default as “C”
  8. what is the current LTP := you may use close key word of pinescript.
  9. Keep the default of 0.0
  10. keep the default of “DHAN”
  11. Specify the Exchange like “NSE”, “BSE”
  12. Specify the Symbol name along with Expiry in the format

SYMBOL NAME _ EXPIRY DATE
for example
BANKNIFTY_2023-10-04

  1. Keep it default 0
  2. Specify the direction of trade like “BUY” or “SELL”
  3. Mention the Qty in Lots := str.tostring(1)
  4. M refers to Market order else you may use L for limit order

Happy to answer any question if you have.

3 Likes

Thanks for sharing this @Shylaja

  1. Could you please explain how pinescript works if no change is made to it and deployed in the market?
    Note: I will update the API details.

  2. You have mentioned that we can use it to trade via webhooks. Could you explain how to link to webhook?

Note: Currently I use webhook feature in the tradingview buy and sell options via basket trigger. The tradingview indicator I use is the ORB for the first 5 minutes

Is it easy to integrate your pinescript with the ORB indicator?

Hey Dear,

As Name suggests it’s a dummy indicator. It’s basically scripted to understand how one can develop/deploy dynamic option trading via Dhan webhook.

Hence I suggest you to understand how pine script work.

Script is basically a long directional trade. Plz try paper trade with it.

For integration of Dhan webhook plz refer below video from Dhan

If you still have a question plz ping me on telegram @Pavan_BreathEasy

1 Like

With due respect to all those SuperTraders who has asked me on to use this dummy code and requested many other features like Trail SL for options, Individual legs, over all strategy.

I have build this indicator.

plz do use this and let me if you still need any other features.

@Hardik @Dhan_Cares nifty oder didn’t fire today. Please check.

Hi Shylaja ,
i tried using the ExitAlertArray with the alert_message in strategy.exit .
Getting the below error.
Variable ‘ExitAlertArray’ was declared with ‘string’ type. Cannot assign it expression of type ‘simple string’ .
Can you help me solve this error ?

thanks :slightly_smiling_face: