Introducing Webhook Alerts : Direct Order Placements on charts from Dhan

Yes @Wignesha provided JSON has ordertype set as LMT. If you keep the price field unchecked (but specify the limit price) and then click on “Generate JSON” a JSON with limit order type is generated.

@t7support , Thanks for replying. Assume i have set 2% profit in my strategy for each buy entry; I have bought futures one lot at 100INR, my buy target for this entry is 102INR, how would I feed this data to JSON? as like we use strategy.order.contracts placeholder in JSON segment to have desired qty

In your pine script you need to do JSON string manipulation to use your custom limit price.

Got it thanks. So in my pinescript i need to convert the Exit price to String and manipulate in alert message. helps a lot

1 Like

This query is applying stoploss through webhooks.
Suppose I have a buy order of 5 lots which has been executed, now my stoploss has to be executed when the bar closes below a horizontal line.

  1. How to do this via tradingview alerts and webhook.
  2. I tried this in past and that webhook added a new order of sell 5 lots instead of closing the earlier position of buy 5 lots.
  3. Can I combine with my previous alert of buy 5 lots?

If someone can please share the syntax that will be useful.

I am pine script novice so not sure how to strategy.exit but from a previous post of @t7support I had got this line of code.

  1. So can I use this in another webhook
  2. How does this ensures that it acts as a SL and not a fresh sell order.

Thanks!

long_exit_msg = ‘{“secret”:“C0B2u”,“alertType”:“multi_leg_order”,“order_legs”:[{“transactionType”:“S”,“orderType”:“MKT”,“quantity”:“1”,“exchange”:“NSE”,“symbol”:“NIFTY1!”,“instrument”:“FUT”,“productType”:“M”,“sort_order”:“1”,“price”:“0”}]}’

@LotOfOptions

In short we have to use a fresh sell order to exit an open position. You can use my sample code in u r strategy with relevant changes - secret code, order type, symbol, Instrument, exchange, product type etc.

I will explain the why below.

Dhan doesn’t allow us to generate stop loss order JSON in their web interface. We can generate JSON only for Market or Limit orders.

But strategy.exit() in tradingview allows us to put stop orders in their order execution emulator and in the cloud once we set the alert. The stop order doesn’t get placed at the exchange directly when the script is executed. But it does send a fresh exit order to close existing position once the exit condition is met during live market.

1 Like