0
votes

I would like to incorporate a 1D RSI into a 4H timeframe. I've tried using resolution or the security functions but these both updated at the candle closure of the daily timeframe and stayed constant until the next day. To get an approximate 20SMA from the 1D chart, I would plot a 120SMA in the 4H chart. It's not the exact same because of the more inputs but it's a bit more precise and more reactive. But if I plot a 1D 14RSI in a 4H chart as an 84RSI I just get a useless indicator floating constantly around the 50 zone.

Example

Is there a way I can get results similar to what I get with the SMA?

//@version=4
study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)

rma_(src, length) =>
    alpha = 1/length
    sum = 0.0
    sum := na(sum[1]) ? sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])

rsi_(x, y) => 
    u = max(x - x[1], 0)
    d = max(x[1] - x, 0)
    rs = rma_(u, y) / rma_(d, y)
    res = 100 - 100 / (1 + rs)
    res

rsi = rsi_(src, len)
plot(rsi, "RSI", color=color.blue, linewidth = 1)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

TIA

1
Please show your results in the screenshot and explain what you would like to change. - AnyDozer
I've added a screenshot to the main post. As you can see the MA is pretty similar in both timeframes but the RSI, due to the nature of it's script, it tends to stay in the middle on the 4H chart. I was wondering if there was a way around it to that it looks similar to the 1D chart just more spread out - Daniel D'Ottavio

1 Answers

0
votes
//@version=4
study(title="Help (Relative Strength Index)", shorttitle="RSI", format=format.price, precision=2, resolution="")
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)

rma_(src, length) =>
    alpha = 1/length
    sum = 0.0
    sum := na(sum[1]) ? sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])

rsi_(x, y) => 
    u = max(x - x[1], 0)
    d = max(x[1] - x, 0)
    rs = rma_(u, y) / rma_(d, y)
    res = 100 - 100 / (1 + rs)
    res

rsi = rsi_(src, len) //currend TF
rsiD = security(syminfo.tickerid, "D", rsi_(src, len))  // TF='D'
plot(rsi, "RSI", color=color.blue, linewidth = 1)
plot(rsiD, "RSI", color=color.green, linewidth = 1)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

The upper window is timeframe D, the lower window is 4H. The values RSI are the same and change in realtime synchronously. What's wrong with that?

enter image description here