通过脚本将 EMA 放入 RSI 指标中,而不是通过添加指标函数?

Put EMA in RSI indicator by script, not by add-indicator function?

我喜欢用 EMA 中的 RSI 编写脚本。 这两个简单的脚本都在为自己工作。但总的来说,我在 EMA 的源头上失败了。

//@version=4
study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")

//RSI
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)
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, "RSI", color=#8E1599)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

//EMA55
lenE55 = input(55, minval=1, title="Length EMA55")
srcE55 = input(<I want 'rsi' instead of 'close' here>, title="Source EMA55")
outE55 = ema(srcE55, lenE55)
plot(outE55, title="EMA55", color=#ffff00, linewidth=2, transp=13)

如果我只使用图表中的 RSI 脚本并选择“在 RSI 上添加 Indicator/Strategy ...”,我可以选择我的 EMA 指标(如脚本部分 //EMA55)。 在设置中,将在“Source EMA55”下的“Inputs”选项卡中出现,而不是(仅)典型的“close”。现在有“RSI”(简称)——您还可以选择图表中的所有其他指标作为源和开盘价、最高价、最低价等!

如何在我的脚本中实现它? 如果我尝试替换

中的“关闭”
srcE55 = input(close, title="Source EMA55"

用“rsi”——甚至用“RSI”——这没有意义,因为我现在在脚本中——我最终会出错。 我不明白如何使用 RSI 部分作为 EMA 部分的基础源。

我不在乎是否必须为另一个指标使用添加函数,但我的目标是能够使用填充函数或设计我的默认指标集,而无需在以后为我的最终结果添加其他指标.

不要惊慌,逻辑思维,你的建议中有答案:

srcE55 = input(<I want 'rsi' instead of 'close' here>, title="Source EMA55")

只需将 EMA 来源 close 更改为您的 rsi 来源。

//@version=4
study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")

//RSI
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)
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, "RSI", color=#8E1599)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

//EMA55
lenE55 = input(55, minval=1, title="Length EMA55")
srcE55 = rsi //use rsi as source instead of close
outE55 = ema(srcE55, lenE55) //just change the `close` source with `rsi` source
plot(outE55, title="EMA55", color=#ffff00, linewidth=2, transp=13)