For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Got IndexError: array index out of range if preload=False
-
Hi,
I want to caculate growth each day, so I did like this in strategy:
class UserStockStrategy(bt.Strategy): def __init__(self): exp_variables["growth"] = (self.data.close - self.data.close[-1])/self.data.close[-1]
Everthing is OK, until I run cerebo with preload=False
cerebro = bt.Cerebro(runonce=False, preload=False)
The I got IndexError:
IndexError: array index out of rangeexp_variables["growth"] = (self.data.close - self.data.close[-1])/self.data.close[-1] File "/home/user/.local/lib/python3.7/site-packages/backtrader/linebuffer.py", line 163, in __getitem__ return self.array[self.idx + ago] IndexError: array index out of range
Could anybody help me, thanks
-
@yacc-don please take a look at delayed indexing docs: https://www.backtrader.com/docu/concepts/#lines-delayed-indexing
-
@vladisld Thanks