添加klu的3种形态识别

This commit is contained in:
jackyu66git
2025-11-01 02:50:44 +08:00
parent 8bb3798a7c
commit 8e21ecb057
8 changed files with 287 additions and 117 deletions
BIN
View File
Binary file not shown.
+1 -48
View File
@@ -352,39 +352,8 @@ def analyze_chan(df, symbol=None, timeframe=None):
# 初始化多时间周期数据以获取EMA52
ema52_dict = None
# 先暂时不用这个功能,太慢了
if symbol and timeframe and False:
try:
# 获取不同时间周期的数据用于初始化
df_1h = get_kl_data(symbol, '1h', limit=1500) if timeframe != '1h' else df
df_1d = get_kl_data(symbol, '1d', limit=2000) if timeframe != '1d' else df
df_1M = get_kl_data(symbol, '1M', limit=1500) if timeframe != '1M' else df
# 添加指标
if df_1h is not None and len(df_1h) > 0:
df_1h = add_indicators(df_1h)
if df_1d is not None and len(df_1d) > 0:
df_1d = add_indicators(df_1d)
if df_1M is not None and len(df_1M) > 0:
df_1M = add_indicators(df_1M)
# 初始化多时间周期数据
chan.init_dataframes(df, df_1h, df_1d, df_1M)
# 获取EMA52数据
ema52_dict = chan.get_ema52_dict()
# 处理NaN值
if ema52_dict:
for key, value in ema52_dict.items():
if pd.isna(value) or value is None:
ema52_dict[key] = None
else:
ema52_dict[key] = float(value)
except Exception as e:
print(f"获取多时间周期EMA52数据失败: {e}")
ema52_dict = None
# 获取分析结果
klu_list = chan.get_kl_data(df)
klc_list = chan.get_klc_list(df)
bi_list = chan.cal_bi_list(klc_list)
#for index in range(0, 10):
@@ -408,8 +377,6 @@ def analyze_chan(df, symbol=None, timeframe=None):
chan_macd = None
chan_macd_data = {}
try:
# 直接使用ChanLun的get_klu_list方法获取KLU列表
klu_list = chan.get_klu_list(df)
if klu_list and len(klu_list) > 0:
print(f"获取到KLU列表,长度: {len(klu_list)}")
@@ -457,20 +424,6 @@ def analyze_chan(df, symbol=None, timeframe=None):
'cross0_down_list': []
}
# 获取原始K线数据用于KLU分型分析
klu_list = []
try:
# 尝试获取KLU数据
if hasattr(chan, 'get_klu_list'):
klu_list = chan.get_klu_list(df)
elif hasattr(chan, 'klu_list'):
klu_list = chan.klu_list
else:
# 如果没有专门的KLU方法,尝试从KLC获取原始K线数据
pass
except Exception as e:
klu_list = []
# 提取K线分型信息
klc_fx_info = []
for klc in klc_list: