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/

    Print all pending orders during stop(self)

    General Code/Help
    2
    3
    823
    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.
    • J
      jf last edited by

      Dear backtrader-community:

      I would like to print all open orders (all orders that have been submitted but have not yet been executed) at the end of the backtest. I guess the stop() function would be th best place to do this.

      So far I have used this approach:

      def stop(self):
              if self.order.status in [self.order.Submitted, self.order.Accepted]:
                  print('-----Asset:             {}'.format(self.order.params.data._name))
                  print('-----Order Size:        {}'.format(self.order.params.size))
      

      This works well if there is just one order, but it doesn't seem to work when there are several pending orders. Does anyone have an idea how I can loop through all pending orders?

      Thanks!
      JF

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        The obvious approach would seem to store the orders in a list when seen and remove then when they are no longer active (it is a method in the order) in notify_order. Or simply store then and only consider those that are active during stop

        1 Reply Last reply Reply Quote 1
        • J
          jf last edited by

          Ok great, thanks. Will try!

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