extending data feed ==> list index out of range issue
-
Hi, I am new to backtrader, and I have a minute-based OHLCV dataset for BTC price, but with an extra 'Forecast' column. I read the
extending data feeds
post and made my own datafeed class as shown below:class datafeed(GenericCSVData): lines = ('Forecast',) # add a 'Forecast' line to the inherited ones from the base class params = ( ('nullvalue', float('NaN')), ('dtformat', '%Y-%m-%d %H:%M:%S'), ('tmformat', '%H:%M:%S'), ('datetime', 1), ('open', 2), ('high', 3), ('low', 4), ('close', 5), ('volume', 6), ('Forecast', 11) # 11th col )
and I am trying to compare the open price and forecast price as a signal
def __init__(self): # To control operation entries self.orderid = None # Create a CrossOver Signal from close an moving average self.signal = self.data.Forecast - self.data.open
But I have the error:
Traceback (most recent call last): File "D:/DailyTradeForecast.py", line 228, in <module> runstrategy() File "D:/DailyTradeForecast.py", line 159, in runstrategy cerebro.run() File "C:\Users\anaconda3\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\anaconda3\lib\site-packages\backtrader\cerebro.py", line 1212, in runstrategies data.preload() File "C:\Users\anaconda3\lib\site-packages\backtrader\feed.py", line 688, in preload while self.load(): File "C:\Users\anaconda3\lib\site-packages\backtrader\feed.py", line 479, in load _loadret = self._load() File "C:\Users\anaconda3\lib\site-packages\backtrader\feed.py", line 710, in _load return self._loadline(linetokens) File "C:\Users\anaconda3\lib\site-packages\backtrader\feeds\csvgeneric.py", line 148, in _loadline csvfield = linetokens[csvidx] IndexError: list index out of range Process finished with exit code 1
I am not so sure what is wrong with my datafeed, or it is the error from the signal, can someone help?
-
Could you please share at least a part of the csv file ?
-
I have the same problem,My solution is to get more columns out。
-
thank you all for the response, I solve the problem by following the documentation, just make sure you count the column number correctly (start from 0) and follow the extending data section in doc
-
@zhangjt9317 which documentation did you read to correct the code?
-