SL and SL trail order placement syntax confusion

Hi Dhan team,
I am very confused, how to give sell order after buying complete in option trading and also share if any videolink given by dhan

In your dhan trade hul link only buying order placement given where as selling order limit and trigger price which will be smaller or greater while doing automation trading lower level SL order or at higher level target order

let say i have purchase buy call ABCAPITAL ,strick price 400 at 20
then how to write dhan code for sell order stopmarket and stoplimit at lowere level for SL order

trigger_price=20% down price of call buying price

orderid = tsl.order_placement(tradingsymbol=ABCAPITAL , exchange=NFO, quantity=qty,
price=0, trigger_price=16,order_type=“STOPMARKET”, transaction_type=“SELL”, trade_type=“MIS”)

orderid = tsl.order_placement(tradingsymbol=ABCAPITAL , exchange=NFO, quantity=qty,
price=16, trigger_price=16.5,order_type=“STOPLIMIT”, transaction_type=“SELL”, trade_type=“MIS”)

is the above 2 syntax correct and also correct me while selling at higher level

trigger_price=20% higher price of call buying price

orderid = tsl.order_placement(tradingsymbol=ABCAPITAL , exchange=NFO, quantity=qty,
price=0, trigger_price=0, order_type=“MARKET”, transaction_type=“SELL”, trade_type=“MIS”)

orderid = tsl.order_placement(tradingsymbol=ABCAPITAL , exchange=NFO, quantity=qty,
price=0, trigger_price=24, order_type=“LIMIT”, transaction_type=“SELL”, trade_type=“MIS”)

and also can you share how to place modify SL trail syntax if partial profit exit done (in the above SL order example ,what will be synatx for SL trail order.

Regard

Rupali

@imran sir,

Waiting for your reply since 2 weeks.
kindly guide me
Regards
Rupali

Hi @Rupali1 ,

Market orders cannot be placed via API. Use SL-Limit orders for Stop Loss and Limit orders for Target/Exit.

For example, if the option was bought at ₹20 and SL trigger is ₹16:

sl_orderid = tsl.order_placement(
    tradingsymbol='ABCAPITAL ... CALL',
    exchange='NFO',
    quantity=qty,
    price=15.90,
    trigger_price=16,
    order_type='STOPLIMIT',
    transaction_type='SELL',
    trade_type='MIS'
)

For a SELL SL-Limit order, keep the limit price slightly below the trigger price. Example: Trigger ₹16, Limit ₹15.90.

For a target at ₹24:

target_orderid = tsl.order_placement(
    tradingsymbol='ABCAPITAL ... CALL',
    exchange='NFO',
    quantity=qty,
    price=24,
    trigger_price=0,
    order_type='LIMIT',
    transaction_type='SELL',
    trade_type='MIS'
)

After partial profit booking, the pending SL can be trailed using modify_order():

tsl.modify_order(
    order_id=sl_orderid,
    order_type='STOPLIMIT',
    quantity=remaining_qty,
    price=18.90,
    trigger_price=19
)

Here the SL is trailed from ₹16 to ₹19. The SL order should be in pending status for modification.

@Tradehull_Imran ,
thank you for your reply,
1.As per the above examaple ,if we will use price=15.90,trigger_price=16 nearby

then it may be possible price can be jump below it without executing it.
In dhan ,we dont’t have SL-M /STOPMARKET order instead of STOPLIMIT

if yes, kindly give syntax of it .

  1. In modify order: tsl.modify_order

everytime we need to change the value or system will automatic trail it like ATR trail .

can you share me syntax of ATR trail SL

3. what is the syntax to write any stock future buy and Sell .

kindly share it

Regards

Rupali

Hi @Rupali1 ,

1. Stop-loss market order

Dhan’s API lists a stop-loss market order. In Tradehull, the order type is written as STOPMARKET. A stop-market order can execute at a different price if the market gaps past the trigger, so the execution price is not guaranteed.

For a long position, to trigger a sell stop at ₹16:

sl_orderid = tsl.order_placement(
    tradingsymbol='ABCAPITAL FUT',
    exchange='NFO',
    quantity=qty,
    price=0,
    trigger_price=16,
    order_type='STOPMARKET',
    transaction_type='SELL',
    trade_type='MARGIN'
)

If you use STOPLIMIT, the limit price is your minimum acceptable selling price. A gap below that price can leave the order unfilled.

2. Trailing an SL using ATR

tsl.modify_order() does not calculate or trail an ATR stop by itself. Your code must calculate the ATR-based stop and modify the pending stop order when the stop moves. For a long position, this example only raises the stop:

# atr_value and highest_price must be updated by your strategy.
new_trigger = round(highest_price - (2 * atr_value), 2)

if new_trigger > current_trigger:
    modified_orderid = tsl.modify_order(
        order_id=sl_orderid,
        order_type='STOPLIMIT',
        quantity=remaining_qty,
        price=round(new_trigger - 0.10, 2),
        trigger_price=new_trigger
    )
    current_trigger = new_trigger

Here, 2 is the ATR multiplier and 0.10 is the limit-price offset; choose values that suit the instrument and its tick size. The SL order must still be pending to be modified.

3. Buy or sell a stock future

For a stock future, use a LIMIT order and set price to your chosen limit price. Replace future_symbol_name, qty, and limit_price with the contract, quantity, and price you want.

# Buy a stock future
buy_orderid = tsl.order_placement(
    tradingsymbol=future_symbol_name,
    exchange='NFO',
    quantity=qty,
    price=limit_price,
    trigger_price=0,
    order_type='LIMIT',
    transaction_type='BUY',
    trade_type='MARGIN'
)
# Sell a stock future
sell_orderid = tsl.order_placement(
    tradingsymbol=future_symbol_name,
    exchange='NFO',
    quantity=qty,
    price=limit_price,
    trigger_price=0,
    order_type='LIMIT',
    transaction_type='SELL',
    trade_type='MARGIN'
)