我有一个pine脚本,我正在尝试将其转换为python。
然而,pine脚本允许RSI有两个系列作为输入,而不是传统的系列和周期。
我的问题是这是如何实现的,我在他们的文档中尝试了实现,但它不计入第二个系列:
pine_rsi(x, y) =>
u = max(x - x[1], 0) // upward change
d = max(x[1] - x, 0) // downward change
rs = rma(u, y) / rma(d, y)
res = 100 - 100 / (1 + rs)
res谢谢,
发布于 2018-08-20 01:26:02
我不是Python或任何方面的专家,但我认为您正在尝试除以零。
RSI的方程式为:
RSI= 100 - { 100 \ (1+RS) }哪里
RS = SMMA(U,n) / SMMA(D,n)你的等式中的逻辑似乎没有考虑到这样一个事实,即如果向下的rma等于零,则RS的分母将为零。每当价格连续14个周期下降时,或无论RSI的周期是什么,就会出现这种情况。
pine编辑器脚本通过在出现上述情况时将RSI设置为100来解决此问题。
在下面的第6行上:只要向下rma项等于0,RSI就被切换到100。这一行的第二部分仅在代码不会被零除时执行。
1 //@version=3
2 study(title="Relative Strength Index", shorttitle="RSI")
3 src = close, len = input(14, minval=1, title="Length")
4 up = rma(max(change(src), 0), len)
5 down = rma(-min(change(src), 0), len)
6 rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
7 plot(rsi, color=purple)
8 band1 = hline(70)
9 band0 = hline(30)
10 fill(band1, band0, color=purple, transp=90)发布于 2020-01-06 00:58:38
从pine脚本文档:
rsi(x,y)
“如果x是序列,y是整数,那么x是源序列,y是长度。
“如果x是级数,y是级数,那么x和y被认为是向上和向下变化的2个计算MAs。”
因此,如果你同时有向上和向下的变化序列,rsi将像这样工作:
u = ["your upward changes series"]
d = ["your downward changes series"]
rsi = 100 - 100 / (1 + u / d) //No need for a period value发布于 2019-04-30 20:50:31
在Pine脚本中确实存在“第二系列”这样的东西。从文档中:
rsi(x,y)
"If x is a series and y is integer then x is a source series and y is a length.
If x is a series and y is a series then x and y are considered to be 2 calculated MAs for upward and downward changes"然而,它没有解释目的是什么,因为没有长度输入到rsi()函数- Pine应该对数据做什么?
像OP一样,我也想知道2系列作为输入的目的,移植到python。这个问题还没有得到回答。
https://stackoverflow.com/questions/50310872
复制相似问题