Hey guys, So I'm trying to work on an algorithm that takes the highs and lows for the RSI and uses those values to for a chosen period but I can't seem to figure out a way to get the values of the RSI highs and low. I am very new to Python so any help is greatly appreciated.
Here is the code I have so far.
from numpy import isnan, matrix, array, zeros, empty, sqrt, round, ones, dot, append, mean, cov, transpose, linspace
import talib
import numpy as np
import pandas as pd
import statsmodels.api as statsmodels
import statsmodels.tsa.stattools as statstools
def initialize(context):
context.data_frequency = '1m'
context.RSI_period = 140
context.RSI_field = 'close_price'
context.RSI_high_period = 450
context.RSI_low_period = 450
context.RSI_high = 0
context.RSI_low = 0
context.stock = symbol('SPY')
def handle_data(context, data):
price_history = history(
bar_count = context.RSI_period,
frequency = context.data_frequency,
field = context.RSI_field
)
RSI = price_history.apply(talib.RSI, timeperiod=context.RSI_period).iloc[-1]
RSI_high = price_history.apply(talib.RSI, timeperiod=context.RSI_period).iloc.high()
RSI_low = price_history.apply(talib.RSI, timeperiod=context.RSI_period).iloc.low()
record(rsi = RSI, RSIhigh = RSI_high, RSIlow = RSI_low)
I've also drawn a picture of what the indicator would look like when it is functional to give a better idea of what I'm trying to accomplish.
http://imgur.com/wsjNHG2
I can also link a video that goes over this type of algorithm is requested.
Thanks for your time!