Backtrader Community

    • 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/

    Bracket orders - am I supposed to only have one open at a time?

    General Code/Help
    2
    2
    179
    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.
    • B
      booboothefool last edited by

      In the documentation: https://www.backtrader.com/blog/posts/2017-04-01-bracket/bracket/

      There is code like:

      def next(self):
              if self.orefs:
                  return  # pending orders do nothing
      
      def notify_order(self, order):
              if order.status == order.Completed:
                  self.holdstart = len(self)
      
              if not order.alive() and order.ref in self.orefs:
                  self.orefs.remove(order.ref)
      
       self.orefs = [o.ref for o in os]
      
              else:  # in the market
                  if (len(self) - self.holdstart) >= self.p.hold:
                      pass  # do nothing in this case
      
      

      I am wondering what the point of all this is? It makes it look like it's not a good idea to have multiple brackets open at a time. I am indeed running into issues with duplicates/bracket orders hanging around. Can someone clarify if I should be using this template of "pending orders do nothing"?

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

        @booboothefool
        Indeed with one data there should only be one bracket open. However, when using multiple datas, then you need a dictionary to manage the orders. See the article here and the code at the bottom.

        RunBacktest.com

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors