Hi,
I'm trying to measure the gradient of a long SMA to gaged the price direction.
I'm using this code:
import numpy as np
def initialize(context):
context.stock = [sid(24)]
def handle_data(context, data):
daily_prices = history(bar_count=252, frequency='1d', field='price')
daily_close = np.array(daily_prices[sid].values.tolist())
daily_sma30 = ta.SMA(daily_close, timeperiod=30)
datetimeSeries = daily_prices[sid(24)].keys()
m, b = np.polyfit( datetimeSeries[-30:], daily_sma30[-30:], 1 )
but I'm getting this error:
9 Error Runtime exception: KeyError: u"no item named , {}),\n orders={},\n new_orders=[],\n current_dt=None),\n recorded_vars={})>"
Could someone help correct this code please as I've little knowledge of numpy.
Thanks.