gpt4 book ai didi

python - 如何在 Python 中实现 RSI Divergence

转载 作者:行者123 更新时间:2023-12-04 11:27:51 24 4
gpt4 key购买 nike

我想知道是否有任何涵盖 RSI-Divergence 的 Python 库(快速和慢速之间的差异 RSI )或有关如何在 Python 中实现其算法的任何指导。
已提问:Programmatically detect RSI divergence .答案之一暗示quantconnect forum对于 Python 版本,但它不涵盖任何内容。
我找不到它的数学公式,但我找到了 RSI-Divergence in pine-script ,如下所示,但我无法将其转换为 Python,因为它无法调试 pine-script使用 tradingview .

study(title="RSI Divergence", shorttitle="RSI Divergence")
src_fast = close, len_fast = input(5, minval=1, title="Length Fast RSI")
src_slow = close, len_slow = input(14,minval=1, title="Length Slow RSI")
up_fast = rma(max(change(src_fast), 0), len_fast)
down_fast = rma(-min(change(src_fast), 0), len_fast)
rsi_fast = down_fast == 0 ? 100 : up_fast == 0 ? 0 : 100 - (100 / (1 + up_fast / down_fast))
up_slow = rma(max(change(src_slow), 0), len_slow)
down_slow = rma(-min(change(src_slow), 0), len_slow)
rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - (100 / (1 + up_slow / down_slow))
divergence = rsi_fast - rsi_slow
plotdiv = plot(divergence, color = divergence > 0 ? lime:red, linewidth = 2)
band = hline(0)

最佳答案

我稍微更改了上面的代码,希望这会有所帮助:

lower_barrier = 30
upper_barrier = 70
width = 5
#Bullish Divergence
for i in range(len(Data)):

try:
if Data.iloc[i, 4] < lower_barrier:
for a in range(i + 1, i + width):
if Data.iloc[a, 4] > lower_barrier:
for r in range(a + 1, a + width):
if Data.iloc[r, 4] < lower_barrier and Data.iloc[r, 4] > Data.iloc[i, 4] and Data.iloc[r, 3] < Data.iloc[i, 3]:
for s in range(r + 1, r + width):
if Data.iloc[s, 4] > lower_barrier:
print('Bullish above',Data.iloc[s+1,1])
Data.iloc[s + 1, 5] = 1
break
else:
continue
else:
continue
else:
continue
else:
continue
except IndexError:
pass
#Bearish Divergence
for i in range(len(Data)):
try:
if Data.iloc[i, 4] > upper_barrier:
for a in range(i + 1, i + width):
if Data.iloc[a, 4] < upper_barrier:
for r in range(a + 1, a + width):
if Data.iloc[r, 4] > upper_barrier and Data.iloc[r, 4] < Data.iloc[i, 4] and Data.iloc[r, 3] > Data.iloc[i, 3]:
for s in range(r + 1, r + width):
if Data.iloc[s, 4] < upper_barrier:
print('Bearish below',Data.iloc[s+1,2])
Data.iloc[s + 1, 6] = -1
break
else:
continue
else:
continue
else:
continue
else:
continue
except IndexError:
pass

关于python - 如何在 Python 中实现 RSI Divergence,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65666858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com