3

My indicator does not look like the built-in Stochastic RSI indicator from TradingView. How can I get the familiar look, to duplicate the st-RSI indicator?

Here is the screen shot that shows the difference between my code and the TradingView indicator

//@version=3
study("Stoch-RSI")
//smooth = (close + close[1] + close[2]) /3
smooth = close
p_k = stoch(rsi(smooth,14),high,low,14)
p_d = 0.0
for i = 1 to 3
    p_d := p_d + p_k[i]
p_d := p_d / 3

plot(p_k*30,color=orange)
plot(p_d*30,color=purple)
plot(close)

The curve should look the same as the tradingview indicator

Taegost
  • 1,208
  • 1
  • 17
  • 26
Sven
  • 45
  • 1
  • 3
  • 6

2 Answers2

13

this how the formula should look like:

study(title="Stoch-RSI")
band1 = hline(20)
band0 = hline(80)
fill(band1, band0, color=purple,transp=90)
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
src4 = input(close, title="RSI Source")
rsi1 = rsi(src4, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
plot(k, color=blue)
plot(d, color=red)
h0 = hline(80, linestyle=dotted)
h1 = hline(20, linestyle=dotted)
Amr Sakr
  • 181
  • 1
  • 4
3

RSI Stoch in pine version 5

//@version=5
indicator(title="lk - Stoch-RSI (v5)")

// Input data to configure on chart
smoothK = input.int (defval=3, title = "Stochastic %K", minval=1, step=1)
smoothD = input.int (defval=3, title = "Stochastic %D", minval=1, step=1)
lengthRSI = input.int (defval=14, title = "RSI Length", minval=1, step=1)
lengthStoch = input.int (defval=14, title = "Stochastic Length", minval=1, step=1)
src4 = input(close, title="RSI Source")

// Calculate indicator
rsi1 = ta.rsi(src4, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

// Drawing - plot on chart
plot(k, color=color.blue)
plot(d, color=color.red)
h0 = hline(80, linestyle=hline.style_dotted)
h1 = hline(20, linestyle=hline.style_dotted)
band1 = hline(20)
band0 = hline(80)
fill(band1, band0, color.new(color.purple, 90))