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
-
The obvious approach would seem to store the orders in a
list
when seen and remove then when they are no longeractive
(it is a method in the order) innotify_order
. Or simply store then and only consider those that areactive
duringstop
-
Ok great, thanks. Will try!