Python Stochastic RSI (same as TradingView)

February 24, 2021
import numpy as np
import talib as ta
import tulipy as ti

rsi = ta.RSI(data['Close'], timeperiod=14)
rsinp = rsi.values
rsinp = rsinp[np.logical_not(np.isnan(rsinp))]
fastk, fastd = ti.stoch(rsinp, rsinp, rsinp, 14, 3, 3)
data['fastk'] = np.concatenate([np.empty(31) * np.nan, fastk])
data['fastd'] = np.concatenate([np.empty(31) * np.nan, fastd])

NOTE: ta.STOCHRSI issue.

The following produce quite similar result with minor differences.

rsi = ta.RSI(data['Close'])
data['fastk'], data['fastd'] = ta.STOCH(rsi, rsi, rsi)
rsi = ta.RSI(data['Close'])
rsinp = rsi.values
rsinp = rsinp[np.logical_not(np.isnan(rsinp))]
data['fastk'], data['fastd'] = ta.STOCH(rsinp , rsinp, rsinp)
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.