This is the error message that I am getting
TypeError: 'instancemethod' object has no attribute '__getitem__'
...
USER ALGORITHM:12, in handle_dataGo to IDE
current_price = data.current[context.security,'price']
Here is my code
def initialize(context):
context.security = symbol('SPY')
#Will be called upon every trade event for the securities you specified
def handle_data(context,data):
print(data)
price_hist1 = data.history(context.security, 'price', 50, '1d')
MA1 = price_hist1.mean()
price_hist2 = data.history(context.security, 'price', 200, '1d')
MA2 = price_hist2.mean()
current_price = data.current[context.security,'price']
current_position = context.portfolio.positions[symbol('SPY')].amount
cash = context.portfolio.cash
if (MA1 > MA2) and current_positions == 0:
numbe_of_shares = int(cash/current_price)
order(context.security, number_of_shares)
log.info('Buysing Shares')
elif (MA1 < MA2) and current_price != 0:
order_target(context.security, 0) #second para = # of shares you keep
log.info('Selling Shares')
record(MA1 = MA1, MA2 = MA2, Price = current_price) # Name = actual value