I need help with that
I need help with that
harrison,
Try this:
# Force index indicator
# http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:force_index
# Force Index(1) = {Close (current period) - Close (prior period)} x Volume
# Force Index(13) = 13-period EMA of Force Index(1)
import talib
def initialize(context):
schedule_function(Force_index_indicator,date_rules.every_day(),time_rules.market_close(minutes = 1))
def Force_index_indicator(context,data):
asset = symbol('SPY')
period = 13
C = data.history(asset, 'price', period + 1, '1d').dropna(axis = 1)
V = data.history(asset, 'volume', period , '1d').dropna(axis = 1)
changes = C.apply(talib.MOM, timeperiod = 1).dropna()
force_1 = changes*V
force = force_1.apply(talib.EMA, timeperiod = period).iloc[-1].dropna()
record(force_index = force)