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

Stop-Loss order is getting value from Parent Order even if sized passed in



  • I have the following order with a stop-loss attached. The problem is the Buy Limit order will be reverse the position from Short -> Long; But I need the Stop-Loss size should be for the balance.

    Example
    Current Position -2 (short)
    Buy 4 (long)
    New Position 2 (long)
    StopLoss Order is 4. I'm passing in the size 2. But somehow this is getting overwritten.

    Does anyone know how to fix this? I don't want to submit an order to close the existing position and then open a new order.

    self.order = self.buy(exectype=bt.Order.Limit,
                                      size=size,
                                      price=p1,
                                      tif='GTD',
                                      goodTillDate=gtd.strftime('%Y%m%d %H:%M:%S GMT'),
                                      account=self.account,
                                      transmit=False)
    
    o2 = self.sell(exectype=bt.Order.Stop,
                               price=sp,
                               valid=valid2,
                               account=self.account,
                               parent=self.order,
                               size=stop_size,  # We want the stop loss to be half our position; meaning don't reverse
                               transmit=True)
    
                logging.info('{}: Oref {} / Sell Stop at {}'.format(self.datetime.date(), o2.ref, sp))
    

Log in to reply
 

});