Reputation:
I want to draw two horizontal lines over one of built-in indicators.
I've tried to create a custom script:
study("Lines")
p1 = plot(0.1)
p2 = plot(0.25)
fill(p1, p2, color=green)
So, I can draw this lines in a separate widget, but how can I draw 'em over another indicator (CMF)?
Upvotes: 0
Views: 6854
Reputation: 11
Is this what you are trying to achieve?
//@version=1
study(title="Relative Strength Index", shorttitle="My StockRSI with RSI")
src = close, len = input(8, minval=1, title="Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, title='RSI',color=#0000ff, transp=0, linewidth=1)
band2 = hline(70, title="Upper band", color=red, linestyle=solid, linewidth=1)
band1 = hline(50, title="Middle band", color=olive, linestyle=solid, linewidth=1)
band0 = hline(30, title="Lower band", color=teal, linestyle=solid, linewidth=1)
//Stochastic RSI//
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
plot(k, title='Smooth K',color=teal, transp=10)
plot(d, title='Smooth D',color=#ff7f00, transp=10)
h0 = hline(100, title="Upper band", linestyle=solid, linewidth=1, color=olive)
h1 = hline(0, title="Lower band", linestyle=solid, linewidth=1, color=olive)
Upvotes: 1