Question about Stop Loss Trading article
I have a question regarding Stop Loss Trading article
why do we need to have a parent child order to do stop loss?
def next(self): if not self.position and self.crossup > 0: if self.buy_order: # something was pending self.cancel(self.buy_order) # not in the market and signal triggered if not self.p.buy_limit: self.buy_order = self.buy(transmit=False) else: price = self.data.close * (1.0 - self.p.buy_limit) # transmit = False ... await child order before transmission self.buy_order = self.buy(price=price, exectype=bt.Order.Limit, transmit=False) # Setting parent=buy_order ... sends both together if not self.p.trail: stop_price = self.data.close * (1.0 - self.p.stop_loss) self.sell(exectype=bt.Order.Stop, price=stop_price, parent=self.buy_order) else: self.sell(exectype=bt.Order.StopTrail, trailamount=self.p.trail, parent=self.buy_order)
I thought we could we can use something like below to do both buy and stop loss together
self.buy(size=1, exectype=bt.Order.StopTrail, trailamount=0.25)
@petehe The line you posted issues buy trailing stop order only.