Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    General Code/Help
    3
    5
    65
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Bo Vargas
      Bo Vargas last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

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

        1 Reply Last reply Reply Quote 0
        • Bo Vargas
          Bo Vargas last edited by

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

          1 Reply Last reply Reply Quote 0
          • J
            jay last edited by

            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=

            1 Reply Last reply Reply Quote 1
            • Bo Vargas
              Bo Vargas last edited by

              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.

              1 Reply Last reply Reply Quote 1
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }