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'])