Search code examples
pine-scriptpine-script-v5pine-script-v4

Get RSI from a fixed timeframe in TradingView pine script


I want an RSI indicator that has a fixed time frame (a week), ignoring the current chart time frame.

I only want the last value of the RSI (week) chart because the indicator will show signals for a scalping time frame depending on this RSI.

I don't want to plot it, it is just for testing purposes. I got 100 or 0.

//@version=5
indicator("TEST", overlay=true)
t = ticker.new(syminfo.prefix, syminfo.ticker)
w_close = request.security(t, 'W', close)

rsi = ta.rsi(w_close, 14)
// plot(rsi)

How can I get the value of the last candle for the RSI on a weekly chart?


Solution

  • You can use your calculated rsi value in the security() function.

    //@version=5
    indicator("TEST", overlay=false)
    
    rsi = ta.rsi(close, 14)
    w_close = request.security(syminfo.tickerid, 'W', rsi)
    plot(w_close)
    

    enter image description here