For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

How to notify SL/TP orders created with buy_bracket?



  • I'm searching for an order attribute that could identify whether an executed order is SL/TP. Something like:

    def notify_order(self, order):
    
       if order.status in [order.Completed]:
            if order.isStopLoss():
                self.log('STOP LOSS TRIGGERED, Price: %.5f' % (order.executed.price))
    
            if order.isTargetProfit():            
                self.log('TARGET PROFIT TRIGGERED, Price: %.5f' % (order.executed.price))
    

    The SL/TP is created with buy_bracket method:

    self.order = self.buy_bracket(size=100, price=price, limitprice=profitTargetPrice, stopprice=stopLossPrice)
    

    Is it possible to notify the execution of SL/TP orders?


  • administrators

    The status (execution, cancelation, ...) of all orders is properly and notified in due time.

    TargetProfit and StopLoss are concepts used by the trader. Such orders DO NOT exist.

    Your options:

    • When issuing the bracket keep a reference to the orders you apply to those concepts (in a list or dict or in a simple variable) and compare then to the actual notified orders

    • Add information to the orders when creating them with the method addinfo and check later the info member attribute (a dict)

    Docs - Order - https://www.backtrader.com/docu/order/



  • @backtrader Thank you for your explanation.
    Thanks,

    if order.ref == self.order[1].ref:
        # notify stop loss
    elif order.ref == self.order[1].ref:
        # notify target profit
    

    did the trick.


Log in to reply
 

});