0

我想在一个内置指标上画两条水平线。
我试图创建一个自定义脚本:

study("Lines")
p1 = plot(0.1)
p2 = plot(0.25)
fill(p1, p2, color=green)

所以,我可以在一个单独的小部件中绘制这条线,但我怎样才能在另一个指标 ( CMF ) 上绘制它们呢?

4

1 回答 1

1

这是你想要达到的目标吗?

//@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)
于 2018-03-19T20:25:15.123 回答