将随机 RSI、DMI 和 RSI 添加到一起
Adding Stochastic RSI, DMI and RSI together
我试图在交易视图中同时添加随机 RSI、DMI 和 RSI,但遇到以下错误 - “添加到图表操作失败,原因:第 39 行:'src' 已定义。”。 =11=]
我的代码如下-
//@version=5
indicator(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
h2 = hline(70, "Upper Band", color=#787B86)
h3 = hline(60, "Upper Band", color=#787B86)
h4 = hline(50, "Upper Band", color=#787B86)
h5 = hline(40, "Upper Band", color=#787B86)
h6 = hline(30, "Upper Band", color=#787B86)
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")
lensig_adx = input.int(14, title="ADX Smoothing", minval=1, maxval=50,group="ADX setting")
len_adx = input.int(14, minval=1, title="DI Length",group="ADX setting")
up_adx = ta.change(high)
down_adx = -ta.change(low)
plusDM_adx = na(up_adx) ? na : (up_adx > down_adx and up_adx > 0 ? up_adx : 0)
minusDM_adx = na(down_adx) ? na : (down_adx > up_adx and down_adx > 0 ? down_adx : 0)
trur_adx = ta.rma(ta.tr, len_adx)
plus_adx = fixnan(100 * ta.rma(plusDM_adx, len_adx) / trur_adx)
minus_adx = fixnan(100 * ta.rma(minusDM_adx, len_adx) / trur_adx)
sum_adx = plus_adx + minus_adx
adx_adx = 100 * ta.rma(math.abs(plus_adx - minus_adx) / (sum_adx == 0 ? 1 : sum_adx), lensig_adx)
plot(adx_adx, color=#F50057, title="ADX")
plot(plus_adx, color=#2962FF, title="+DI")
plot(minus_adx, color=#FF6D00, title="-DI")
indicator(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
len = input.int(14, minval=1, title="Length",group="RSI setting")
src = input(close, "Source",group="RSI setting")
up = ta.rma(math.max(ta.change(src), 0), len)
down = ta.rma(-math.min(ta.change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")
请帮我解决这个问题。
谢谢和问候。
您已经有一个名为 src
的变量。同一个变量不能声明两次。
将其更改为其他内容(例如 src_rsi
)。
此外,您不能进行两次或多次 indicator()
通话。删除其中一个。
这应该有效:
//@version=5
indicator(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
h2 = hline(70, "Upper Band", color=#787B86)
h3 = hline(60, "Upper Band", color=#787B86)
h4 = hline(50, "Upper Band", color=#787B86)
h5 = hline(40, "Upper Band", color=#787B86)
h6 = hline(30, "Upper Band", color=#787B86)
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")
lensig_adx = input.int(14, title="ADX Smoothing", minval=1, maxval=50,group="ADX setting")
len_adx = input.int(14, minval=1, title="DI Length",group="ADX setting")
up_adx = ta.change(high)
down_adx = -ta.change(low)
plusDM_adx = na(up_adx) ? na : (up_adx > down_adx and up_adx > 0 ? up_adx : 0)
minusDM_adx = na(down_adx) ? na : (down_adx > up_adx and down_adx > 0 ? down_adx : 0)
trur_adx = ta.rma(ta.tr, len_adx)
plus_adx = fixnan(100 * ta.rma(plusDM_adx, len_adx) / trur_adx)
minus_adx = fixnan(100 * ta.rma(minusDM_adx, len_adx) / trur_adx)
sum_adx = plus_adx + minus_adx
adx_adx = 100 * ta.rma(math.abs(plus_adx - minus_adx) / (sum_adx == 0 ? 1 : sum_adx), lensig_adx)
plot(adx_adx, color=#F50057, title="ADX")
plot(plus_adx, color=#2962FF, title="+DI")
plot(minus_adx, color=#FF6D00, title="-DI")
len = input.int(14, minval=1, title="Length",group="RSI setting")
src_rsi = input(close, "Source",group="RSI setting")
up = ta.rma(math.max(ta.change(src_rsi), 0), len)
down = ta.rma(-math.min(ta.change(src_rsi), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")
我试图在交易视图中同时添加随机 RSI、DMI 和 RSI,但遇到以下错误 - “添加到图表操作失败,原因:第 39 行:'src' 已定义。”。 =11=]
我的代码如下-
//@version=5
indicator(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
h2 = hline(70, "Upper Band", color=#787B86)
h3 = hline(60, "Upper Band", color=#787B86)
h4 = hline(50, "Upper Band", color=#787B86)
h5 = hline(40, "Upper Band", color=#787B86)
h6 = hline(30, "Upper Band", color=#787B86)
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")
lensig_adx = input.int(14, title="ADX Smoothing", minval=1, maxval=50,group="ADX setting")
len_adx = input.int(14, minval=1, title="DI Length",group="ADX setting")
up_adx = ta.change(high)
down_adx = -ta.change(low)
plusDM_adx = na(up_adx) ? na : (up_adx > down_adx and up_adx > 0 ? up_adx : 0)
minusDM_adx = na(down_adx) ? na : (down_adx > up_adx and down_adx > 0 ? down_adx : 0)
trur_adx = ta.rma(ta.tr, len_adx)
plus_adx = fixnan(100 * ta.rma(plusDM_adx, len_adx) / trur_adx)
minus_adx = fixnan(100 * ta.rma(minusDM_adx, len_adx) / trur_adx)
sum_adx = plus_adx + minus_adx
adx_adx = 100 * ta.rma(math.abs(plus_adx - minus_adx) / (sum_adx == 0 ? 1 : sum_adx), lensig_adx)
plot(adx_adx, color=#F50057, title="ADX")
plot(plus_adx, color=#2962FF, title="+DI")
plot(minus_adx, color=#FF6D00, title="-DI")
indicator(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
len = input.int(14, minval=1, title="Length",group="RSI setting")
src = input(close, "Source",group="RSI setting")
up = ta.rma(math.max(ta.change(src), 0), len)
down = ta.rma(-math.min(ta.change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")
请帮我解决这个问题。
谢谢和问候。
您已经有一个名为 src
的变量。同一个变量不能声明两次。
将其更改为其他内容(例如 src_rsi
)。
此外,您不能进行两次或多次 indicator()
通话。删除其中一个。
这应该有效:
//@version=5
indicator(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
h2 = hline(70, "Upper Band", color=#787B86)
h3 = hline(60, "Upper Band", color=#787B86)
h4 = hline(50, "Upper Band", color=#787B86)
h5 = hline(40, "Upper Band", color=#787B86)
h6 = hline(30, "Upper Band", color=#787B86)
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")
lensig_adx = input.int(14, title="ADX Smoothing", minval=1, maxval=50,group="ADX setting")
len_adx = input.int(14, minval=1, title="DI Length",group="ADX setting")
up_adx = ta.change(high)
down_adx = -ta.change(low)
plusDM_adx = na(up_adx) ? na : (up_adx > down_adx and up_adx > 0 ? up_adx : 0)
minusDM_adx = na(down_adx) ? na : (down_adx > up_adx and down_adx > 0 ? down_adx : 0)
trur_adx = ta.rma(ta.tr, len_adx)
plus_adx = fixnan(100 * ta.rma(plusDM_adx, len_adx) / trur_adx)
minus_adx = fixnan(100 * ta.rma(minusDM_adx, len_adx) / trur_adx)
sum_adx = plus_adx + minus_adx
adx_adx = 100 * ta.rma(math.abs(plus_adx - minus_adx) / (sum_adx == 0 ? 1 : sum_adx), lensig_adx)
plot(adx_adx, color=#F50057, title="ADX")
plot(plus_adx, color=#2962FF, title="+DI")
plot(minus_adx, color=#FF6D00, title="-DI")
len = input.int(14, minval=1, title="Length",group="RSI setting")
src_rsi = input(close, "Source",group="RSI setting")
up = ta.rma(math.max(ta.change(src_rsi), 0), len)
down = ta.rma(-math.min(ta.change(src_rsi), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")