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?
-
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
ordict
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 theinfo
member attribute (adict
)
-
-
@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.