Stop loss order is not placing through pine script webhook to Dhan though Buy and target are placed

I am trying to use webhook to place the buy, target and sl order to the Dhan using webhook. I tried below

{

“secret”: “45R4l”,

“alertType”: “multi_leg_order”,

“order_legs”: [

{

“transactionType”: “B”,

“orderType”: “LMT”,

“quantity”: “1”,

“exchange”: “MCX”,

“symbol”: “GOLDTEN1!”,

“instrument”: “FUT”,

“productType”: “M”,

“sort_order”: “1”,

“price”: “153800”

},

{

“transactionType”: “S”,

“orderType”: “LMT”,

“quantity”: “1”,

“exchange”: “MCX”,

“symbol”: “GOLDTEN1!”,

“instrument”: “FUT”,

“productType”: “M”,

“sort_order”: “2”,

“price”: “154200”

},

{

“transactionType”: “S”,

“orderType”: “SL”,

“quantity”: “1”,

“exchange”: “MCX”,

“symbol”: “GOLDTEN1!”,

“instrument”: “FUT”,

“productType”: “M”,

“sort_order”: “3”,

“price”: “0”,

“triggerPrice”: “153500”

}

]

}

Also tried the SL-M order also .

Hi @Shailendra_Maheshwar

There’s no SL enum for the orderType field.

Webhook orders are trigger-based, once the trigger condition is met, the order goes to the exchange as either a Limit or Market order. The stop-loss behaviour comes from the trigger itself, not from the order type.

What you’re describing is closer to a Super Order. That’s precisely why we built Super Order: webhook orders have no OCO logic, so trying to replicate it here won’t give you the result you’re expecting.

Hope this helps!

@Shailendra_Maheshwar

SL order’s in webhook are just an exit order , nest a condition in your pinescript code only.

Example:
SL = ta.crossunder(close, low[1])

long_entry = ta.crossover(close, close[1])

long_exit = ta.crossover(close, high[1]) or SL

Hi @Shailendra_Maheshwar ,

Please note that the Dhan Webhook JSON supports only Limit (LMT) and Market (MKT) as the orderType. Therefore, using SL or SL-M as the orderType in the webhook JSON will not work.

For setting up an automated Target and Stop Loss through TradingView Webhooks, the conditions need to be defined within your Pine Script.

For example, after a Buy Entry order is triggered, you can define separate Target and Stop Loss conditions in your Pine Script. When either condition is met, the corresponding Sell Market Webhook JSON can be triggered to exit the position.

Please note that Webhook orders do not provide OCO functionality. The Target and Stop Loss logic needs to be handled through the conditions defined in your Pine Script.

if buy condtion met buy jason Buy CE fire order ,if SL condition met means sell CE it will not exit right ,it will punch new order instead of exit ..how it possible to exit ,i am new to algo

Hello @Jeya_Chan ,

If the Buy condition is triggered first, the Buy JSON will place the order and create an open position in that contract.

When your SL condition is triggered, if the Sell JSON is for the same contract, the Sell order will square off the existing Buy position.

However, if the Sell condition is triggered when there is no existing Buy position in that contract, the Sell order will create a new short position instead of exiting anything.

Therefore, the entry and exit conditions need to be properly handled in your Pine Script so that the Sell webhook is triggered only when the corresponding Buy position exists.

In case of options buy triggers CE and sell triggers buy PE how to close buy CE

Hello @Jeya_Chan ,

We want to inform you that, these order trigger conditions has to be managed under the pine script as per the logic intended by you.