未检测到TaLib锤模式

2024-04-29 19:32:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从事一个自动化项目,用于检测趋势。这将是一个集合模型,使用多个不同的输入,其中一个输入是检测烛台模式(将使用已知模式) 首先作为输入,最终只是为了对嵌入层进行健全性检查(嵌入层应自动识别此类模式)。 当我环顾四周时,我发现了一个库,它应该能够检测像锤子一样的烛台图案。当我测试它的时候,我发现了一些在我看来不正确的结果

import re
import numpy as np
import talib
import plotly.graph_objects as go
import plotly.io as pio
data = np.load('usd-bitcoin.npy')
open_ = data[1, -10:].astype(float)
high_ = data[2, -10:].astype(float)
low_ = data[3, -10:].astype(float)
close_ = data[4, -10:].astype(float)

pio.renderers.default = "png"
fig = go.Figure(data=[go.Candlestick(x=data[0, -10:],
                                     open=open_,
                                     high=high_,
                                     low=low_,
                                     close=close_)])
fig.write_image("plots/fig1.png")

cdls = re.findall('(CDL\w*)', ' '.join(dir(talib)))
for cdl in cdls:
    toExec = getattr(talib, cdl)
    out    = toExec(open_, high_, low_, close_)
    print(str(out) + ' ' + cdl)

正如您在下图中所看到的,数据和烛台图似乎显示了两个锤形图案,一个是从起点到终点的3个位置,另一个是从终点到终点的3个位置。然而,程序的输出显示没有检测到锤子,这是按照预期工作还是我应该以某种方式预处理数据

[0 0 0 0 0 0 0 0 0 0] CDLHAMMER

DataCandleStick Plot


Tags: importgoclosedataas模式openfloat
1条回答
网友
1楼 · 发布于 2024-04-29 19:32:34

from CDL Hammer Documentation

https://sourceforge.net/p/ta-lib/code/HEAD/tree/trunk/ta-lib/c/src/ta_func/ta_CDLHAMMER.c#l236

所以你测试的应该是倒置的锤子而不是锤子

/*继续计算请求的范围

* Must have:
* - small real body
* - long upper shadow
* - no, or very short, lower shadow
* - gap down
* The meaning of "short", "very short" and "long" is specified with TA_SetCandleSettings;
* outInteger is positive (1 to 100): inverted hammer is always bullish;
* the user should consider that an inverted hammer must appear in a downtrend, while this function does not consider it

https://sourceforge.net/p/ta-lib/code/HEAD/tree/trunk/ta-lib/c/src/ta_func/ta_CDLINVERTEDHAMMER.c

相关问题 更多 >