在内置指示器上绘制水平线

时间:2017-12-14 16:37:21

标签: tradingview-api pine-script

我想在一个内置指示器上绘制两条水平线 我试图创建一个自定义脚本:

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

所以,我可以在一个单独的小部件中绘制这些行,但是如何在另一个指示符(CMF)上绘制它们呢?

1 个答案:

答案 0 :(得分: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)