添加新的bb2633,笔识别改回去了

This commit is contained in:
jackyu66git
2026-02-24 01:01:19 +08:00
parent 85609d2758
commit 377f23a9ec
6 changed files with 1595 additions and 1726 deletions
+13 -199
View File
@@ -81,6 +81,7 @@ class TF_DF():
bb302 = ta.BBANDS(df, timeperiod=41, nbdevup=2.0, nbdevdn=2.0, matype=0)
bb30 = ta.BBANDS(df, timeperiod=20, nbdevup=2.0, nbdevdn=2.0, matype=0)
bb302 = ta.BBANDS(df, timeperiod=20, nbdevup=2.0, nbdevdn=2.0, matype=0)
bb2633 = ta.BBANDS(df, timeperiod=26, nbdevup=3.0, nbdevdn=3.0, matype=0)
# 计算布林带中轨(移动平均线)
bb30_middle = ta.SMA(df, timeperiod=90)
@@ -90,6 +91,11 @@ class TF_DF():
bbp120 = (df['close'] - bb120['lowerband']) / (bb120['upperband'] - bb120['lowerband'])
bbp30 = (df['close'] - bb30['lowerband']) / (bb30['upperband'] - bb30['lowerband'])
bbp302 = (df['close'] - bb302['lowerband']) / (bb302['upperband'] - bb302['lowerband'])
bbp2633 = (df['close'] - bb2633['lowerband']) / (bb2633['upperband'] - bb2633['lowerband'])
df['bb2633upper'] = bb2633['upperband']
df['bb2633lower'] = bb2633['lowerband']
df['bbp2633'] = bbp2633
df['bb2633middle'] = bb2633['middleband']
df['atr'] = ta.ATR(df, timeperiod=14)
df['bbup365'] = bb365['upperband']
df['bblow365'] = bb365['lowerband']
@@ -114,6 +120,7 @@ class TF_DF():
df['ema104'] = ta.EMA(df, timeperiod=104)
df['ema156'] = ta.EMA(df, timeperiod=156)
df['ema208'] = ta.EMA(df, timeperiod=208)
df['ema26'] = ta.EMA(df, timeperiod=26)
df['rsi'] = ta.RSI(df, timeperiod=14)
df['volume_ratio'] = self.cal_volume_ratio(df)
return df
@@ -872,11 +879,11 @@ class TF_DF():
last_bottom = None
for klc in klc_list:
fx = self.check_fx(klc)
if fx == Chan_FX_TYPE.TOP and False:
if fx == Chan_FX_TYPE.TOP:
if last_bottom:
if self.check_top_fx(last_bottom, klc) == False:
fx = Chan_FX_TYPE.UNKNOWN
if fx == Chan_FX_TYPE.BOTTOM and False:
if fx == Chan_FX_TYPE.BOTTOM:
if last_top:
if self.check_bottom_fx(last_top, klc) == False:
#print(klc.end_time, last_top.end_time, "---")
@@ -1198,200 +1205,6 @@ class TF_DF():
return False
return True
def check_fx_chanlun(self, klc):
"""标准缠论分型:仅用高低点,不用 MACD,不要求整根 K 线包在左右内。"""
if klc.pre is None or klc.next is None:
return Chan_FX_TYPE.UNKNOWN
# 顶分型:中间 K 线高点最高
if klc.high > klc.pre.high and klc.high > klc.next.high:
klc.set_fx(Chan_FX_TYPE.TOP)
return Chan_FX_TYPE.TOP
# 底分型:中间 K 线低点最低
if klc.low < klc.pre.low and klc.low < klc.next.low:
klc.set_fx(Chan_FX_TYPE.BOTTOM)
return Chan_FX_TYPE.BOTTOM
return Chan_FX_TYPE.UNKNOWN
def cal_bi_list_chanlun(self, klc_list):
"""
与 cal_bi_list 逻辑完全一致,仅分型用 check_fx_chanlun(标准缠论分型,不看 MACD)。
"""
bi_list = []
last_top = None
last_bottom = None
for klc in klc_list:
fx = self.check_fx_chanlun(klc)
if fx == Chan_FX_TYPE.TOP:
if last_bottom:
if self.check_top_fx(last_bottom, klc) == False:
fx = Chan_FX_TYPE.UNKNOWN
if fx == Chan_FX_TYPE.BOTTOM:
if last_top:
if self.check_bottom_fx(last_top, klc) == False:
fx = Chan_FX_TYPE.UNKNOWN
if fx == Chan_FX_TYPE.UNKNOWN:
if len(bi_list) > 0:
bi_list[-1].add_klc(klc)
continue
if len(bi_list) > 0 and klc.end_klu:
last_bi = bi_list[-1]
if last_top and last_bi.dir == Chan_BI_DIR.DOWN:
if last_bottom and klc.high > last_bi.high:
last_bi.set_end_klc(last_bottom, klc)
bi = ChanBI(last_bottom, len(bi_list), Chan_BI_DIR.UP)
last_bi.set_next(bi)
bi.set_pre(last_bi)
for klc_index in range(last_bi.end_klc.index, len(klc_list)):
bi.add_klc(klc_list[klc_index])
bi_list.append(bi)
last_top = klc
klc.set_bi(bi)
else:
if last_bottom and last_bi.dir == Chan_BI_DIR.UP:
if last_top and klc.low < last_bi.low:
last_bi.set_end_klc(last_top, klc)
bi = ChanBI(last_top, len(bi_list), Chan_BI_DIR.DOWN)
last_bi.set_next(bi)
bi.set_pre(last_bi)
for klc_index in range(last_bi.end_klc.index, len(klc_list)):
bi.add_klc(klc_list[klc_index])
bi_list.append(bi)
last_bottom = klc
klc.set_bi(bi)
else:
if fx == Chan_FX_TYPE.TOP:
if last_top:
if last_bottom:
if last_bottom.index < last_top.index:
if last_top.high > klc.high:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
last_top = klc
klc.set_klc_fx_type(Chan_KLC_FX.TOP1)
self.check_fx_pattern(klc)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_bottom.index + 4 > klc.index:
if last_top.high > klc.high:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_top.index + 4 < klc.index and len(bi_list) > 1:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
klc.set_fx(Chan_FX_TYPE.PTOP)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
last_bi = bi_list[-1]
if not last_bi.is_sure:
last_bi.set_end_klc(last_bottom, klc)
bi = ChanBI(last_bottom, len(bi_list), Chan_BI_DIR.UP)
last_bi.set_next(bi)
bi.set_pre(last_bi)
bi.add_klc(klc)
bi_list.append(bi)
last_top = klc
klc.set_klc_fx_type(Chan_KLC_FX.TOP2)
self.check_fx_pattern(klc)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_top.high < klc.high:
last_bi = bi_list[-1]
last_bi.set_start_klc(klc, Chan_BI_DIR.DOWN)
last_top = klc
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
klc.set_fx(Chan_FX_TYPE.TT)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_bottom:
if last_bottom.index + 4 > klc.index:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
last_top = klc
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
last_top = klc
bi = ChanBI(klc, len(bi_list), Chan_BI_DIR.DOWN)
bi_list.append(bi)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_bottom:
if last_top:
if last_top.index < last_bottom.index:
if last_bottom.low < klc.low:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
last_bottom = klc
klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM1)
self.check_fx_pattern(klc)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_top.index + 4 > klc.index:
if last_bottom.low < klc.low:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_bottom.index + 4 < klc.index and len(bi_list) > 1:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
last_bi = bi_list[-1]
if not last_bi.is_sure:
last_bi.set_end_klc(last_top, klc)
bi = ChanBI(last_top, len(bi_list), Chan_BI_DIR.DOWN)
last_bi.set_next(bi)
bi.set_pre(last_bi)
bi.add_klc(klc)
bi_list.append(bi)
last_bottom = klc
klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM2)
self.check_fx_pattern(klc)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_bottom.low > klc.low:
last_bi = bi_list[-1]
last_bi.set_start_klc(klc, Chan_BI_DIR.UP)
last_bottom = klc
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
klc.set_fx(Chan_FX_TYPE.BB)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
if last_top:
if last_top.index + 4 > klc.index:
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
last_bottom = klc
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
else:
last_bottom = klc
bi = ChanBI(klc, len(bi_list), Chan_BI_DIR.UP)
bi_list.append(bi)
bi_list[-1].add_klc(klc)
klc.set_bi(bi_list[-1])
return bi_list
def cal_bi_zs(self, seg_list):
bi_zs_list = []
for seg in seg_list:
@@ -1453,7 +1266,7 @@ class TF_DF():
Chan_BSP_DIR.SELL,
leave_bi.sure_time,
zs.index+1, zs, None
)
)
leave_bi.end_klc.set_bsp_type(Chan_BSP_TYPE.S1)
bsp_list.append(bsp)
# 回拉笔
@@ -1496,7 +1309,7 @@ class TF_DF():
Chan_BSP_DIR.BUY,
leave_bi.sure_time,
zs.index+1, zs, None
)
)
leave_bi.end_klc.set_bsp_type(Chan_BSP_TYPE.B1)
bsp_list.append(bsp)
# 反弹笔
@@ -1713,7 +1526,8 @@ class TF_DF():
bsp_list.append(bsp)
return bsp_list
def calculate_zs(self, bi_list, seg_list):
return self.get_zs_list(bi_list, seg_list)
def get_zs_list(self, bi_list, seg_list):
zs_list = []
bsp_list = []