添加识别中继分型
This commit is contained in:
@@ -122,6 +122,8 @@ class TF_DF():
|
||||
df['ema156'] = ta.EMA(df, timeperiod=156)
|
||||
df['ema208'] = ta.EMA(df, timeperiod=208)
|
||||
df['ema26'] = ta.EMA(df, timeperiod=26)
|
||||
df['ema13'] = ta.EMA(df, timeperiod=13)
|
||||
df['ema7'] = ta.EMA(df, timeperiod=7)
|
||||
df['rsi'] = ta.RSI(df, timeperiod=14)
|
||||
df['volume_ratio'] = self.cal_volume_ratio(df)
|
||||
return df
|
||||
@@ -1001,7 +1003,7 @@ class TF_DF():
|
||||
# 不满足结合律的分型
|
||||
else:
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.TOP0)
|
||||
print(klc.end_time, klc.klc_fx_type)
|
||||
#print(klc.end_time, klc.klc_fx_type)
|
||||
if last_bottom.index + bi_klc_min > klc.index:
|
||||
if last_top.high > klc.high:
|
||||
#print(klc.start_time, klc.fx, "二类卖点Sell 1")
|
||||
@@ -1213,331 +1215,29 @@ class TF_DF():
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Bottom Change 5")
|
||||
#print(klc.start_time, klc.fx, "笔买点Buy 4")
|
||||
self.get_above_zero_bsp(klc_list)
|
||||
return bi_list
|
||||
def cal_bi_list1(self, klc_list):
|
||||
bi_list = []
|
||||
last_top = None
|
||||
last_bottom = None
|
||||
def get_above_zero_bsp(self, klc_list):
|
||||
buy_bsp_list = []
|
||||
sell_bsp_list = []
|
||||
above_zero = False
|
||||
buy_bsp = None
|
||||
sell_bsp = None
|
||||
for klc in klc_list:
|
||||
fx = self.check_fx(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:
|
||||
#print(klc.end_time, last_top.end_time, "---")
|
||||
fx = Chan_FX_TYPE.UNKNOWN
|
||||
# Do nothing
|
||||
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]
|
||||
#print(klc.start_time, last_bi.start_time, last_bi.end_time, last_bi.dir, last_bi.high, last_bi.low, last_bottom.end_time, "last bi")
|
||||
if last_top and last_bi.dir == Chan_BI_DIR.DOWN:
|
||||
print("fx=unknown, 1")
|
||||
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)
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM7)
|
||||
#klc.bb_out = True
|
||||
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)
|
||||
#print(klc.start_time, bi.start_time, bi.end_time, bi.dir, bi.high, bi.low, bi.is_sure)
|
||||
else:
|
||||
print("fx=unknown, 2")
|
||||
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)
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.TOP6)
|
||||
#klc.bb_out = True
|
||||
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)
|
||||
#print(klc.start_time, bi.start_time, bi.end_time, bi.dir, bi.high, bi.low, bi.is_sure)
|
||||
else:
|
||||
if fx == Chan_FX_TYPE.TOP:
|
||||
if last_top:
|
||||
if last_bottom:
|
||||
#print(klc.start_time, last_bottom.start_time, last_top.start_time)
|
||||
if last_bottom.index < last_top.index:
|
||||
# Second top lower to be second sell point
|
||||
if last_top.high > klc.high:
|
||||
#klc.set_fx(Chan_FX_TYPE.TT)
|
||||
#klc.set_state("20")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#klc.cal_invisible()
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.TOP3)
|
||||
#print(klc.start_time, klc.fx, "二类卖点Sell 1")
|
||||
else:
|
||||
# A new top found
|
||||
#last_top.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||
last_top = klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Change 1")
|
||||
klc.set_klc_fx_type(Chan_KLC_FX.TOP1)
|
||||
self.check_fx_pattern(klc)
|
||||
#print(klc.end_time, klc.fx, "一类卖点Sell 1")
|
||||
#klc.set_fx(fx)
|
||||
#klc.set_state("10")
|
||||
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:
|
||||
#print(klc.start_time, klc.fx, "二类卖点Sell 1")
|
||||
#klc.set_fx(Chan_FX_TYPE.PTOP)
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
# New TOP Found replace last top
|
||||
else:
|
||||
if last_top.index + 4 < klc.index and len(bi_list) > 1:
|
||||
pre_last_bi = bi_list[-2]
|
||||
last_bi = bi_list[-1]
|
||||
if pre_last_bi.is_sure and not last_bi.is_sure and pre_last_bi.dir == Chan_BI_DIR.UP and False:
|
||||
pre_last_bi.update_bi(klc)
|
||||
bi_list.remove(last_bi)
|
||||
pre_last_bi.set_next(None)
|
||||
#last_top.set_fx(Chan_FX_TYPE.PTOP)
|
||||
last_top = klc
|
||||
last_bottom = pre_last_bi.start_klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Bottom Change 1")
|
||||
klc.set_klc_fx_type(Chan_KLC_FX.TOP2)
|
||||
#print(klc.start_time, last_bi.start_klc.start_time, "New TOP Found reset last bi")
|
||||
#klc.set_state("10")
|
||||
#print(klc.start_time, klc.fx, "笔卖点Sell 1")
|
||||
###klc.set_klc_fx_type(Chan_KLC_FX.TOP2) # when bi is down but the fx is top
|
||||
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])
|
||||
#print(klc.start_time, klc.fx, "无效分型")
|
||||
# 满足结合律
|
||||
else:
|
||||
# New Temp TOP and last bottom confirmed ***** confirm last down bi(last bottom and last top)
|
||||
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)
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM7)
|
||||
#klc.bb_out = True
|
||||
last_bi.set_next(bi)
|
||||
bi.set_pre(last_bi)
|
||||
bi.add_klc(klc)
|
||||
bi_list.append(bi)
|
||||
last_top = klc
|
||||
#print(klc.end_time, klc.fx, bi_list[-1].dir, "Last Top Change 2")
|
||||
klc.set_klc_fx_type(Chan_KLC_FX.TOP2)
|
||||
self.check_fx_pattern(klc)
|
||||
#klc.set_state('30')
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, last_bottom.start_time, "Normal TOP Found, Confirm down bi 4")
|
||||
#print(klc.start_time, klc.fx, "笔卖点Sell 2")
|
||||
# last bottom = None
|
||||
else:
|
||||
if last_top.high < klc.high:
|
||||
last_bi = bi_list[-1]
|
||||
last_bi.set_start_klc(klc, Chan_BI_DIR.DOWN)
|
||||
#last_top.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||
last_top = klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Change 3")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, "笔卖点Sell 3")
|
||||
else:
|
||||
klc.set_fx(Chan_FX_TYPE.TT)
|
||||
#klc.set_state('20')
|
||||
#print(klc.start_time, klc.fx, "二类卖点Sell 2")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
else:
|
||||
if last_bottom:
|
||||
# 不满足结合律的分型
|
||||
if last_bottom.index + 4 > klc.index:
|
||||
#klc.set_fx(Chan_FX_TYPE.PTOP)
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, "中枢卖点Sell 1")
|
||||
else:
|
||||
# First temp top and last bottom confirmed
|
||||
last_top = klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Change 4")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, "一类卖点Sell 1")
|
||||
# Last top = None, last bottom = None, create first down bi
|
||||
else:
|
||||
# First temp top
|
||||
last_top = klc
|
||||
bi = ChanBI(klc, len(bi_list), Chan_BI_DIR.DOWN)
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.TOP6)
|
||||
#klc.bb_out = True
|
||||
bi_list.append(bi)
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Change 5")
|
||||
#print(klc.start_time, 'Create first top')
|
||||
#print(klc.start_time, klc.fx, "笔卖点Sell 1")
|
||||
#klc.fx = Bottom ========================
|
||||
else:
|
||||
if last_bottom:
|
||||
if last_top:
|
||||
# Bottom after top and find a new bottom
|
||||
if last_top.index < last_bottom.index:
|
||||
# Second bottom uppper to be second buy point and confirm last bi
|
||||
if last_bottom.low < klc.low:
|
||||
#klc.set_fx(Chan_FX_TYPE.BB)
|
||||
#klc.set_state("-20")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#klc.cal_invisible()
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM3)
|
||||
#print(last_bottom.start_time, last_bottom.end_time, "--------------------------------1")
|
||||
#print(klc.start_time, klc.fx, "二类买点Buy 1")
|
||||
else:
|
||||
# A new bottom found
|
||||
#last_bottom.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||
last_bottom = klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Bottom Change 1")
|
||||
klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM1)
|
||||
self.check_fx_pattern(klc)
|
||||
#print(klc.start_time, klc.fx, "一类买点Buy 1")
|
||||
#klc.set_state("-10")
|
||||
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:
|
||||
#klc.set_fx(Chan_FX_TYPE.PBOTTOM)
|
||||
#klc.set_fx(Chan_FX_TYPE.BB)
|
||||
#klc.set_state("-100")
|
||||
#print(klc.start_time, klc.fx, "中枢买点Buy 1")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
# Found new bottom
|
||||
else:
|
||||
if last_bottom.index + 4 < klc.index and len(bi_list) > 1:
|
||||
pre_last_bi = bi_list[-2]
|
||||
last_bi = bi_list[-1]
|
||||
if pre_last_bi.is_sure and not last_bi.is_sure and pre_last_bi.dir == Chan_BI_DIR.DOWN and False:
|
||||
pre_last_bi.update_bi(klc)
|
||||
bi_list.remove(last_bi)
|
||||
pre_last_bi.set_next(None)
|
||||
#last_bottom.set_fx(Chan_FX_TYPE.PBOTTOM)
|
||||
last_bottom = klc
|
||||
last_top = pre_last_bi.start_klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Bottom Change 2")
|
||||
klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM2)
|
||||
#print(klc.start_time, last_bi.start_klc.start_time, "New BOTTOM Found reset last bi")
|
||||
#klc.set_state("-10")
|
||||
#print(klc.start_time, klc.fx, "笔买点Buy 1")
|
||||
###klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM2) # when bi is up but the fx is bottom
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
else:
|
||||
#klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, "无效分型")
|
||||
# 满足结合律的分型
|
||||
else:
|
||||
# New Temp Bottom and last top confirmed ***** confirm last up bi(last bottom and last top)
|
||||
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)
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.TOP6)
|
||||
#klc.bb_out = True
|
||||
last_bi.set_next(bi)
|
||||
bi.set_pre(last_bi)
|
||||
bi.add_klc(klc)
|
||||
bi_list.append(bi)
|
||||
last_bottom = klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Bottom Change 2")
|
||||
klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM2)
|
||||
self.check_fx_pattern(klc)
|
||||
#klc.set_state('-30')
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, "笔买点Buy 2")
|
||||
#print(klc.start_time, last_top.start_time, "Normal Bottom Found, Confirm up bi 6")
|
||||
# last_top = None
|
||||
else:
|
||||
if last_bottom.low > klc.low:
|
||||
last_bi = bi_list[-1]
|
||||
last_bi.set_start_klc(klc, Chan_BI_DIR.UP)
|
||||
#last_bottom.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||
last_bottom = klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Bottom Change 3")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, "笔买点Buy 3")
|
||||
else:
|
||||
klc.set_fx(Chan_FX_TYPE.BB)
|
||||
#klc.set_state('-20')
|
||||
#print(klc.start_time, klc.fx, "二类买点Buy 2")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
# last_bottom = None
|
||||
else:
|
||||
if last_top:
|
||||
# 不满足结合律的分型
|
||||
if last_top.index + 4 > klc.index:
|
||||
#klc.set_fx(Chan_FX_TYPE.PBOTTOM)
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, "中枢买点Buy 1")
|
||||
else:
|
||||
# First temp bottom and last top confirmed
|
||||
last_bottom = klc
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Bottom Change 4")
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, "一类买点Buy 1")
|
||||
# Last top = None, last bottom = None, create first up bi
|
||||
else:
|
||||
# First temp bottom and no top yet
|
||||
last_bottom = klc
|
||||
bi = ChanBI(klc, len(bi_list), Chan_BI_DIR.UP)
|
||||
#klc.set_klc_fx_type(Chan_KLC_FX.BOTTOM7)
|
||||
#klc.bb_out = True
|
||||
bi_list.append(bi)
|
||||
bi_list[-1].add_klc(klc)
|
||||
klc.set_bi(bi_list[-1])
|
||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Bottom Change 5")
|
||||
#print(klc.start_time, klc.fx, "笔买点Buy 4")
|
||||
#if klc.fx != Chan_FX_TYPE.UNKNOWN:
|
||||
#print(klc.start_time, klc.fx, klc.index)
|
||||
"""
|
||||
for klc in klc_list:
|
||||
if klc.fx == Chan_FX_TYPE.TOP:
|
||||
klc.state = "10"
|
||||
#print(klc.time, klc.state)
|
||||
if klc.fx == Chan_FX_TYPE.BOTTOM:
|
||||
klc.state = "-10"
|
||||
#print(klc.time, klc.state)
|
||||
"""
|
||||
#for index in range(0, 10):
|
||||
#print(bi_list[index].start_time, bi_list[index].start_klc.start_time, bi_list[index].dir)
|
||||
return bi_list
|
||||
if klc.pre and klc.pre.signal < 0 and klc.signal > 0:
|
||||
above_zero = True
|
||||
if klc.pre and klc.pre.signal > 0 and klc.signal < 0:
|
||||
above_zero = False
|
||||
if above_zero and klc.klc_fx_type == Chan_KLC_FX.BOTTOM2 and klc.macd > 0:
|
||||
buy_bsp = klc
|
||||
buy_bsp_list.append(klc)
|
||||
#print(klc.end_time, "MACD 0轴上穿,回调笔底分型做多")
|
||||
if buy_bsp and klc.pre and klc.pre.macdhist > 0 and klc.macdhist < 0:
|
||||
sell_bsp = klc
|
||||
sell_bsp_list.append(klc)
|
||||
buy_bsp = None
|
||||
#print(klc.end_time, "Sell BSP Found")
|
||||
return buy_bsp_list
|
||||
def check_top_fx(self, last_bottom, klc):
|
||||
if (last_bottom.high > klc.pre.low or last_bottom.high > klc.next.low) and (klc.index - last_bottom.index < 10):
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user