gpt4 book ai didi

python - TradingView STC 与任何 python STC

转载 作者:行者123 更新时间:2023-12-05 05:47:35 26 4
gpt4 key购买 nike

我正在尝试在交易策略中使用 STC 指标,但我无法找出它无法正常工作的原因。

我使用的图表是 UTC 上的 BTC/USDT 作为时间范围。

图表时间:UTC 22 年 2 月 1 日 - 16:20

--------------------交易 View :------------------------

STC值:97.66

STC 设置:

enter image description here

---------------- Python:----------------

我试过以下库:

Pandas ta( link ):

dataframe.ta.stc(tclength=12, fast=26, slow=50, factor=0.5, append=True)

技术指标( link )

dataframe['stc_2'] = technical.indicators.stc(dataframe, fast=26, slow=50, length=12)

财务技术分析( link )

dataframe['stc'] = fta.STC(dataframe, period_fast=26, period_slow=50, k_period=12, d_period=3, adjust=True)

我还尝试通过转换来自 here 的 pine 脚本来重新创建指标到 python

def stoch(source, high, low, lenght):
return Series(100 * (source - low[-lenght:].min()) / (high[-lenght:].max() - low[-lenght:].min()))


def fixnan(s: Series):
mask = np.isnan(s)
s[mask] = np.interp(np.flatnonzero(mask), np.flatnonzero(~mask), s[~mask])
return s


def nz(s: Series):
return s.fillna(0)


def stc(ohlc: DataFrame, fast: int, slow: int, length: int, d1: int, d2: int):
macd = ta.EMA(ohlc['close'], timeperiod=fast) - ta.EMA(ohlc['close'], timeperiod=slow)
k = nz(fixnan(stoch(macd, macd, macd, length)))
d = ta.EMA(k, d1)
kd = nz(fixnan(stoch(d, d, d, length)))
stc = ta.EMA(kd, d2)
r1 = np.where(stc >= 100, 100, stc)
r2 = np.where(r1 <= 0, 0, r1)
return r2


dataframe['stc_MINE'] = stc(dataframe, 26, 50, 10, 3, 3)

这是所有这些的输出:

enter image description here

可以看出,它们都不是 97.66,谁能向我解释一下我做错了什么或者我错过了什么?

最佳答案

您可以使用 ta来自 bukosabino 的图书馆。

我能够获得与 TradingView 完全相同的结果。这是用法:

from ta.trend import STCIndicator

stc = STCIndicator(dataframe["close"], window_slow=50, window_fast=26, cycle=12).stc()
dataframe["stc"] = stc

关于python - TradingView STC 与任何 python STC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70979355/

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