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)



  • 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


  • administrators

    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



  • Ok great, thanks. Will try!