添加ema52显示
This commit is contained in:
+45
-9
@@ -346,10 +346,43 @@ def calculate_macd(df):
|
||||
'histogram': histogram.tolist()
|
||||
}
|
||||
|
||||
def analyze_chan(df):
|
||||
def analyze_chan(df, symbol=None, timeframe=None):
|
||||
"""进行缠论分析"""
|
||||
chan = ChanLun()
|
||||
|
||||
# 初始化多时间周期数据以获取EMA52
|
||||
ema52_dict = None
|
||||
if symbol and timeframe:
|
||||
try:
|
||||
# 获取不同时间周期的数据用于初始化
|
||||
df_1h = get_kl_data(symbol, '1h', limit=800) if timeframe != '1h' else df
|
||||
df_1d = get_kl_data(symbol, '1d', limit=800) if timeframe != '1d' else df
|
||||
df_1M = get_kl_data(symbol, '1M', limit=800) 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
|
||||
|
||||
# 获取分析结果
|
||||
klc_list = chan.get_klc_list(df)
|
||||
bi_list = chan.cal_bi_list(klc_list)
|
||||
@@ -546,7 +579,8 @@ def analyze_chan(df):
|
||||
'trade_points': buy_sell_points,
|
||||
'klc_fx_info': klc_fx_info, # KLC分型信息
|
||||
'klu_fx_info': klu_fx_info, # 添加KLU分型信息
|
||||
'chan_macd': chan_macd_data # 添加ChanMACD分析数据
|
||||
'chan_macd': chan_macd_data, # 添加ChanMACD分析数据
|
||||
'ema52_dict': ema52_dict # 添加多时间周期EMA52数据
|
||||
}
|
||||
|
||||
def generate_replay_data(df, client_tz, symbol=None, element_timeframe=None, start_time=None, end_time=None):
|
||||
@@ -572,7 +606,7 @@ def generate_replay_data(df, client_tz, symbol=None, element_timeframe=None, sta
|
||||
current_df = add_indicators(current_df)
|
||||
|
||||
# 进行缠论分析
|
||||
analysis_result = analyze_chan(current_df)
|
||||
analysis_result = analyze_chan(current_df, symbol, timeframe)
|
||||
|
||||
# 计算MACD
|
||||
macd_data = calculate_macd(current_df)
|
||||
@@ -590,7 +624,7 @@ def generate_replay_data(df, client_tz, symbol=None, element_timeframe=None, sta
|
||||
if len(element_current_df) > 0:
|
||||
# 重新对当前时间范围的次周期数据进行缠论分析
|
||||
# 这样可以确保数据的准确性,避免时间筛选的复杂性
|
||||
element_current_analysis = analyze_chan(element_current_df)
|
||||
element_current_analysis = analyze_chan(element_current_df, symbol, element_timeframe)
|
||||
|
||||
# 直接使用分析结果,无需复杂的时间筛选
|
||||
filtered_bi_list = element_current_analysis['bi_list']
|
||||
@@ -1614,7 +1648,7 @@ def analyze():
|
||||
df = add_indicators(df)
|
||||
|
||||
# 进行缠论分析
|
||||
analysis_result = analyze_chan(df)
|
||||
analysis_result = analyze_chan(df, symbol, timeframe)
|
||||
|
||||
# 计算MACD
|
||||
macd_data = calculate_macd(df)
|
||||
@@ -1717,7 +1751,9 @@ def analyze():
|
||||
'fx_confirmed': bool(point['fx_confirmed']) # 分型是否确认
|
||||
} for point in analysis_result['klu_fx_info']],
|
||||
# 添加ChanMACD分析数据
|
||||
'chan_macd': serialize_chan_macd_data(analysis_result.get('chan_macd', {}), client_tz)
|
||||
'chan_macd': serialize_chan_macd_data(analysis_result.get('chan_macd', {}), client_tz),
|
||||
# 添加多时间周期EMA52数据
|
||||
'ema52_dict': analysis_result.get('ema52_dict', {})
|
||||
})
|
||||
|
||||
# 如果生成了回放数据,添加到返回结果中
|
||||
@@ -1734,7 +1770,7 @@ def analyze():
|
||||
element_df = add_indicators(element_df)
|
||||
|
||||
# 对小周期数据进行缠论分析
|
||||
element_analysis = analyze_chan(element_df)
|
||||
element_analysis = analyze_chan(element_df, symbol, element_timeframe)
|
||||
|
||||
# 计算小周期MACD数据
|
||||
element_macd_data = calculate_macd(element_df)
|
||||
@@ -1936,7 +1972,7 @@ def test_element_data():
|
||||
|
||||
# 分析次周期数据
|
||||
element_df = add_indicators(element_df)
|
||||
element_analysis = analyze_chan(element_df)
|
||||
element_analysis = analyze_chan(element_df, symbol, element_timeframe)
|
||||
|
||||
return jsonify({
|
||||
'main_data_count': len(main_df),
|
||||
@@ -2123,7 +2159,7 @@ def filter_stocks():
|
||||
continue
|
||||
|
||||
# 进行缠论分析
|
||||
analysis_result = analyze_chan(df)
|
||||
analysis_result = analyze_chan(df, symbol, timeframe)
|
||||
|
||||
if not analysis_result or 'klc_fx_info' not in analysis_result:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user