here i attach a function fro calculating rsi. If you want to create your strategy using RSI than contact me i will provide testing with backtesting.
def rsi(df, n): "function to calculate RSI" delta = df["close"].diff().dropna() u = delta * 0 d = u.copy() u[delta > 0] = delta[delta > 0] d[delta < 0] = -delta[delta < 0] u[u.index[n-1]] = np.mean( u[:n]) # first value is average of gains u = u.drop(u.index[:(n-1)]) d[d.index[n-1]] = np.mean( d[:n]) # first value is average of losses d = d.drop(d.index[:(n-1)]) rs = u.ewm(com=n,min_periods=n).mean()/d.ewm(com=n,min_periods=n).mean() df['RSI'] = 100 - 100 / (1+rs) return df
You can get started from here.
def rsi(df, n):
"function to calculate RSI"
delta = df["close"].diff().dropna()
u = delta * 0
d = u.copy()
u[delta > 0] = delta[delta > 0]
d[delta < 0] = -delta[delta < 0]
u[u.index[n-1]] = np.mean( u[:n]) # first value is average of gains
u = u.drop(u.index[:(n-1)])
d[d.index[n-1]] = np.mean( d[:n]) # first value is average of losses
d = d.drop(d.index[:(n-1)])
rs = u.ewm(com=n,min_periods=n).mean()/d.ewm(com=n,min_periods=n).mean()
df['RSI'] = 100 - 100 / (1+rs)
return df