After removing the following arguments the code ran, lol.
dtformat=('%Y-%m-%d'),tmformat=('%H:%M:%S'),
After removing the following arguments the code ran, lol.
dtformat=('%Y-%m-%d'),tmformat=('%H:%M:%S'),
The rest of the code is the default getting started code.
I noticed there was some issues with the data, after fixing, I'm getting another error
File "C:\Users\GEO\AppData\Local\Programs\Python\Python37-32\lib\_strptime.py", line 362, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: 00:02:13
I tried adding different timeframe like minutes ticks etc same error
data = btfeeds.GenericCSVData(dataname='finally.csv',dtformat=('%Y-%m-%d'),tmformat=('%H:%M:%S'),timeframe=bt.TimeFrame.Seconds, compression=1,datetime=1, high=3, low=4, open=2, close=5, volume=-1, openinterest=-1)
timestamp Open High Low Close
0 2019-11-01 00:02:13 9153.5 9154 9147.5 9147.5
1 2019-11-01 00:06:33 9147.5 9148 9123.5 9123.5
Strategy code
def next(self):
self.count += 1
print(self.count)
print('*' * 5, 'NEXT:', bt.num2date(self.data.datetime[0]), self.data._name, self.data.open[0], self.data.high[0],
self.data.low[0], self.data.close[0], self.data.volume[0],
bt.TimeFrame.getname(self.data._timeframe), len(self.data))
if not self.position:
if self.data.close[0] > self.sma[0]:
print("BUY %.2f" % self.data.close[0])
self.order = self.buy()
else:
if self.dataclose[0] < self.sma[0]:
print("SELL %.2f" % self.data.close[0])
self.order = self.sell()
Importing Datafeed
data = btfeeds.GenericCSVData(dataname='cdataNov.csv',dtformat=('%Y-%m-%d'),tmformat=('%H:%M:%S'), datetime=1, high=3, low=4, open=2, close=5, volume=-1, openinterest=-1)
cerebro.adddata(data)
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.addstrategy(TestStrategy)
cerebro.run()
Error
Traceback (most recent call last):
Starting Portfolio Value: 100000.00
File "C:/Users/GEO/PycharmProjects/untitled/one.py", line 93, in <module>
cerebro.run()
File "C:\Users\GEO\PycharmProjects\untitled\venv\lib\site-packages\backtrader\cerebro.py", line 1127, in run
runstrat = self.runstrategies(iterstrat)
File "C:\Users\GEO\PycharmProjects\untitled\venv\lib\site-packages\backtrader\cerebro.py", line 1212, in runstrategies
data.preload()
File "C:\Users\GEO\PycharmProjects\untitled\venv\lib\site-packages\backtrader\feed.py", line 685, in preload
while self.load():
File "C:\Users\GEO\PycharmProjects\untitled\venv\lib\site-packages\backtrader\feed.py", line 476, in load
_loadret = self._load()
File "C:\Users\GEO\PycharmProjects\untitled\venv\lib\site-packages\backtrader\feed.py", line 707, in _load
return self._loadline(linetokens)
File "C:\Users\GEO\PycharmProjects\untitled\venv\lib\site-packages\backtrader\feeds\csvgeneric.py", line 105, in _loadline
dtfield = linetokens[self.p.datetime]
IndexError: list index out of range
What can I do to fix this error?