new sell order executed alone with previous BracketOrder(stop loss)
-
Hi there,
I have created a bracket order as suggested:
mainside = self.buy(price=13.50, exectype=bt.Order.Limit, transmit=False) lowside = self.sell(price=13.00, size=mainside.size, exectype=bt.Order.Stop, transmit=False, parent=mainside) highside = self.sell(price=14.00, size=mainside.size, exectype=bt.Order.Limit, transmit=True, parent=mainside)
A few bars later, I created a sell order to sell out whole stakes in next(). However, previous bracket order (stop loss) has also been triggered and both orders have been executed and position goes to negative. Do you have any idea how to avoid that?
Thanks so much!
-
It isn't clear what you are trying to say, because not enough information is provided. From your message let's assume the following:
- Bracket Orders are issued. Main Order (Buy) is active and the 2 bracketing (Sell) orders are inactive (they only become active when the main order is executed)
- Main Order (Buy) is executed and the 2 bracketing (Sell) orders become active
- You issue a new
Sell
order and is executed - One of the 2 bracketing orders (
Sell
) is also executed. The other is correspondingly canceled.
Yes, you have a negative position, i.e.: you have gone short.
What is your expectation?
The only thing which seems logical is to canel the bracketing orders before issuing the new sell to avoid them being executed.
-
Yes, that is what happened. Is there any mechanism available in BackTrader to support long-only strategy?
If not, I need to manage all active sell order in the implementation of my strategy and cancel all (some) of them before issuing new sell order, right?Thanks!
-
@fei-xue said in new sell order executed alone with previous BracketOrder(stop loss):
Yes, that is what happened. Is there any mechanism available in BackTrader to support long-only strategy?
You can implement a custom
Sizer
(Docs - Sizers) and avoid selling if your position is already at0
.@fei-xue said in new sell order executed alone with previous BracketOrder(stop loss):
If not, I need to manage all active sell order in the implementation of my strategy and cancel all (some) of them before issuing new sell order, right?
This is a MUST, not something you think you might do, but it's a lot better if the platform can think for you. You need to manage your orders and your positions.
-
It is clear for me now. Thank you so much!!!