Backtrader DOES NOT CRASH on MOO orders - The USER CODE does
-
Hi,
I'm getting this traceback when creating MOO(Market On Open) order before market open. It seems that backtrader needs price data to create orders. However, some securities do not trade during premarket.
Any ideas how to fix or work around this?
P.S. This happens in live trading.
Traceback (most recent call last): File "./test-moo.py", line 87, in <module> sys.exit(main(sys.argv)) File "./test-moo.py", line 84, in main cerebro.run() File "backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "backtrader\cerebro.py", line 1295, in runstrategies self._runnext(runstrats) File "backtrader\cerebro.py", line 1626, in _runnext strat._next() File "backtrader\strategy.py", line 325, in _next super(Strategy, self)._next() File "backtrader\lineiterator.py", line 270, in _next self.prenext() File "./test-moo.py", line 53, in prenext self.buy(data, size=100, exectype=bt.Order.Market, File "backtrader\strategy.py", line 905, in buy data = data or self.datas[0] File "backtrader\lineroot.py", line 287, in __nonzero__ return self._operationown(bool) File "backtrader\lineroot.py", line 94, in _operationown return self._operationown_stage2(operation) File "backtrader\lineroot.py", line 218, in _operationown_stage2 return operation(self[0]) File "backtrader\lineseries.py", line 467, in __getitem__ return self.lines[0][key] File "backtrader\linebuffer.py", line 163, in __getitem__ return self.array[self.idx + ago] IndexError: array index out of range
Regards,
Ed -
@Ed-Bartosh maybe some data from the previous day loaded into
bt
might help? -
CORRECTION: YOUR CODE CRASHES.
@Ed-Bartosh said in Backtrader crashes on MOO orders:
Hi,
I'm getting this traceback when creating MOO(Market On Open)That order type is not supported. You are using a
Market
order. But that's not the problem.@Ed-Bartosh said in Backtrader crashes on MOO orders:
It seems that backtrader needs price data to create orders
That's also not the problem.
@Ed-Bartosh said in Backtrader crashes on MOO orders:
File "backtrader\lineiterator.py", line 270, in _next
self.prenext()
File "./test-moo.py", line 53, in prenext
self.buy(data, size=100, exectype=bt.Order.Market,That's the problem. I will reduce it to the actual problem
@Ed-Bartosh said in Backtrader crashes on MOO orders:
File "backtrader\lineiterator.py", line 270, in _next
self.prenext()@Ed-Bartosh said in Backtrader crashes on MOO orders:
Any ideas how to fix or work around this?
Use
next
where guarantees are valid. -
@backtrader said in Backtrader DOES NOT CRASH on MOO orders - The USER CODE does:
Use next where guarantees are valid.
I tried this before using prenext. next is not called as securities are not traded, so there not enough bars I guess. For some securities there is no trading happening at all. Does it mean that for them it's not possible to create orders before market open?
-
prenext
andnext
(andnextstart
) have nothing to do with market times. Docs - Operating the Platform - Minimum Period@ab_trader said in Backtrader DOES NOT CRASH on MOO orders - The USER CODE does:
@Ed-Bartosh maybe some data from the previous day loaded into bt might help?
-
@backtrader said in Backtrader DOES NOT CRASH on MOO orders - The USER CODE does:
prenext
andnext
(andnextstart
) have nothing to do with market times. Docs - Operating the Platform - Minimum Period@ab_trader said in Backtrader DOES NOT CRASH on MOO orders - The USER CODE does:
@Ed-Bartosh maybe some data from the previous day loaded into bt might help?
Have I understood correctly that you're suggesting to load price data to be able to create orders?
-
You want to use a method with no guarantees (i.e.:
prenext
) for a purpose which is also not designed (i.e.: pre-market times, where thepre
in the name and thepre
in market times, have nothing to do with each other)The only thing you present is a trace ... but you obviously come into
prenext
because something has a buffer with at least one data point.. Probably because you use multiple data feeds ... and you probably target the one which doesn't have any data point.You additionally want to send an order type which is not supported (you may implemented it, that I don't know, but it seems a regular
Market
order)@ab_trader has stated how you can overcome the situation and I have remarked it. Your options: do so ... do something else.
-
@backtrader thank you for the explanations.
Yes, I was trying to use one symbol that's trading on pre-market to trigger prenext. As you can see it didn't help much, i.e. it crashed backtrader.
What I was trying to ask (and apparently failed) is: if creating orders without price data supported by backtrader at all? If it's possible then it would be great if you explain how to do it without loading data as @ab_trader suggested. If it's not possible ... well I'll try to work around it using @ab_trader's suggestion.