I have a custom indicator that I use on Tradingview. The values for the mst indicator in python do not match the values for mst indicator in Tradingview. How do I fix this so the values are exactly the same?
The pinescript code is as follows:
//Calculate MST
RSI = ta.rsi(close, 14)
rsidelta = ta.mom(RSI, 9)
rsisma = ta.sma(ta.rsi(close, 3), 3)
mst = rsidelta+rsisma
plot(mst, title="MST", color=#BB2BFA, linewidth = 2)
I am trying to replicate the exact values for MST in a python script. The python code for RSI that I am using is as follows:
def rsi(df: pd.DataFrame, period: int = 14, source: str = 'close') -> np.array:
rsi = ta.rsi(df[source], period)
if rsi is not None:
return rsi.values
This is code in my configuration file:
[scans.7] # MST
rsi_source = 'close'
rsi_period = 14
rsi_delta_period = 9
rsi_sma_period = 3
mst_threshold = [20, 80]
This is code in scanner.py file
# Scan 7
if '7' in self.scans:
scan = self.scans['7']
rsi = indicators.rsi(df=df, period=scan['rsi_period'], source=scan['rsi_source'])
rsi_delta = rsi[-1] - rsi[-scan['rsi_delta_period']]
rsi_sma = pd.Series(indicators.rsi(df=df, period=scan['rsi_sma_period'], source=scan['rsi_source'])).rolling(scan['rsi_sma_period']).mean()
mst = rsi_delta + rsi_sma
I have encountered the same issue on the EMA indicator for me the issue was that I took the last 500 candles from Binance and tried to calculate the EMA and see if the values matched Trading View's values, then I realized that the EMA + RSI indicators are recursive(meaning they relay on past result values to generate a result.) with this said it might be that the reason for this inaccuracy in results is simply the fact that my indicator calculation started at a different point than that of Trading view's resulting in slight inaccuracies between the results.