In my algorithm, I can set the TP only when my buy/sell limit has been filled. More specifically, the tp only can be calculated when the current market price is around the buy/sell limit price.
I am using a code like the following to implement this. But the target does not work this way.
self.order_placed = False
if not self.order_placed:
main_order = self.sell(
price=limit_price,
exectype=bt.Order.Limit,
transmit=False,
tradeid=self.soli_strategy_objects.very_next_tradeid,
)
stop_loss_order = self.buy(
price=stop_loss_price,
exectype=bt.Order.Stop,
parent=main_order,
transmit=True,
tradeid=main_order.tradeid,
)
self.order_placed= True
if main_order.status in [bt.Order.Completed] and self.order_placed:
tp_level = self.calculate_tp_level()
Target_Order = self.buy(
price=tp_level,
exectype=bt.Order.Limit,
transmit=True,
parent=bracket_order_instance.main_order,
tradeid=bracket_order_instance.main_order.tradeid,
)
But target order does not work. More specifically, it becomes “Accepted” and remains this way no matter what. (It is like a ghost order that doesn’t exist at all)
Note that I cannot set “transmit” to False for the stop-loss order because in that case my main order does not get activated at all.
Any ideas?
I want the target order to be set whenever I want not necessarily at the same time as the parent order and the other child.
Abbas Shojakani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.