I am new in pine script and just tring to print the value of RSI of two different timeframes eg "D" (Daily) and "60" (Hourly) using the following code but whenever I change the timeframe from the chart tollber the vales changes !!
daily_close = request.security(syminfo.tickerid, "D", close)
hourly_close = request.security(syminfo.tickerid, "60", close)
rsiD = ta.rsi(daily_close, 14)
rsiH = ta.rsi(hourly_close, 14)
var myTable = table.new(position.bottom_right, 2, 5)
if barstate.islast
table.cell(myTable, 0, 0, "RSI Daily", text_color = color.white)
table.cell(myTable, 1, 0, str.tostring(rsiD[0], "#.##"), text_color = color.white)
table.cell(myTable, 0, 1, "RSI Hourly", text_color = color.white)
table.cell(myTable, 1, 1, str.tostring(rsiH[0], "#.##"), text_color = color.white)
-
What timeframes are you testing this on?vitruvius– vitruvius2025年11月03日 21:12:31 +00:00Commented Nov 3, 2025 at 21:12
-
Daily and hourly RSI values changes when I change the timeframe to 30Min or 15 Min, Or 5 Min, all the values are different in all the different timeframesProsenjit– Prosenjit2025年11月05日 15:27:22 +00:00Commented Nov 5, 2025 at 15:27
-
Is this a strategy or an indicator?vitruvius– vitruvius2025年11月05日 18:58:56 +00:00Commented Nov 5, 2025 at 18:58
-
Just a Indicator Printing the daily and hourly RSI values on 5min or 15min ChartProsenjit– Prosenjit2025年11月05日 19:23:58 +00:00Commented Nov 5, 2025 at 19:23
-
Got it ! Thank you !Prosenjit– Prosenjit2025年11月06日 04:42:49 +00:00Commented Nov 6, 2025 at 4:42
1 Answer 1
You are getting the close price from the security() and using that in ta.rsi(). However, this will not work as you think it will.
Your daily_close will have the daily close price until there is a new day. This means it will have the same value over multiple bars on the lower timeframe you are testing this on. When you pass this variable to ta.rsi() with a length of 14, calculations will be based on daily_close's value on the lower timeframe (many of them will have the same value as explained just before). And NOT the last 14 daily close prices.
You can actually call functions in security().
rsiD = request.security(syminfo.tickerid, "D", ta.rsi(close, 14))
rsiH = request.security(syminfo.tickerid, "60", ta.rsi(close, 14))
var myTable = table.new(position.bottom_right, 2, 5)
if barstate.islast
table.cell(myTable, 0, 0, "RSI Daily", text_color = color.white)
table.cell(myTable, 1, 0, str.tostring(rsiD[0], "#.##"), text_color = color.white)
table.cell(myTable, 0, 1, "RSI Hourly", text_color = color.white)
table.cell(myTable, 1, 1, str.tostring(rsiH[0], "#.##"), text_color = color.white)
This will always use the last 14 daily and 1h close prices.