Tradingview中自定义指标的振荡器通道填充



我在tradingview中用pine脚本从头开始编码RSI,仅供学习之用。除了两个问题外,指标运行良好。首先,我没能找到一种方法将背景填充无限期地扩展到右侧。然后,从指示器的设置菜单中更改所需的长度。请帮我解决这两个问题。我的代码如下-

//@version=5
indicator(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
n = 14
up_days = ta.rma(close > close[1] ? close - close[1] :0, n)
down_days = ta.rma(close < close[1] ? close[1] - close :0, n)
rs = up_days / down_days
rsi = 100 - (100/(1+rs))
plot(rsi)
bandm = plot(50, color=color.black)
band1 = plot(70, color=color.black)
band0 = plot(30, color=color.black)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")  

谢谢&当做

要将常量行向前推进,可以使用hline((而不是plot。我插入了一个输入来代替14;n〃;变量。还请考虑注释的rsi代码,以获得使用内置ta函数和跳过计算的替代方法。

//@version=5
indicator(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
n = input.int(14, "Length")
up_days = ta.rma(close > close[1] ? close - close[1] :0, n)
down_days = ta.rma(close < close[1] ? close[1] - close :0, n)
rs = up_days / down_days
rsi = 100 - (100/(1+rs))
// rsi = ta.rsi(close,n)
plot(rsi)
bandm = plot(50, color=color.black)
band1 = hline(70, color=color.black, linestyle= hline.style_solid)
band0 = hline(30, color=color.black, linestyle= hline.style_solid)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background") 

干杯,祝你的编码好运

最新更新