The below code has error message below when I load only one series of OHLC data (In Pandas DataFrame format). But it doesnt have problem when I add a second series of data. i.e with two data series it works.
And when I use "runonce=True" setting, it works also.
So it ONLY doesn't work when I load only one series of data and use "runonce=False" set up. Does anyone know what is wrong here?
"C:\ProgramData\Anaconda3\lib\site-packages\backtrader\linebuffer.py", line 163, in getitem
return self.array[self.idx + ago]
IndexError: array index out of range
class TestStrategy(bt.Strategy):
def __init__(self):
self.closePx = self.datas[0].close
def next(self):
# The LINE BELOW POP UP ERROR MSG ABOVE
print(self.stats.broker.value[0])
# ***************************************************************
def stop(self):
pass
data = bt.feeds.PandasData(dataname=dailyOHLCDF, open='Open', high='High', low='Low', close = 'Close', volume = 'Volume'\
, openinterest=None)
cerebro = bt.Cerebro(stdstats=False)
cerebro.adddata(data)
cerebro.addobserver(bt.observers.Broker, plot = False)
cerebro.broker.setcash(500000.0)
cerebro.addstrategy(TestStrategy)
thestrats = cerebro.run(runonce=False)