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

StopTrailLimit throwing issue to specify one value



  • I have the following code.

    p1 = close
    tp = p1 - (10 * atr)
    sp = p1 + (4 * atr)
    trail = (3 * atr)
    # Parent
                self.order = self.sell(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)
    
                logging.info('{}: Oref {} / Sell at {}'.format(self.datetime.date(), self.order.ref, p1))
    
                # Take Profit
                oT = self.buy(exectype=bt.Order.Limit,
                              price=tp,
                              # valid=valid3,
                              account=self.account,
                              parent=self.order,
                              size=self.order.size,
                              transmit=False)
    
                logging.info('{}: Oref {} / Buy TP Limit at {}'.format(self.datetime.date(), oT.ref, tp))
    
                # Stop Trail Limit
                o3 = self.buy(exectype=bt.Order.StopTrailLimit,
                              price=p1,
                              plimit=sp,
                              trailamount=trail,
                              account=self.account,
                              parent=self.order,
                              size=self.order.size,
                              transmit=True)
    

    When I execute. I get an error saying "You must specify one value: Limit Price or Limit Price Offset Value.

    This is on IBKR. I do not specify the limit price offset. Does anyone see the issue?



  • Please include the actual error message and if possbile what line it's referring to. Thanks.



  • That is the error. "You must specify one value: Limit Price or Limit Price Offset Value."



  • afaik this is coming from IB, because of the nature of stoptraillimit orders. to place a valid stop-trail-limit order you will need the "limit price" at which you want to trail to start or an offset which is then used to calculate the "limit price". without either of these its not a valid stl order.
    https://www.interactivebrokers.com/en/software/tws/usersguidebook/ordertypes/trailing_stop_limit.htm

    but the error could also mean you are specifying both limit price and limit price offset value, based on the above code you are only specifying plimit and not offset, so its coming from somewhere else. I saw one thread on ib_insync where this happened because TWS has a default offset is set in Order Presets configured. maybe you can check and confirm.
    https://github.com/erdewit/ib_insync/issues/88
    https://groups.io/g/twsapi/topic/trail_limit_orders/34461744?p=



  • Yes. It looks like TWS automatically sets the offset for you in the Global Configuration. Another item I notice is StopTrailLimits need to explicitly have the RTH=True if you want the trail to work after hours.


Log in to reply
 

});