diff --git a/ChanPY.py b/ChanPY.py index bc67e45..802f0ad 100644 --- a/ChanPY.py +++ b/ChanPY.py @@ -287,7 +287,36 @@ class ChanPY(): #for zs in kl_datas.zs_list: #print(zs.begin.time, zs.end.time) return bsps, updown, bi_sure + def get_bsp_state(self, dataframe:DataFrame): + fields = "time,open,high,low,close,volume" + bsps = [] + if self.chanIn: + kl_data = self.get_kl_data(dataframe) + self.chan.trigger_load({self.k_type: kl_data}) + bsp_list = self.chan.get_bsp() + bsp_index = 0 + for klu in kl_data: + if bsp_index >= len(bsp_list): + bsp_index = len(bsp_list) - 1 + bsp = bsp_list[bsp_index] + if klu.idx == bsp.klu.idx: + bsp_type = self.get_bsp_type(bsp.type[0], bsp.is_buy) + if abs(bsp_type) == 1 or abs(bsp_type) == 2: + bsps.append(1) + else: + bsps.append(0) + bsp_index = bsp_index + 1 + else: + bsps.append(0) + self.chanIn = False + else: + klu = CKLine_Unit(self.create_item_dict(self.get_last_item_data(dataframe), GetColumnNameFromFieldList(fields)), autofix=True) + if self.last_kline.time < klu.time: + self.chan.trigger_load({self.k_type: [klu]}) # 喂给CChan新增k线 + self.last_kline = klu + return bsps + def get_bsp_state1(self, dataframe:DataFrame): fields = "time,open,high,low,close,volume" bsps = [] if self.chanIn: diff --git a/strategies/ChanLun_BTC_30.py b/strategies/ChanLun_BTC_30.py index 2cf2818..3a7d185 100644 --- a/strategies/ChanLun_BTC_30.py +++ b/strategies/ChanLun_BTC_30.py @@ -242,7 +242,7 @@ class ChanLun_BTC_30(IStrategy): #(dataframe['state'] == "-30") (dataframe[state_str].shift(shift_time) > strength) & (dataframe[fx_str].shift(shift_time) == -1) & - (dataframe[chanpy_state_str].shift(shift_time+10) == 1) + (dataframe[chanpy_state_str].shift(shift_time+30) == 1) #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10") & #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time30)] == "-10") & #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10") @@ -254,7 +254,7 @@ class ChanLun_BTC_30(IStrategy): #(dataframe['state'] == "-30") (dataframe[state_str].shift(shift_time) > strength) & (dataframe[fx_str].shift(shift_time) == 1) & - (dataframe[chanpy_state_str].shift(shift_time+10) == -1) + (dataframe[chanpy_state_str].shift(shift_time+30) == -1) #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10") & #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time30)] == "-10") & #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10") @@ -273,7 +273,7 @@ class ChanLun_BTC_30(IStrategy): #(dataframe['state']== "30") (dataframe[state_str].shift(shift_time) > strength) & (dataframe[fx_str].shift(shift_time) == 1) & - (dataframe[chanpy_state_str].shift(shift_time+10) == -1) + (dataframe[chanpy_state_str].shift(shift_time+30) == -1) #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time30)] == "10") & #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time60)] == "10") ), @@ -283,7 +283,7 @@ class ChanLun_BTC_30(IStrategy): #(dataframe['state']== "30") (dataframe[state_str].shift(shift_time) > strength) & (dataframe[fx_str].shift(shift_time) == -1) & - (dataframe[chanpy_state_str].shift(shift_time+10) == 1) + (dataframe[chanpy_state_str].shift(shift_time+30) == 1) #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time30)] == "10") & #(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time60)] == "10") ), diff --git a/web/app.py b/web/app.py index 1697060..32a4816 100644 --- a/web/app.py +++ b/web/app.py @@ -43,12 +43,17 @@ china_stock = ChinaStockData() # 时间周期映射 TIMEFRAMES = { '1m': '1分钟', + '3m': '3分钟', '5m': '5分钟', '15m': '15分钟', '30m': '30分钟', '1h': '1小时', + '2h': '2小时', '4h': '4小时', + '8h': '8小时', + '12h': '12小时', '1d': '日线', + '3d': '3日线', '1w': '周线', '1M': '月线', } @@ -355,7 +360,7 @@ def analyze_chan(df): # 统一使用cal_fx_strength函数 if hasattr(klc, 'cal_fx_strength'): - fx_strength = klc.cal_fx_strength() + fx_strength = klc.cal_fx_strength(5) # 尝试获取分型强度等级 if hasattr(klc, 'get_fx_strength_level'): @@ -644,19 +649,19 @@ def generate_replay_data(df, client_tz, symbol=None, element_timeframe=None, sta 'price': float(point['price']), 'fx_type': point['fx_type'], 'is_bottom': bool(point['is_bottom']), - 'fx_strength': float(point['fx_strength']), - 'fx_strength_level': str(point['fx_strength_level']), - 'is_strong_fx': bool(point['is_strong_fx']) + 'fx_strength': float(point['fx_strength']), # 分型强度分数 + 'fx_strength_level': str(point['fx_strength_level']), # 分型强度等级 + 'is_strong_fx': bool(point['is_strong_fx']) # 是否为强分型 } for point in analysis_result['klc_fx_info']], 'klu_fx_info': [{ 'time': format_time_safely(point['time'], client_tz), 'price': float(point['price']), 'fx_type': point['fx_type'], 'is_bottom': bool(point['is_bottom']), - 'fx_strength': float(point['fx_strength']), - 'fx_strength_level': str(point['fx_strength_level']), - 'is_strong_fx': bool(point['is_strong_fx']), - 'fx_confirmed': bool(point['fx_confirmed']) + 'fx_strength': float(point['fx_strength']), # 分型强度分数 + 'fx_strength_level': str(point['fx_strength_level']), # 分型强度等级 + 'is_strong_fx': bool(point['is_strong_fx']), # 是否为强分型 + 'fx_confirmed': bool(point['fx_confirmed']) # 分型是否确认 } for point in analysis_result['klu_fx_info']] } @@ -821,7 +826,7 @@ def identify_fx_warning_points(bi_list): fx_strength = 0 if hasattr(bi.end_klc, 'cal_fx_strength'): try: - fx_strength = bi.end_klc.cal_fx_strength() + fx_strength = bi.end_klc.cal_fx_strength(5) except: fx_strength = 0 diff --git a/web/templates/index.html b/web/templates/index.html index ebe76fc..9230ee8 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -3250,7 +3250,7 @@ // 构建显示文本,包含分型类型和强度信息 let displayText = `${fx.fx_strength.toFixed(1)}`; - if (fx.fx_strength < 2.2) { // 降低阈值,让更多分型显示 + if (fx.fx_strength < 1.0) { // 降低阈值,让更多分型显示 displayText = fx.fx_strength >= 0.8 ? '' : '' // 0.8以上显示点,0.8以下不显示文本 }