Set a stop loss and target at same time

Rajneesh_12
I need to place a buy order and then place stop loss and target limit orders. Right now I have only SL and target as my exit condition.
I don't want to use a BO.

Is there a way I can place SL and target in the same order? If not then what can be a good alternative to BO.
Also, will a GTT OCO order be useful here?

This is what I was trying. I initially placed a b normal BUY market order and a target order and then if ltp falls below sl then I modify target order to SL. But this is not working for me.

kite.place_order(tradingsymbol=symbol,
exchange=kite.EXCHANGE_NFO,
transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=quantity,
order_type=kite.ORDER_TYPE_MARKET,
product=kite.PRODUCT_MIS,
variety=kite.VARIETY_REGULAR)
    kite.place_order(tradingsymbol=symbol,
exchange=kite.EXCHANGE_NFO,
transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=quantity,
order_type=kite.ORDER_TYPE_LIMIT,
price=target,
trigger_price = target,
product=kite.PRODUCT_MIS,
variety=kite.VARIETY_REGULAR)
  • sujith
    You can place an order and use GTT for the exit. An exit can be based on stoploss or target. You can use OCO GTT.
  • Rajneesh_12
    def placeGTT(symbol,quantity,sl_price, target, ltp):    
    kite.place_order(tradingsymbol=symbol,
    exchange=kite.EXCHANGE_NFO,
    transaction_type=kite.TRANSACTION_TYPE_BUY,
    quantity=quantity,
    order_type=kite.ORDER_TYPE_MARKET,
    product=kite.PRODUCT_MIS,
    variety=kite.VARIETY_REGULAR)

    order_dict = [{"transaction_type": kite.TRANSACTION_TYPE_BUY, "quantity": quantity,
    'order_type': kite.ORDER_TYPE_LIMIT, "product": kite.PRODUCT_NRML , "price": sl_price},
    {"transaction_type": kite.TRANSACTION_TYPE_BUY, "quantity": quantity,
    'order_type': kite.ORDER_TYPE_LIMIT, "product": kite.PRODUCT_NRML , "price": target}
    ]
    kite.place_gtt(kite.GTT_TYPE_OCO, symbol, kite.EXCHANGE_NFO, [sl_price, target], ltp, order_dict)
    Is this the correct way?
  • Rajneesh_12
    Also, what is the correct way of finding sl_price, target?

    For example,
    ltp = 2067.7
    I want 1% stop loss

    So my sl_price should be ltp - 0.01*ltp = 0.99 * ltp right?

    And how should I take modulo tick_size to make it a multiple of tick_size, 0.05 in my case.
  • rakeshr
    @Rajneesh_12
    Is this the correct way?
    Yes, this is correct request for OCO GTT.
    Also, make sure you are setting up correct transaction_type here "transaction_type": kite.TRANSACTION_TYPE_BUY. If you are looking for sell exit, transaction_type should be SELL.
    So my sl_price should be ltp - 0.01*ltp = 0.99 * ltp right?
    Yes, sl_price here should be sl value not difference value. So, ltp - 0.01*ltp = 0.99 * ltp is fine.
    how should I take modulo tick_size to make it a multiple of tick_size, 0.05 in my case.
    This thread should help.
  • Rajneesh_12
    @sujith @rakeshr thanks a lot for helping.

    I have one more query.

    Now I also have one more sell exit condition apart from stop loss and target. So it may be possible that this condition is satisfied but GTT orders are still pending.

    How to take this situation into consideration?
  • rakeshr
    There are no direct APIs to cancel another pending stop-loss/target order once, GTT is satisfied or vice-versa.
    You will have to do this other order cancelation at your end for open orders/GTT.
Sign In or Register to comment.