Modify BO Stoploss orders for all pending orders at once

ZZ8030
Hi people,

I use only BO orders. When I reached a profitable position, I want to modify the SL limit price of all the orders to a few ticks away from the LTP, so that I can secure the profitable position. TSL is not useful for this purpose. Since I used to took more trades it is hectic to do it manually. Is there any way to place modifyBOSL of all pending orders at a price few ticks away from the LTP. Thanks in advance.
  • sujith
    You can modify trigger price of the stop-loss order.
  • HowUTrade
    @ZZ8030

    The best way to do this, virtually trail your mtm in excel and when your PnL crosses below your trailmtm, then call ExitBO to close your BO position.

    But if still want to modify all SL order, then you can use the below code;
    'This is generic example to modify all BO stoploss at certain % from Ltp
    'Modify your code to suit your requirements
    'Make sure you are not calling this function in a loop
    'Use static variables to restrict multiple calling of this function


    https://gist.github.com/botany02/a9127384ad9015b7b28800cd7a1d93e3

    Public Function ModifyAllBOStoploss(ByVal ParentOrderId As String) As String
    On Error GoTo ErrHandler:
    'This is generic example to modify all BO stoploss at certain % from Ltp
    'Modify your code to suit your requirements
    'Make sure you are not calling this function in a loop
    'Use static variables to restrict multiple calling of this function

    Dim ModifyPct As Single
    ModifyPct = 0.25 / 100 'Modify the stoploss with 0.25% from Ltp

    Dim ChildOrders As String
    ChildOrders = Kite.GetChildOrders(ParentOrderId)

    If ChildOrders = vbNullString Then ModifyAllBOStoploss = "NullChildOrders": Exit Function

    Dim ChildOrderArray() As String
    ChildOrderArray = Split(ChildOrders, ",")

    'Loop through all child orders
    'Check for SL order type
    'Check for transaction

    Dim ChildOrder As Variant
    For Each ChildOrder In ChildOrderArray
    If ChildOrders <> vbNullString Then 'Check for Null or Empty order id
    Dim OrdType As String
    OrdType = Kite.GetOrderType(ChildOrder)
    If OrdType = "SL" Then 'Modify only if OrderType SL
    Dim Trans As String
    Dim Exch As String
    Dim TrdSym As String

    Trans = Kite.GetOrderTrans(ChildOrder)
    Exch = Kite.GetOrderExch(ChildOrder)
    TrdSym = Kite.GetOrderTrdSym(ChildOrder)

    Dim Ltp As Double
    Ltp = Kite.GetLtp(Exch, TrdSym)

    If Ltp > 0 Then 'Check we have correct Ltp
    Dim NewSlPrice As Double
    Dim PointsToModify As Double
    PointsToModify = Ltp * ModifyPct '455 * 0.0025 = 1.14

    If Trans = "BUY" Then 'SL BUY Order
    NewSlPrice = Ltp + PointsToModify
    Else 'SL SELL order
    NewSlPrice = Ltp - PointsToModify
    End If

    'Modify the BO stoploss order
    Kite.ModifyBOSl ChildOrder, NewSlPrice
    End If

    End If
    End If
    Next
    ModifyAllBOStoploss = "Success"
    Exit Function
    ErrHandler:
    ModifyAllBOStoploss = Err.Description
    End Function
Sign In or Register to comment.