For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Loading one data series and run Got Error Message

  • 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\", 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):
            # ***************************************************************
        def stop(self):
    data = bt.feeds.PandasData(dataname=dailyOHLCDF, open='Open', high='High', low='Low', close = 'Close', volume = 'Volume'\
    , openinterest=None)
    cerebro = bt.Cerebro(stdstats=False)
    cerebro.addobserver(bt.observers.Broker, plot = False)
    thestrats =

  • I juse tested is working.

    But[0] not working. So I can just use right? My goal is to print out broker value every day.

  • administrators

    An Observer operates after things have happened, because it is observing the overall consequences of your actions and the calculations of indicators.

    In iterations next + 1, accessing[0] will give you the broker value of the previous iteration.

    In next + 0 (the 1st time), there is still no data there if you have no indicators forcing you to have a minimum period. And if you have them, you will get and old value as pointed out above.