Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: array index out of range #15

Open
shixin-code opened this issue Oct 14, 2024 · 1 comment
Open

IndexError: array index out of range #15

shixin-code opened this issue Oct 14, 2024 · 1 comment

Comments

@shixin-code
Copy link

Traceback (most recent call last):
File "e:\code\python\backtrader\btmain_ib.py", line 58, in
results = cerebro.run()
^^^^^^^^^^^^^
File "C:\Users\shixi\miniconda3\envs\backtrader\Lib\site-packages\backtrader\cerebro.py", line 1132, in run
runstrat = self.runstrategies(iterstrat)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\shixi\miniconda3\envs\backtrader\Lib\site-packages\backtrader\cerebro.py", line 1303, in runstrategies
self._runnext(runstrats)
File "C:\Users\shixi\miniconda3\envs\backtrader\Lib\site-packages\backtrader\cerebro.py", line 1536, in _runnext
self._datanotify()
File "C:\Users\shixi\miniconda3\envs\backtrader\Lib\site-packages\backtrader\cerebro.py", line 732, in _datanotify
strat.notify_data(data, status, *args, **kwargs)
File "e:\code\python\backtrader\strategies\emastrategy.py", line 43, in notify_data
self.log(f'status {data._getstatusname(status)}')
File "e:\code\python\backtrader\strategies\basestrategy.py", line 33, in log
dt = dt or self.data.datetime[0]
~~~~~~~~~~~~~~~~~~^^^
File "C:\Users\shixi\miniconda3\envs\backtrader\Lib\site-packages\backtrader\linebuffer.py", line 163, in getitem
return self.array[self.idx + ago]
~~~~~~~~~~^^^^^^^^^^^^^^^^
IndexError: array index out of range

@shixin-code
Copy link
Author

shixin-code commented Oct 14, 2024

code like this

clientId = int(datetime.datetime.now().timestamp())
print(f'clientId: {clientId}') 
ibstore = IBStore(host='127.0.0.1', 
                  port=7497, 
                  clientId=clientId)
data = ibstore.getdata(
              name='AAPL', dataname='AAPL',
              secType='STK', currency='USD', exchange='SMART',
            #   backfill_start=False, backfill=False,
              # fromdate = datetime.datetime(2016, 1, 1),
              # todate = datetime.datetime(2018, 1, 1),
              # historical=True,
              # what='TRADES',
              # timeframe=bt.TimeFrame.Ticks,
              # rtbar=False, 
              _debug=True
              )
cerebro.adddata(data)

broker = ibstore.getbroker()
cerebro.setbroker(broker)

cerebro.addstrategy(mystrategy.MyStrategy, printlog=True)

print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
results = cerebro.run()
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant