Rsi calculation - correction requested

Team

There is a huge difference in RSI Calculation using talib. RSI Calculation as per code is 49.07 for 60 Minutes Timeframe and as per exchange is 33.94. My code used is - Please help me in correction

SYMBOL = “NIFTY”
EXCHANGE = “NFO”
TIMEFRAME = ‘60’

— Fetch symbols —

atm_ce_symbol, atm_pe_symbol, _ = tsl.ATM_Strike_Selection(Underlying=SYMBOL, Expiry=0)
ce_symbol, pe_symbol, _, _ = tsl.ITM_Strike_Selection(Underlying=SYMBOL, Expiry=0, ITM_count=1)

all_symbols = [atm_ce_symbol, atm_pe_symbol, ce_symbol, pe_symbol]

— Fetch and process historical data for each symbol —

for symbol in all_symbols:
try:
data = tsl.get_historical_data(tradingsymbol=symbol, exchange=EXCHANGE, timeframe=TIMEFRAME)
df = pd.DataFrame(data)

    if 'timestamp' in df.columns:
        df['timestamp'] = pd.to_datetime(df['timestamp'])
        df.set_index('timestamp', inplace=True)
    else:
        print(f"No 'timestamp' column in data for {symbol}")
        continue
    if 'close' not in df.columns or 'open' not in df.columns:
        print(f"No 'close' or 'open' column in data for {symbol}")
        continue
    df['rsi'] = talib.RSI(df['close'], timeperiod=14).round(2)

    print(atm_ce_symbol, df['rsi'])

Tradehull Team

Please help me in suggesting a correction to this.

Hi @Karun149 ,

Please note that the RSI calculation relies entirely on the historical data provided by Dhan. Ensure that the data you are using is accurate by cross-verifying it with the RSI values shown on Dhan’s chart for the same symbol and timeframe.

Additionally, before checking the RSI on the broker’s terminal, make sure to refresh the page. Keeping the Dhan page open for an extended period may result in outdated or stale data, leading to incorrect RSI values.