Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How do I get RSI into 5 Minutes timeframes?

Hi there, I'm comparing the RSI values given by data on Quantopian and it varies greatly from that of charts from Thinkorswim.

I need your help in converting minutely RSI data into 5 Min readings - basically the RSI of a 5-minute candlestick.

Here's what I've gotten thus far from scrolling through past forum questions, and the internet.

def RSI_resampling(context, data):

rsi_period = 14  
prices_1m = data.history(context.nugt, 'close', 300, '1m')  
prices = prices_1m.resample('5T', closed='left').mean()  

rsi = talib.RSI(prices.dropna(), rsi_period)  
print(rsi[-1])

Any input would really be greatly appreciated! Thanks in advance!

2 responses

Try this:

import talib  
# -----------------------------------------------------  
stock = symbol('QQQ');  rsi_period = 14; timeframe = 5;  
# -----------------------------------------------------  
def initialize(context):  
    for i in range(1, 390, timeframe):  
        schedule_function(resampled_RSI, date_rules.every_day(), time_rules.market_open(minutes = i), True )  

def resampled_RSI(context, data):  
    bars = rsi_period*timeframe*2*5  
    C = data.history(stock, 'price', bars,'1m').resample('5T', label='right', closed='right').last().bfill()  
    price = C[-1] 

    rsi = talib.RSI(C, rsi_period)[-1]

    print("%s: Price:%.2f / RSI:%.2f" %(stock, price, rsi))  

Hi Vladimir,

Thanks for the wonderful response!

I have tried it, but the RSI values that have been printed out in the logs make absolutely no sense! It is miles apart from the RSI values that are displayed on 5 min charts on Thinkorswim.

2020-06-10 21:35 PRINT Equity(40553 [NUGT]): Price:66.12 / RSI:83.83
2020-06-10 21:40 PRINT Equity(40553 [NUGT]): Price:65.11 / RSI:0.00
2020-06-10 21:45 PRINT Equity(40553 [NUGT]): Price:65.28 / RSI:15.34
2020-06-10 21:50 PRINT Equity(40553 [NUGT]): Price:65.52 / RSI:31.36
2020-06-10 21:55 PRINT Equity(40553 [NUGT]): Price:65.42 / RSI:28.91
2020-06-10 22:00 PRINT Equity(40553 [NUGT]): Price:64.93 / RSI:20.46
2020-06-10 22:05 PRINT Equity(40553 [NUGT]): Price:64.88 / RSI:19.82
2020-06-10 22:10 PRINT Equity(40553 [NUGT]): Price:64.92 / RSI:21.92
2020-06-10 22:15 PRINT Equity(40553 [NUGT]): Price:64.87 / RSI:21.17
2020-06-10 22:20 PRINT Equity(40553 [NUGT]): Price:64.70 / RSI:18.83
2020-06-10 22:25 PRINT Equity(40553 [NUGT]): Price:64.35 / RSI:15.12
2020-06-10 22:30 PRINT Equity(40553 [NUGT]): Price:64.15 / RSI:13.49
2020-06-10 22:35 PRINT Equity(40553 [NUGT]): Price:63.25 / RSI:8.85
2020-06-10 22:40 PRINT Equity(40553 [NUGT]): Price:63.27 / RSI:9.60

on thinkorswim, the first 3 five minute candles are - 55.5733, 41.2074, 43.839

RSI used on thinkorswim has a period of 14, price = closed, wilders type.

Any idea on why this large discrepancy exists?