首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将随机RSI、DMI和RSI相加

将随机RSI、DMI和RSI相加
EN

Stack Overflow用户
提问于 2021-11-23 09:50:43
回答 1查看 111关注 0票数 0

我试图在交易视图中将随机RSI、DMI和RSI添加到一起,但遇到以下错误-“添加到图表操作失败,原因:第39行:'src‘已定义。”

我的代码如下:

代码语言:javascript
复制
//@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")

请帮我解决这个问题。

谢谢&致以问候。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-23 10:23:33

您已经有一个名为src的变量。不能两次声明同一个变量。

将其更改为其他值(例如src_rsi)。

此外,您不能有两个或更多indicator()调用。移除其中一个。

这应该是可行的:

代码语言:javascript
复制
//@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")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70078651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档