Tradingview 中自定义指标的振荡器通道填充
Oscillator Channel Fill for Custom Indicators in 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。我也为“n”变量插入了一个输入来代替 14。还请考虑使用内置 ta 函数的替代方法的注释 rsi 代码,跳过计算。
//@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")
祝你编码顺利
我已经在 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。我也为“n”变量插入了一个输入来代替 14。还请考虑使用内置 ta 函数的替代方法的注释 rsi 代码,跳过计算。
//@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")
祝你编码顺利