Thank you for the fast response. I will describe my situation.
Now, I want to get historical data from IB to do some backtesting. I have a paper trading account and followed this article 'https://medium.com/@danjrod/interactive-brokers-in-python-with-backtrader-23dea376b2fc' to get the right settings. As already said, I work in a jupyter notebook.
This is my code:
from __future__ import (absolute_import, division, print_function,
unicode_literals)
!pip install https://github.com/blampe/IbPy/archive/master.zip
import pandas as pd
import backtrader as bt
from datetime import datetime
!pip install backtrader[plotting]
%matplotlib inline
# Create a subclass of Strategy to define the indicators and logi
class EMA(bt.Strategy):
# list of parameters which are configurable for the strategy
params = dict(
pfast=7, # period for the fast moving average
pslow=10 # period for the slow moving average
)
def __init__(self):
sma1 = bt.ind.ExponentialMovingAverage(period=self.p.pfast) # fast moving average
sma2 = bt.ind.ExponentialMovingAverage(period=self.p.pslow) # slow moving average
self.crossover = bt.ind.CrossOver(sma1, sma2) # crossover signal
def next(self):
if not self.position: # not in the market
if self.crossover > 0 : # if fast crosses slow to the upside
self.buy() # enter long
elif self.crossover < 0 : # in the market & cross to the downside
self.close() # close long position
cerebro = bt.Cerebro()
ibstore = bt.stores.IBStore(host='127.0.0.1', port=7497, clientId=35)
data = ibstore.getdata(dataname='AAPL-STK-SMART-USD', fromdate=datetime(2017, 5, 1), todate=datetime(2018, 8, 20))
cerebro.adddata(data)
cerebro.addstrategy(EMA)
cerebro.run()
cerebro.plot()
Response: AttributeError: 'Plot_OldSync' object has no attribute 'mpyplot'
Thanks in advance and sorry for not making clear the situation at first.