+1
-1
@@ -26,7 +26,7 @@ class ChanBIZS():
|
|||||||
self.set_end_time(end_bi.end_klc.end_time)
|
self.set_end_time(end_bi.end_klc.end_time)
|
||||||
self.is_sure = True
|
self.is_sure = True
|
||||||
self.sure_time = sure_bi.sure_time
|
self.sure_time = sure_bi.sure_time
|
||||||
print(self.start_time, self.is_sure, len(self.bi_list), self.dir, self.zs_type)
|
#print(self.start_time, self.is_sure, len(self.bi_list), self.dir, self.zs_type)
|
||||||
def set_end_time(self, end_time):
|
def set_end_time(self, end_time):
|
||||||
self.end_time = end_time
|
self.end_time = end_time
|
||||||
def set_zg(self, zg):
|
def set_zg(self, zg):
|
||||||
|
|||||||
+4
-4
@@ -4,11 +4,11 @@ from ChanEnum import Chan_BSP_TYPE, Chan_BSP_DIR
|
|||||||
class ChanBSP():
|
class ChanBSP():
|
||||||
def __init__(self, bi: ChanBI, index, type: Chan_BSP_TYPE, ddir: Chan_BSP_DIR, sure_time, zs_count, zs, seg):
|
def __init__(self, bi: ChanBI, index, type: Chan_BSP_TYPE, ddir: Chan_BSP_DIR, sure_time, zs_count, zs, seg):
|
||||||
self.bi = bi
|
self.bi = bi
|
||||||
self.klc = bi.start_klc
|
self.klc = bi.end_klc
|
||||||
self.index = index
|
self.index = index
|
||||||
self.type = type
|
self.type = type
|
||||||
self.start_time = bi.end_klc.start_time
|
self.start_time = self.klc.start_time
|
||||||
self.end_time = bi.end_klc.end_time
|
self.end_time = self.klc.end_time
|
||||||
if sure_time:
|
if sure_time:
|
||||||
self.is_sure = True
|
self.is_sure = True
|
||||||
self.sure_time = sure_time
|
self.sure_time = sure_time
|
||||||
@@ -18,7 +18,7 @@ class ChanBSP():
|
|||||||
self.dir = ddir
|
self.dir = ddir
|
||||||
self.zs_count = zs_count
|
self.zs_count = zs_count
|
||||||
self.zs = zs
|
self.zs = zs
|
||||||
self.seg = seg
|
self.seg = bi.seg
|
||||||
def set_sure_time(self, sure_time):
|
def set_sure_time(self, sure_time):
|
||||||
self.is_sure = True
|
self.is_sure = True
|
||||||
self.sure_time = sure_time
|
self.sure_time = sure_time
|
||||||
@@ -151,6 +151,14 @@ class ChanLun():
|
|||||||
return self.tf_df.check_bottom_fx(last_top, klc)
|
return self.tf_df.check_bottom_fx(last_top, klc)
|
||||||
def cal_bi_list(self, klc_list):
|
def cal_bi_list(self, klc_list):
|
||||||
return self.tf_df.cal_bi_list(klc_list)
|
return self.tf_df.cal_bi_list(klc_list)
|
||||||
|
def cal_bi_list_chanlun(self, klc_list):
|
||||||
|
return self.tf_df.cal_bi_list_chanlun(klc_list)
|
||||||
|
def find_first_bsp(self, bi_list, bi_zs_list):
|
||||||
|
return self.tf_df.find_first_bsp(bi_list, bi_zs_list)
|
||||||
|
def find_second_bsp(self, bi_list, first_bsp_list):
|
||||||
|
return self.tf_df.find_second_bsp(bi_list, first_bsp_list)
|
||||||
|
def find_third_bsp(self, bi_list, bi_zs_list):
|
||||||
|
return self.tf_df.find_third_bsp(bi_list, bi_zs_list)
|
||||||
def get_zs_list(self, bi_list, seg_list):
|
def get_zs_list(self, bi_list, seg_list):
|
||||||
return self.tf_df.get_zs_list(bi_list, seg_list)
|
return self.tf_df.get_zs_list(bi_list, seg_list)
|
||||||
def cal_bi_zs(self, seg_list):
|
def cal_bi_zs(self, seg_list):
|
||||||
|
|||||||
+5
-6
@@ -26,7 +26,7 @@ class ChanMACDHistSet():
|
|||||||
def set_middle_klu(self, middle_klu):
|
def set_middle_klu(self, middle_klu):
|
||||||
self.middle_klu = middle_klu
|
self.middle_klu = middle_klu
|
||||||
#self.middle_area = abs(middle_klu.macdhist)
|
#self.middle_area = abs(middle_klu.macdhist)
|
||||||
self.middle_klu = None
|
#self.middle_klu = None
|
||||||
def set_unittf_div(self, unittf_div):
|
def set_unittf_div(self, unittf_div):
|
||||||
self.unittf_div = unittf_div
|
self.unittf_div = unittf_div
|
||||||
def add_klu(self, klu):
|
def add_klu(self, klu):
|
||||||
@@ -92,12 +92,11 @@ class ChanMACDHistSet():
|
|||||||
self.peak_klu = self.start_klu
|
self.peak_klu = self.start_klu
|
||||||
else:
|
else:
|
||||||
self.peak_klu = end_klu
|
self.peak_klu = end_klu
|
||||||
if self.start_klu.index + 2 == end_klu.index:
|
if len(self.klu_list) >= 3 and self.peak_klu == None:
|
||||||
peak = self.klu_list[0]
|
self.peak_klu = self.klu_list[0]
|
||||||
for klu in self.klu_list:
|
for klu in self.klu_list:
|
||||||
if abs(klu.macdhist) > abs(peak.macdhist):
|
if abs(klu.macdhist) > abs(self.peak_klu.macdhist):
|
||||||
peak = klu
|
self.peak_klu = klu
|
||||||
self.peak_klu = peak
|
|
||||||
peak_str = ""
|
peak_str = ""
|
||||||
state_str = ""
|
state_str = ""
|
||||||
for peak_div in self.peak_div_list:
|
for peak_div in self.peak_div_list:
|
||||||
|
|||||||
@@ -48,6 +48,15 @@ class ChanSBI():
|
|||||||
#print(self.start_bi.start_time, self.end_bi.end_time, self.pre.start_bi.start_time, self.next.start_bi.start_time, self.dir, self.has_fx_gap, self.fx)
|
#print(self.start_bi.start_time, self.end_bi.end_time, self.pre.start_bi.start_time, self.next.start_bi.start_time, self.dir, self.has_fx_gap, self.fx)
|
||||||
return Chan_FX_TYPE.BOTTOM
|
return Chan_FX_TYPE.BOTTOM
|
||||||
return Chan_FX_TYPE.UNKNOWN
|
return Chan_FX_TYPE.UNKNOWN
|
||||||
|
def check_seg_bi_broken(self):
|
||||||
|
broken = False
|
||||||
|
if self.fx == Chan_FX_TYPE.TOP:
|
||||||
|
if self.next.low < self.pre.high:
|
||||||
|
broken = True
|
||||||
|
elif self.fx == Chan_FX_TYPE.BOTTOM:
|
||||||
|
if self.next.high > self.pre.low:
|
||||||
|
broken = True
|
||||||
|
return broken
|
||||||
def check_bi_included(self, bi):
|
def check_bi_included(self, bi):
|
||||||
included = False
|
included = False
|
||||||
if self.high > bi.high:
|
if self.high > bi.high:
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class TF_DF():
|
|||||||
df['volume_ratio'] = self.cal_volume_ratio(df)
|
df['volume_ratio'] = self.cal_volume_ratio(df)
|
||||||
return df
|
return df
|
||||||
def get_klu_state(self, dataframe):
|
def get_klu_state(self, dataframe):
|
||||||
klc_list = self.get_klc_list(dataframe)
|
klc_list = self.get_klc_list(self.get_klu_list(dataframe))
|
||||||
bi_list = self.cal_bi_list(klc_list)
|
bi_list = self.cal_bi_list(klc_list)
|
||||||
klu_state_list = []
|
klu_state_list = []
|
||||||
klc_index = 0
|
klc_index = 0
|
||||||
@@ -127,32 +127,45 @@ class TF_DF():
|
|||||||
klc_index = len(klc_list) - 1
|
klc_index = len(klc_list) - 1
|
||||||
klc = klc_list[klc_index]
|
klc = klc_list[klc_index]
|
||||||
if klc.end_klu and klc.end_klu.idx == index:
|
if klc.end_klu and klc.end_klu.idx == index:
|
||||||
if klc.klc_fx_type == Chan_KLC_FX.TOP4:
|
if klc.klc_fx_type == Chan_KLC_FX.TOP1 or klc.klc_fx_type == Chan_KLC_FX.TOP2:
|
||||||
klu_state_list.append("10")
|
klu_state_list.append("10")
|
||||||
elif klc.klc_fx_type == Chan_KLC_FX.BOTTOM4:
|
#print(klc.end_time, klc.klc_fx_type)
|
||||||
|
elif klc.klc_fx_type == Chan_KLC_FX.BOTTOM1 or klc.klc_fx_type == Chan_KLC_FX.BOTTOM2:
|
||||||
klu_state_list.append("-10")
|
klu_state_list.append("-10")
|
||||||
|
#print(klc.end_time, klc.klc_fx_type)
|
||||||
else:
|
else:
|
||||||
klu_state_list.append("00")
|
if klc.continue_div:
|
||||||
|
if klc.macdhist > 0:
|
||||||
|
klu_state_list.append("20")
|
||||||
|
#print(klc.end_time, "CD", 20)
|
||||||
|
else:
|
||||||
|
klu_state_list.append("-20")
|
||||||
|
#print(klc.end_time, "CD", -20)
|
||||||
|
elif klc.separate_div:
|
||||||
|
if klc.macdhist > 0:
|
||||||
|
klu_state_list.append("30")
|
||||||
|
#print(klc.end_time, "SD", 30)
|
||||||
|
else:
|
||||||
|
klu_state_list.append("-30")
|
||||||
|
#print(klc.end_time, "SD", -30)
|
||||||
|
else:
|
||||||
|
klu_state_list.append("00")
|
||||||
klc_index += 1
|
klc_index += 1
|
||||||
else:
|
else:
|
||||||
klu_state_list.append("00")
|
klu_state_list.append("00")
|
||||||
return klu_state_list
|
return klu_state_list
|
||||||
def check_fx(self, klc):
|
def check_fx(self, klc):
|
||||||
if klc.pre and klc.next:
|
if klc.pre and klc.next:
|
||||||
if klc.high > klc.pre.high and klc.high > klc.next.high and klc.low > klc.pre.low and klc.low > klc.next.low and klc.macd > 0:
|
if klc.high > klc.pre.high and klc.high > klc.next.high and klc.low > klc.pre.low and klc.low > klc.next.low and klc.macd> 0:
|
||||||
if klc.pre.pre and klc.next.next:
|
#if (klc.close > klc.ema52 or klc.next.close > klc.next.ema52) and klc.macd > 0:
|
||||||
if klc.high > klc.pre.pre.high and klc.high > klc.next.next.high:
|
klc.set_fx(Chan_FX_TYPE.TOP)
|
||||||
#if (klc.close > klc.ema52 or klc.next.close > klc.next.ema52) and klc.macd > 0:
|
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "TOP")
|
||||||
klc.set_fx(Chan_FX_TYPE.TOP)
|
return Chan_FX_TYPE.TOP
|
||||||
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "TOP")
|
|
||||||
return Chan_FX_TYPE.TOP
|
|
||||||
elif klc.low < klc.pre.low and klc.low < klc.next.low and klc.high < klc.pre.high and klc.high < klc.next.high and klc.macd < 0:
|
elif klc.low < klc.pre.low and klc.low < klc.next.low and klc.high < klc.pre.high and klc.high < klc.next.high and klc.macd < 0:
|
||||||
if klc.pre.pre and klc.next.next:
|
#if (klc.close < klc.ema52 or klc.next.close < klc.next.ema52) and klc.macd < 0:
|
||||||
if klc.low < klc.pre.pre.low and klc.low < klc.next.next.low:
|
klc.set_fx(Chan_FX_TYPE.BOTTOM)
|
||||||
#if (klc.close < klc.ema52 or klc.next.close < klc.next.ema52) and klc.macd < 0:
|
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "BOTTOM")
|
||||||
klc.set_fx(Chan_FX_TYPE.BOTTOM)
|
return Chan_FX_TYPE.BOTTOM
|
||||||
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "BOTTOM")
|
|
||||||
return Chan_FX_TYPE.BOTTOM
|
|
||||||
return Chan_FX_TYPE.UNKNOWN
|
return Chan_FX_TYPE.UNKNOWN
|
||||||
def check_fx_pattern(self, klc):
|
def check_fx_pattern(self, klc):
|
||||||
klu_list = klc.pre.klu_list + klc.klu_list + klc.next.klu_list
|
klu_list = klc.pre.klu_list + klc.klu_list + klc.next.klu_list
|
||||||
@@ -524,6 +537,7 @@ class TF_DF():
|
|||||||
return klu_list
|
return klu_list
|
||||||
def get_bi_list(self, dataframe):
|
def get_bi_list(self, dataframe):
|
||||||
bi_list = self.cal_bi_list(self.get_klc_list(dataframe))
|
bi_list = self.cal_bi_list(self.get_klc_list(dataframe))
|
||||||
|
#bi_list = self.cal_bi_list_chanlun(self.get_klc_list(dataframe))
|
||||||
return bi_list
|
return bi_list
|
||||||
def get_kl_data(self, dataframe:DataFrame):
|
def get_kl_data(self, dataframe:DataFrame):
|
||||||
return self.cal_kl_data(dataframe)
|
return self.cal_kl_data(dataframe)
|
||||||
@@ -858,13 +872,14 @@ class TF_DF():
|
|||||||
last_bottom = None
|
last_bottom = None
|
||||||
for klc in klc_list:
|
for klc in klc_list:
|
||||||
fx = self.check_fx(klc)
|
fx = self.check_fx(klc)
|
||||||
if fx == Chan_FX_TYPE.TOP and False:
|
if fx == Chan_FX_TYPE.TOP:
|
||||||
if last_bottom:
|
if last_bottom:
|
||||||
if self.check_top_fx(last_bottom, klc) == False:
|
if self.check_top_fx(last_bottom, klc) == False:
|
||||||
fx = Chan_FX_TYPE.UNKNOWN
|
fx = Chan_FX_TYPE.UNKNOWN
|
||||||
if fx == Chan_FX_TYPE.BOTTOM and False:
|
if fx == Chan_FX_TYPE.BOTTOM:
|
||||||
if last_top:
|
if last_top:
|
||||||
if self.check_bottom_fx(last_top, klc) == False:
|
if self.check_bottom_fx(last_top, klc) == False:
|
||||||
|
#print(klc.end_time, last_top.end_time, "---")
|
||||||
fx = Chan_FX_TYPE.UNKNOWN
|
fx = Chan_FX_TYPE.UNKNOWN
|
||||||
# Do nothing
|
# Do nothing
|
||||||
if fx == Chan_FX_TYPE.UNKNOWN:
|
if fx == Chan_FX_TYPE.UNKNOWN:
|
||||||
@@ -1174,15 +1189,209 @@ class TF_DF():
|
|||||||
#print(bi_list[index].start_time, bi_list[index].start_klc.start_time, bi_list[index].dir)
|
#print(bi_list[index].start_time, bi_list[index].start_klc.start_time, bi_list[index].dir)
|
||||||
return bi_list
|
return bi_list
|
||||||
def check_top_fx(self, last_bottom, klc):
|
def check_top_fx(self, last_bottom, klc):
|
||||||
if last_bottom.high > klc.pre.low or last_bottom.high > klc.next.low:
|
if (last_bottom.high > klc.pre.low or last_bottom.high > klc.next.low) and (klc.index - last_bottom.index < 10):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def check_bottom_fx(self, last_top, klc):
|
def check_bottom_fx(self, last_top, klc):
|
||||||
if last_top.low < klc.pre.high or last_top.low < klc.next.high:
|
if (last_top.low < klc.pre.high or last_top.low < klc.next.high) and (klc.index - last_top.index < 10):
|
||||||
return False
|
return False
|
||||||
return True
|
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):
|
def cal_bi_zs(self, seg_list):
|
||||||
bi_zs_list = []
|
bi_zs_list = []
|
||||||
for seg in seg_list:
|
for seg in seg_list:
|
||||||
@@ -1191,9 +1400,260 @@ class TF_DF():
|
|||||||
bi_zs_list.append(zs_list)
|
bi_zs_list.append(zs_list)
|
||||||
return bi_zs_list
|
return bi_zs_list
|
||||||
def find_third_bsp(self, bi_list, bi_zs_list):
|
def find_third_bsp(self, bi_list, bi_zs_list):
|
||||||
if len(bi_list) > 3 and len(bi_zs_list) > 0:
|
"""
|
||||||
last_bi_zs = bi_zs_list[-1]
|
笔中枢的三类买卖点识别
|
||||||
last_bi = bi_list[-1]
|
|
||||||
|
三类买点:中枢形成后,一笔向上离开中枢(低点 > zg),
|
||||||
|
随后回拉的一笔低点不跌回中枢(低点 >= zg),确认支撑有效。
|
||||||
|
三类卖点:中枢形成后,一笔向下离开中枢(高点 < zd),
|
||||||
|
随后反弹的一笔高点不回到中枢(高点 <= zd),确认压力有效。
|
||||||
|
|
||||||
|
参数:
|
||||||
|
bi_list: 笔列表
|
||||||
|
bi_zs_list: 笔中枢列表(二维列表,每个seg内的中枢列表)
|
||||||
|
|
||||||
|
返回:
|
||||||
|
bsp_list: ChanBSP 列表,包含所有识别到的三类买卖点
|
||||||
|
"""
|
||||||
|
bsp_list = []
|
||||||
|
if len(bi_list) < 4 or len(bi_zs_list) == 0:
|
||||||
|
return bsp_list
|
||||||
|
|
||||||
|
for zs in bi_zs_list:
|
||||||
|
if not zs.is_sure or len(zs.bi_list) < 3:
|
||||||
|
continue
|
||||||
|
#print(zs.start_time, zs.end_time, zs.dir, zs.is_sure, len(zs.bi_list))
|
||||||
|
# 中枢结束后的第一笔(离开笔)
|
||||||
|
last_zs_bi = zs.bi_list[-1]
|
||||||
|
if last_zs_bi.dir == Chan_BI_DIR.UP:
|
||||||
|
if last_zs_bi.end_klc.high <= zs.zg or (last_zs_bi.next and last_zs_bi.next.is_sure and last_zs_bi.next.end_klc.low < zs.zd):
|
||||||
|
leave_bi = last_zs_bi.next
|
||||||
|
else:
|
||||||
|
leave_bi = last_zs_bi
|
||||||
|
else:
|
||||||
|
if last_zs_bi.end_klc.low >= zs.zd or (last_zs_bi.next and last_zs_bi.next.is_sure and last_zs_bi.next.end_klc.high > zs.zg):
|
||||||
|
leave_bi = last_zs_bi.next
|
||||||
|
else:
|
||||||
|
leave_bi = last_zs_bi
|
||||||
|
#print(zs.zg, zs.zd)
|
||||||
|
if leave_bi is None or not leave_bi.is_sure:
|
||||||
|
continue
|
||||||
|
if (zs.dir == Chan_ZS_DIR.UP and leave_bi.dir == Chan_BI_DIR.UP and leave_bi.end_klc.high < zs.zg and leave_bi.end_klc.high > zs.zd) or (zs.dir == Chan_ZS_DIR.DOWN and leave_bi.dir == Chan_BI_DIR.DOWN and leave_bi.end_klc.low < zs.zg and leave_bi.end_klc.low > zs.zd):
|
||||||
|
#print("--------------------", leave_bi.dir, leave_bi.end_klc.high, leave_bi.end_klc.low, zs.zg, zs.zd)
|
||||||
|
leave_bi = leave_bi.next
|
||||||
|
# 三类买点:向上离开中枢后回拉不破 zg
|
||||||
|
#print("Leave bi:", leave_bi.start_time, leave_bi.end_time, leave_bi.dir, leave_bi.is_sure, leave_bi.low, leave_bi.high)
|
||||||
|
if leave_bi.dir == Chan_BI_DIR.UP:
|
||||||
|
# 回拉笔
|
||||||
|
pullback_bi = leave_bi.next
|
||||||
|
#print(pullback_bi.start_klc.start_time, pullback_bi.dir, pullback_bi.is_sure, pullback_bi.low, pullback_bi.high)
|
||||||
|
if pullback_bi and pullback_bi.is_sure and pullback_bi.dir == Chan_BI_DIR.DOWN:
|
||||||
|
if pullback_bi.low >= zs.zg:
|
||||||
|
# 确认三类买点:回拉笔的低点不跌回中枢
|
||||||
|
bsp = ChanBSP(
|
||||||
|
pullback_bi, len(bsp_list),
|
||||||
|
Chan_BSP_TYPE.T3,
|
||||||
|
Chan_BSP_DIR.BUY,
|
||||||
|
pullback_bi.sure_time,
|
||||||
|
1, zs, None
|
||||||
|
)
|
||||||
|
bsp_list.append(bsp)
|
||||||
|
|
||||||
|
# 三类卖点:向下离开中枢后反弹不破 zd
|
||||||
|
elif leave_bi.dir == Chan_BI_DIR.DOWN:
|
||||||
|
# 反弹笔
|
||||||
|
bounce_bi = leave_bi.next
|
||||||
|
#print(bounce_bi.start_klc.start_time, bounce_bi.dir, bounce_bi.is_sure, bounce_bi.low, bounce_bi.high)
|
||||||
|
if bounce_bi and bounce_bi.is_sure and bounce_bi.dir == Chan_BI_DIR.UP:
|
||||||
|
if bounce_bi.high <= zs.zd:
|
||||||
|
# 确认三类卖点:反弹笔的高点不回到中枢
|
||||||
|
bsp = ChanBSP(
|
||||||
|
bounce_bi, len(bsp_list),
|
||||||
|
Chan_BSP_TYPE.T3,
|
||||||
|
Chan_BSP_DIR.SELL,
|
||||||
|
bounce_bi.sure_time,
|
||||||
|
1, zs, None
|
||||||
|
)
|
||||||
|
bsp_list.append(bsp)
|
||||||
|
return bsp_list
|
||||||
|
|
||||||
|
def find_first_bsp(self, bi_list, bi_zs_list):
|
||||||
|
"""
|
||||||
|
笔中枢的一类买卖点识别
|
||||||
|
|
||||||
|
一类买点:下跌趋势中,最后一个中枢完成后,向下离开中枢的笔创新低,
|
||||||
|
但该笔与进入中枢前的最后一笔下跌形成底背驰(力度减弱),
|
||||||
|
即趋势力竭的转折点。
|
||||||
|
一类卖点:上涨趋势中,最后一个中枢完成后,向上离开中枢的笔创新高,
|
||||||
|
但该笔与进入中枢前的最后一笔上涨形成顶背驰(力度减弱),
|
||||||
|
即趋势力竭的转折点。
|
||||||
|
|
||||||
|
简化判断:中枢形成后,离开中枢的笔(突破笔)本身即为一类买卖点的触发笔。
|
||||||
|
|
||||||
|
参数:
|
||||||
|
bi_list: 笔列表
|
||||||
|
bi_zs_list: 笔中枢列表(扁平列表,每个元素是一个中枢对象)
|
||||||
|
|
||||||
|
返回:
|
||||||
|
bsp_list: ChanBSP 列表,包含所有识别到的一类买卖点
|
||||||
|
"""
|
||||||
|
bsp_list = []
|
||||||
|
if len(bi_list) < 4 or len(bi_zs_list) == 0:
|
||||||
|
return bsp_list
|
||||||
|
|
||||||
|
for zs in bi_zs_list:
|
||||||
|
if not zs.is_sure or len(zs.bi_list) < 3:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 找到中枢的最后一笔
|
||||||
|
last_zs_bi = zs.bi_list[-1]
|
||||||
|
|
||||||
|
# 确定离开笔:中枢最后一笔之后的第一笔
|
||||||
|
if last_zs_bi.dir == Chan_BI_DIR.UP:
|
||||||
|
# 中枢最后一笔向上,如果没有真正离开中枢,取下一笔
|
||||||
|
if last_zs_bi.end_klc.high <= zs.zg:
|
||||||
|
leave_bi = last_zs_bi.next
|
||||||
|
else:
|
||||||
|
leave_bi = last_zs_bi
|
||||||
|
else:
|
||||||
|
# 中枢最后一笔向下,如果没有真正离开中枢,取下一笔
|
||||||
|
if last_zs_bi.end_klc.low >= zs.zd:
|
||||||
|
leave_bi = last_zs_bi.next
|
||||||
|
else:
|
||||||
|
leave_bi = last_zs_bi
|
||||||
|
|
||||||
|
if leave_bi is None or not leave_bi.is_sure:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 一类买点:向下离开中枢(leave_bi向下,低点 < zd),趋势力竭
|
||||||
|
if leave_bi.dir == Chan_BI_DIR.DOWN and leave_bi.low < zs.zd:
|
||||||
|
# 背驰判断:比较离开笔与中枢内最后一笔同向笔的MACD柱状累积面积
|
||||||
|
# 缠论原文:两段同向走势的MACD柱状面积比较,面积缩小即为背驰
|
||||||
|
compare_bi = None
|
||||||
|
for bi in reversed(zs.bi_list):
|
||||||
|
if bi.dir == Chan_BI_DIR.DOWN and bi is not leave_bi:
|
||||||
|
compare_bi = bi
|
||||||
|
break
|
||||||
|
|
||||||
|
is_divergence = False
|
||||||
|
if compare_bi:
|
||||||
|
# 笔的macd_hist是该笔内所有KLU的macdhist累积面积
|
||||||
|
leave_macd_area = abs(leave_bi.macd_hist)
|
||||||
|
compare_macd_area = abs(compare_bi.macd_hist)
|
||||||
|
|
||||||
|
# 价格创新低但MACD面积缩小 = 底背驰
|
||||||
|
if leave_bi.low <= compare_bi.low and leave_macd_area < compare_macd_area:
|
||||||
|
is_divergence = True
|
||||||
|
# 即使没创新低,MACD面积明显缩小也算背驰
|
||||||
|
elif leave_macd_area < compare_macd_area * 0.5:
|
||||||
|
is_divergence = True
|
||||||
|
else:
|
||||||
|
# 没有对比笔时,只要离开中枢就算一类买点
|
||||||
|
is_divergence = True
|
||||||
|
|
||||||
|
if is_divergence:
|
||||||
|
bsp = ChanBSP(
|
||||||
|
leave_bi, len(bsp_list),
|
||||||
|
Chan_BSP_TYPE.T1,
|
||||||
|
Chan_BSP_DIR.BUY,
|
||||||
|
leave_bi.sure_time,
|
||||||
|
1, zs, None
|
||||||
|
)
|
||||||
|
bsp_list.append(bsp)
|
||||||
|
|
||||||
|
# 一类卖点:向上离开中枢(leave_bi向上,高点 > zg),趋势力竭
|
||||||
|
elif leave_bi.dir == Chan_BI_DIR.UP and leave_bi.high > zs.zg:
|
||||||
|
# 背驰判断:比较离开笔与中枢内最后一笔同向笔的MACD柱状累积面积
|
||||||
|
compare_bi = None
|
||||||
|
for bi in reversed(zs.bi_list):
|
||||||
|
if bi.dir == Chan_BI_DIR.UP and bi is not leave_bi:
|
||||||
|
compare_bi = bi
|
||||||
|
break
|
||||||
|
|
||||||
|
is_divergence = False
|
||||||
|
if compare_bi:
|
||||||
|
leave_macd_area = abs(leave_bi.macd_hist)
|
||||||
|
compare_macd_area = abs(compare_bi.macd_hist)
|
||||||
|
|
||||||
|
# 价格创新高但MACD面积缩小 = 顶背驰
|
||||||
|
if leave_bi.high >= compare_bi.high and leave_macd_area < compare_macd_area:
|
||||||
|
is_divergence = True
|
||||||
|
# 即使没创新高,MACD面积明显缩小也算背驰
|
||||||
|
elif leave_macd_area < compare_macd_area * 0.5:
|
||||||
|
is_divergence = True
|
||||||
|
else:
|
||||||
|
is_divergence = True
|
||||||
|
|
||||||
|
if is_divergence:
|
||||||
|
bsp = ChanBSP(
|
||||||
|
leave_bi, len(bsp_list),
|
||||||
|
Chan_BSP_TYPE.T1,
|
||||||
|
Chan_BSP_DIR.SELL,
|
||||||
|
leave_bi.sure_time,
|
||||||
|
1, zs, None
|
||||||
|
)
|
||||||
|
bsp_list.append(bsp)
|
||||||
|
|
||||||
|
return bsp_list
|
||||||
|
|
||||||
|
def find_second_bsp(self, bi_list, first_bsp_list):
|
||||||
|
"""
|
||||||
|
笔中枢的二类买卖点识别
|
||||||
|
|
||||||
|
二类买点:一类买点出现后,价格向上反弹一笔,再回落一笔,
|
||||||
|
回落笔的低点不跌破一类买点的低点,确认底部成立。
|
||||||
|
二类卖点:一类卖点出现后,价格向下回落一笔,再反弹一笔,
|
||||||
|
反弹笔的高点不超过一类卖点的高点,确认顶部成立。
|
||||||
|
|
||||||
|
参数:
|
||||||
|
bi_list: 笔列表
|
||||||
|
first_bsp_list: 一类买卖点列表(find_first_bsp 的返回值)
|
||||||
|
|
||||||
|
返回:
|
||||||
|
bsp_list: ChanBSP 列表,包含所有识别到的二类买卖点
|
||||||
|
"""
|
||||||
|
bsp_list = []
|
||||||
|
if not first_bsp_list or len(bi_list) < 4:
|
||||||
|
return bsp_list
|
||||||
|
|
||||||
|
for first_bsp in first_bsp_list:
|
||||||
|
trigger_bi = first_bsp.bi # 一类买卖点的触发笔
|
||||||
|
|
||||||
|
if first_bsp.dir == Chan_BSP_DIR.BUY:
|
||||||
|
# 一买之后:trigger_bi 向下 -> 反弹笔(向上) -> 回落笔(向下)
|
||||||
|
# 回落笔的低点 > trigger_bi 的低点 => 二类买点
|
||||||
|
bounce_bi = trigger_bi.next # 反弹笔(向上)
|
||||||
|
if bounce_bi and bounce_bi.is_sure and bounce_bi.dir == Chan_BI_DIR.UP:
|
||||||
|
pullback_bi = bounce_bi.next # 回落笔(向下)
|
||||||
|
if pullback_bi and pullback_bi.is_sure and pullback_bi.dir == Chan_BI_DIR.DOWN:
|
||||||
|
if pullback_bi.low > trigger_bi.low:
|
||||||
|
bsp = ChanBSP(
|
||||||
|
pullback_bi, len(bsp_list),
|
||||||
|
Chan_BSP_TYPE.T2,
|
||||||
|
Chan_BSP_DIR.BUY,
|
||||||
|
pullback_bi.sure_time,
|
||||||
|
1, first_bsp.zs, None
|
||||||
|
)
|
||||||
|
bsp_list.append(bsp)
|
||||||
|
|
||||||
|
elif first_bsp.dir == Chan_BSP_DIR.SELL:
|
||||||
|
# 一卖之后:trigger_bi 向上 -> 回落笔(向下) -> 反弹笔(向上)
|
||||||
|
# 反弹笔的高点 < trigger_bi 的高点 => 二类卖点
|
||||||
|
drop_bi = trigger_bi.next # 回落笔(向下)
|
||||||
|
if drop_bi and drop_bi.is_sure and drop_bi.dir == Chan_BI_DIR.DOWN:
|
||||||
|
bounce_bi = drop_bi.next # 反弹笔(向上)
|
||||||
|
if bounce_bi and bounce_bi.is_sure and bounce_bi.dir == Chan_BI_DIR.UP:
|
||||||
|
if bounce_bi.high < trigger_bi.high:
|
||||||
|
bsp = ChanBSP(
|
||||||
|
bounce_bi, len(bsp_list),
|
||||||
|
Chan_BSP_TYPE.T2,
|
||||||
|
Chan_BSP_DIR.SELL,
|
||||||
|
bounce_bi.sure_time,
|
||||||
|
1, first_bsp.zs, None
|
||||||
|
)
|
||||||
|
bsp_list.append(bsp)
|
||||||
|
|
||||||
|
return bsp_list
|
||||||
|
|
||||||
def get_zs_list(self, bi_list, seg_list):
|
def get_zs_list(self, bi_list, seg_list):
|
||||||
zs_list = []
|
zs_list = []
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ logger = logging.getLogger(__name__)
|
|||||||
# freqtrade plot-dataframe --strategy ChanLun_BTC_30 --datadir user_data/data/binance -c ./user_data/ChanLun_SOL_30.json --timerange=20250309-
|
# freqtrade plot-dataframe --strategy ChanLun_BTC_30 --datadir user_data/data/binance -c ./user_data/ChanLun_SOL_30.json --timerange=20250309-
|
||||||
|
|
||||||
# freqtrade trade -c ./user_data/Chan/config/ChanLun_BTC_30.json --strategy ChanLun_BTC_30 --strategy-path ./user_data/Chan/strategies
|
# freqtrade trade -c ./user_data/Chan/config/ChanLun_BTC_30.json --strategy ChanLun_BTC_30 --strategy-path ./user_data/Chan/strategies
|
||||||
# freqtrade backtesting -c ./user_data/Chan/config/ChanLun_BTC_30.json --strategy ChanLun_BTC_30 --strategy-path ./user_data/Chan/strategies --timerange=20250901-
|
# freqtrade backtesting -c ./user_data/Chan/config/ChanLun_BTC_30.json --strategy ChanLun_BTC_30 --strategy-path ./user_data/Chan/strategies --timerange=20260101-
|
||||||
# freqtrade download-data -c ./user_data/Chan/config/ChanLun_BTC_30.json -t 1m --pairs BTC/USDT:USDT --timerange=20250405-
|
# freqtrade download-data -c ./user_data/Chan/config/ChanLun_BTC_30.json -t 1m --pairs BTC/USDT:USDT --timerange=20250405-
|
||||||
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi --strategy ChanLun_BTC_30 --strategy-path ./user_data/Chan/strategies -c ./user_data/Chan/config/ChanLun_BTC_30.json -e 200 --timerange=20250201-20250901
|
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi --strategy ChanLun_BTC_30 --strategy-path ./user_data/Chan/strategies -c ./user_data/Chan/config/ChanLun_BTC_30.json -e 200 --timerange=20250201-20250901
|
||||||
# freqtrade edge -c ./user_data/Chan/config/ChanLun_BTC_30.json --strategy ChanLun_BTC_30 --strategy-path ./user_data/Chan/strategies --timerange 20250721-20250901
|
# freqtrade edge -c ./user_data/Chan/config/ChanLun_BTC_30.json --strategy ChanLun_BTC_30 --strategy-path ./user_data/Chan/strategies --timerange 20250721-20250901
|
||||||
@@ -64,9 +64,9 @@ class ChanLun_BTC_30(IStrategy):
|
|||||||
}
|
}
|
||||||
|
|
||||||
can_short = True
|
can_short = True
|
||||||
lev = 2.0
|
lev = 1.0
|
||||||
stoploss = -0.3 # 设置为很大的负值,让custom_stoploss来控制
|
stoploss = -0.3 # 设置为很大的负值,让custom_stoploss来控制
|
||||||
use_custom_stoploss = True # 启用自定义止损
|
use_custom_stoploss = False # 启用自定义止损
|
||||||
|
|
||||||
trailing_stop = False
|
trailing_stop = False
|
||||||
trailing_stop_positive = 0.03
|
trailing_stop_positive = 0.03
|
||||||
@@ -75,7 +75,7 @@ class ChanLun_BTC_30(IStrategy):
|
|||||||
|
|
||||||
# 关闭分批止盈/仓位调整
|
# 关闭分批止盈/仓位调整
|
||||||
position_adjustment_enable = False
|
position_adjustment_enable = False
|
||||||
startup_candle_count = 2880
|
startup_candle_count = 1440
|
||||||
time3 = 3
|
time3 = 3
|
||||||
time5 = 5
|
time5 = 5
|
||||||
time15 = 15
|
time15 = 15
|
||||||
@@ -92,61 +92,60 @@ class ChanLun_BTC_30(IStrategy):
|
|||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
|
||||||
# resample our dataframes
|
# resample our dataframes
|
||||||
dataframe_3 = resample_to_interval(dataframe, self.get_ticker_indicator() * 3)
|
#dataframe_3 = resample_to_interval(dataframe, self.get_ticker_indicator() * 3)
|
||||||
dataframe_5 = resample_to_interval(dataframe, self.get_ticker_indicator() * 5)
|
dataframe_5 = resample_to_interval(dataframe, self.get_ticker_indicator() * 5)
|
||||||
dataframe_15 = resample_to_interval(dataframe, self.get_ticker_indicator() * 15)
|
#dataframe_15 = resample_to_interval(dataframe, self.get_ticker_indicator() * 15)
|
||||||
dataframe_30 = resample_to_interval(dataframe, self.get_ticker_indicator() * 30)
|
dataframe_30 = resample_to_interval(dataframe, self.get_ticker_indicator() * 30)
|
||||||
dataframe_60 = resample_to_interval(dataframe, self.get_ticker_indicator() * 60)
|
#dataframe_60 = resample_to_interval(dataframe, self.get_ticker_indicator() * 60)
|
||||||
dataframe_2h = resample_to_interval(dataframe, self.get_ticker_indicator() * 120)
|
#dataframe_2h = resample_to_interval(dataframe, self.get_ticker_indicator() * 120)
|
||||||
dataframe_4h = resample_to_interval(dataframe, self.get_ticker_indicator() * 240)
|
#dataframe_4h = resample_to_interval(dataframe, self.get_ticker_indicator() * 240)
|
||||||
|
|
||||||
#dataframe_1d = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe='1d')
|
#dataframe_1d = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe='1d')
|
||||||
#dataframe_1w = resample_to_interval(dataframe_1d, self.get_ticker_indicator() * 10080)
|
#dataframe_1w = resample_to_interval(dataframe_1d, self.get_ticker_indicator() * 10080)
|
||||||
#dataframe_1m = resample_to_interval(dataframe_1d, self.get_ticker_indicator() * 43200)
|
#dataframe_1m = resample_to_interval(dataframe_1d, self.get_ticker_indicator() * 43200)
|
||||||
|
|
||||||
dataframe_1d = resample_to_interval(dataframe, self.get_ticker_indicator() * 1440)
|
#dataframe_1d = resample_to_interval(dataframe, self.get_ticker_indicator() * 1440)
|
||||||
#dataframe_1w = resample_to_interval(dataframe, self.get_ticker_indicator() * 10080)
|
#dataframe_1w = resample_to_interval(dataframe, self.get_ticker_indicator() * 10080)
|
||||||
#dataframe_1m = resample_to_interval(dataframe, self.get_ticker_indicator() * 43200)
|
#dataframe_1m = resample_to_interval(dataframe, self.get_ticker_indicator() * 43200)
|
||||||
dataframe = self.add_indicators(dataframe)
|
dataframe = self.add_indicators(dataframe)
|
||||||
dataframe_3 = self.add_indicators(dataframe_3)
|
#dataframe_3 = self.add_indicators(dataframe_3)
|
||||||
dataframe_5 = self.add_indicators(dataframe_5)
|
dataframe_5 = self.add_indicators(dataframe_5)
|
||||||
dataframe_15 = self.add_indicators(dataframe_15)
|
#dataframe_15 = self.add_indicators(dataframe_15)
|
||||||
dataframe_30 = self.add_indicators(dataframe_30)
|
dataframe_30 = self.add_indicators(dataframe_30)
|
||||||
dataframe_60 = self.add_indicators(dataframe_60)
|
#dataframe_60 = self.add_indicators(dataframe_60)
|
||||||
dataframe_2h = self.add_indicators(dataframe_2h)
|
#dataframe_2h = self.add_indicators(dataframe_2h)
|
||||||
dataframe_4h = self.add_indicators(dataframe_4h)
|
#dataframe_4h = self.add_indicators(dataframe_4h)
|
||||||
dataframe_1d = self.add_indicators(dataframe_1d)
|
#dataframe_1d = self.add_indicators(dataframe_1d)
|
||||||
#self.chan.plot_dual(dataframe_5, dataframe_30)
|
#self.chan.plot_dual(dataframe_5, dataframe_30)
|
||||||
#chanpy_state = self.chanpy.get_bsp_state(dataframe_5)
|
#chanpy_state = self.chanpy.get_bsp_state(dataframe_5)
|
||||||
#dataframe_5['chanpy_state'] = chanpy_state
|
#dataframe_5['chanpy_state'] = chanpy_state
|
||||||
state_list = self.chan.get_klu_state_list(dataframe_3)
|
#state_list = self.chan.get_klu_state(dataframe_3)
|
||||||
dataframe_3['state'] = state_list
|
#dataframe_3['state'] = state_list
|
||||||
state_list = self.chan.get_klu_state_list(dataframe_5)
|
state_list = self.chan.get_klu_state(dataframe_5)
|
||||||
dataframe_5['state'] = state_list
|
dataframe_5['state'] = state_list
|
||||||
state_list = self.chan.get_klu_state_list(dataframe_15)
|
#state_list = self.chan.get_klu_state(dataframe_15)
|
||||||
dataframe_15['state'] = state_list
|
#dataframe_15['state'] = state_list
|
||||||
state_list = self.chan.get_klu_state_list(dataframe_30)
|
state_list = self.chan.get_klu_state(dataframe_30)
|
||||||
dataframe_30['state'] = state_list
|
dataframe_30['state'] = state_list
|
||||||
state_list = self.chan.get_klu_state_list(dataframe_60)
|
#state_list = self.chan.get_klu_state(dataframe_60)
|
||||||
dataframe_60['state'] = state_list
|
#dataframe_60['state'] = state_list
|
||||||
state_list = self.chan.get_klu_state_list(dataframe_2h)
|
#state_list = self.chan.get_klu_state(dataframe_2h)
|
||||||
dataframe_2h['state'] = state_list
|
#dataframe_2h['state'] = state_list
|
||||||
state_list = self.chan.get_klu_state_list(dataframe_4h)
|
#state_list = self.chan.get_klu_state(dataframe_4h)
|
||||||
dataframe_4h['state'] = state_list
|
#dataframe_4h['state'] = state_list
|
||||||
state_list = self.chan.get_klu_state_list(dataframe_1d)
|
#state_list = self.chan.get_klu_state(dataframe_1d)
|
||||||
dataframe_1d['state'] = state_list
|
#dataframe_1d['state'] = state_list
|
||||||
|
|
||||||
if self.last_time + timedelta(minutes=1) < datetime.now():
|
if self.last_time + timedelta(minutes=1) < datetime.now():
|
||||||
print("-------------------------------------------------------------------------------")
|
print("-------------------------------------------------------------------------------")
|
||||||
self.last_time = datetime.now()
|
self.last_time = datetime.now()
|
||||||
dataframe = resampled_merge(dataframe, dataframe_3)
|
#dataframe = resampled_merge(dataframe, dataframe_3)
|
||||||
dataframe = resampled_merge(dataframe, dataframe_5)
|
dataframe = resampled_merge(dataframe, dataframe_5)
|
||||||
dataframe = resampled_merge(dataframe, dataframe_15)
|
#dataframe = resampled_merge(dataframe, dataframe_15)
|
||||||
dataframe = resampled_merge(dataframe, dataframe_30)
|
dataframe = resampled_merge(dataframe, dataframe_30)
|
||||||
dataframe = resampled_merge(dataframe, dataframe_60)
|
#dataframe = resampled_merge(dataframe, dataframe_60)
|
||||||
dataframe = resampled_merge(dataframe, dataframe_2h)
|
#dataframe = resampled_merge(dataframe, dataframe_2h)
|
||||||
dataframe = resampled_merge(dataframe, dataframe_4h)
|
#dataframe = resampled_merge(dataframe, dataframe_4h)
|
||||||
dataframe = resampled_merge(dataframe, dataframe_1d)
|
#dataframe = resampled_merge(dataframe, dataframe_1d)
|
||||||
return dataframe
|
return dataframe
|
||||||
def print_seg(self, dataframe):
|
def print_seg(self, dataframe):
|
||||||
klc_list = self.chan.get_klc_list(dataframe)
|
klc_list = self.chan.get_klc_list(dataframe)
|
||||||
@@ -267,9 +266,9 @@ class ChanLun_BTC_30(IStrategy):
|
|||||||
return -0.05
|
return -0.05
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
|
dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
|
||||||
last_candle = dataframe.iloc[-1].squeeze()
|
last_candle = dataframe.iloc[-1].squeeze()
|
||||||
ema52_str = 'resample_{}_ema52'.format(self.get_ticker_indicator()*self.time60)
|
ema52_str = 'resample_{}_ema52'.format(self.get_ticker_indicator()*self.time30)
|
||||||
ema52_val = float(last_candle.get(ema52_str, 0) or 0)
|
ema52_val = float(last_candle.get(ema52_str, 0) or 0)
|
||||||
close_str = 'resample_{}_close'.format(self.get_ticker_indicator()*self.time60)
|
close_str = 'resample_{}_close'.format(self.get_ticker_indicator()*self.time30)
|
||||||
close_val = float(last_candle.get(close_str, 0) or 0)
|
close_val = float(last_candle.get(close_str, 0) or 0)
|
||||||
if close_val < ema52_val:
|
if close_val < ema52_val:
|
||||||
return -0.01
|
return -0.01
|
||||||
@@ -282,6 +281,8 @@ class ChanLun_BTC_30(IStrategy):
|
|||||||
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs):
|
current_profit: float, **kwargs):
|
||||||
# 不做分批止盈/最终止盈处理,退出由策略信号/ROI/止损决定
|
# 不做分批止盈/最终止盈处理,退出由策略信号/ROI/止损决定
|
||||||
|
if current_profit > 0.008:
|
||||||
|
return "Take profit"
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,
|
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,
|
||||||
@@ -295,7 +296,7 @@ class ChanLun_BTC_30(IStrategy):
|
|||||||
if dataframe is None or len(dataframe) == 0:
|
if dataframe is None or len(dataframe) == 0:
|
||||||
return False
|
return False
|
||||||
last = dataframe.iloc[-1]
|
last = dataframe.iloc[-1]
|
||||||
atr_str = 'resample_{}_atr'.format(self.get_ticker_indicator()*self.time60)
|
atr_str = 'resample_{}_atr'.format(self.get_ticker_indicator()*self.time30)
|
||||||
atr_val = float(last.get(atr_str, 0) or 0)
|
atr_val = float(last.get(atr_str, 0) or 0)
|
||||||
if atr_val < 0.001:
|
if atr_val < 0.001:
|
||||||
#logger.info(f"ATR过滤:atr={atr_val:.2f} < 100, 拒绝进场 {pair}")
|
#logger.info(f"ATR过滤:atr={atr_val:.2f} < 100, 拒绝进场 {pair}")
|
||||||
@@ -318,7 +319,7 @@ class ChanLun_BTC_30(IStrategy):
|
|||||||
# Obtain pair dataframe (just to show how to access it)
|
# Obtain pair dataframe (just to show how to access it)
|
||||||
dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
|
dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
|
||||||
last_candle = dataframe.iloc[-1].squeeze()
|
last_candle = dataframe.iloc[-1].squeeze()
|
||||||
atr_str = 'resample_{}_atr'.format(self.get_ticker_indicator()*self.time60)
|
atr_str = 'resample_{}_atr'.format(self.get_ticker_indicator()*self.time30)
|
||||||
# 保存开仓时的ATR值用于止损计算
|
# 保存开仓时的ATR值用于止损计算
|
||||||
if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side):
|
if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side):
|
||||||
entry_atr = last_candle[atr_str] * 4
|
entry_atr = last_candle[atr_str] * 4
|
||||||
@@ -326,36 +327,34 @@ class ChanLun_BTC_30(IStrategy):
|
|||||||
#logger.info(f"保存开仓时ATR值: {entry_atr}")
|
#logger.info(f"保存开仓时ATR值: {entry_atr}")
|
||||||
return None
|
return None
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
shift60 = self.time60
|
|
||||||
state60 = 'resample_{}_state'.format(self.get_ticker_indicator()*shift60)
|
|
||||||
shift30 = self.time30
|
shift30 = self.time30
|
||||||
state30 = 'resample_{}_state'.format(self.get_ticker_indicator()*shift30)
|
state30 = 'resample_{}_state'.format(self.get_ticker_indicator()*shift30)
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
(
|
(
|
||||||
(dataframe[state60].shift(shift60) == "-20")
|
(dataframe[state30].shift(shift30) == "-10") |
|
||||||
|
(dataframe[state30].shift(shift30) == "-20") |
|
||||||
|
(dataframe[state30].shift(shift30) == "-30")
|
||||||
),
|
),
|
||||||
['enter_long', 'enter_tag']] = (1, 'long_30')
|
['enter_long', 'enter_tag']] = (1, 'long_10')
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
(
|
(
|
||||||
(dataframe[state30].shift(shift30) == "40")
|
(dataframe[state30].shift(shift30) == "10") |
|
||||||
|
(dataframe[state30].shift(shift30) == "20") |
|
||||||
|
(dataframe[state30].shift(shift30) == "30")
|
||||||
),
|
),
|
||||||
['enter_short', 'enter_tag']] = (1, 'short_30')
|
['enter_short', 'enter_tag']] = (1, 'short_10')
|
||||||
return dataframe
|
return dataframe
|
||||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
shift60 = self.time60
|
|
||||||
state60 = 'resample_{}_state'.format(self.get_ticker_indicator()*shift60)
|
|
||||||
shift30 = self.time30
|
shift30 = self.time30
|
||||||
state30 = 'resample_{}_state'.format(self.get_ticker_indicator()*shift30)
|
state30 = 'resample_{}_state'.format(self.get_ticker_indicator()*shift30)
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
(
|
(
|
||||||
(dataframe[state60].shift(shift60) == "20") |
|
(dataframe[state30].shift(shift30) == "10")
|
||||||
(dataframe[state60].shift(shift60) == "30")
|
|
||||||
),
|
),
|
||||||
['exit_long', 'exit_tag']] = (1, 'long_close_30')
|
['exit_long', 'exit_tag']] = (1, 'long_close_30')
|
||||||
dataframe.loc[
|
dataframe.loc[
|
||||||
(
|
(
|
||||||
(dataframe[state30].shift(shift30) == "-20") |
|
(dataframe[state30].shift(shift30) == "-10")
|
||||||
(dataframe[state30].shift(shift30) == "-30")
|
|
||||||
),
|
),
|
||||||
['exit_short', 'exit_tag']] = (1, 'short_close_30')
|
['exit_short', 'exit_tag']] = (1, 'short_close_30')
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ EMA24,EMA52,EMA104,EMA156成下跌趋势依次排列(EMA156 > EMA104 > E
|
|||||||
|
|
||||||
# freqtrade trade -c ./user_data/Chan/config/ChanLun_EMA_Align.json --strategy ChanLun_EMA_Align --strategy-path ./user_data/Chan/strategies
|
# freqtrade trade -c ./user_data/Chan/config/ChanLun_EMA_Align.json --strategy ChanLun_EMA_Align --strategy-path ./user_data/Chan/strategies
|
||||||
# freqtrade backtesting -c ./user_data/Chan/config/ChanLun_EMA_Align.json --strategy ChanLun_EMA_Align --strategy-path ./user_data/Chan/strategies --timerange=20260101-
|
# freqtrade backtesting -c ./user_data/Chan/config/ChanLun_EMA_Align.json --strategy ChanLun_EMA_Align --strategy-path ./user_data/Chan/strategies --timerange=20260101-
|
||||||
# freqtrade download-data -c ./user_data/Chan/config/ChanLun_EMA_Align.json -t 1m 1m 1h 1d 1w 1M --pairs BTC/USDT:USDT --timerange=20240101-
|
# freqtrade download-data -c ./user_data/Chan/config/ChanLun_EMA_Align.json -t 1m 1m 5m 15m 30m 1h 1d 1w 1M --pairs BTC/USDT:USDT --timerange=20240101-
|
||||||
# freqtrade download-data -c ./user_data/Chan/config/ChanLun_EMA_Align.json -t 1m 1h 1d 1M --pairs BTC/USDT --timerange=20170101-
|
# freqtrade download-data -c ./user_data/Chan/config/ChanLun_EMA_Align.json -t 1m 1h 1d 1M --pairs BTC/USDT --timerange=20170101-
|
||||||
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi --strategy ChanLun_EMA_Align --strategy-path ./user_data/Chan/strategies -c ./user_data/Chan/config/ChanLun_EMA_Align.json -e 200 --timerange=20250201-20250901
|
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi --strategy ChanLun_EMA_Align --strategy-path ./user_data/Chan/strategies -c ./user_data/Chan/config/ChanLun_EMA_Align.json -e 200 --timerange=20250201-20250901
|
||||||
# freqtrade edge -c ./user_data/Chan/config/ChanLun_EMA_Align.json --strategy ChanLun_EMA_Align --strategy-path ./user_data/Chan/strategies --timerange 20250721-20250901
|
# freqtrade edge -c ./user_data/Chan/config/ChanLun_EMA_Align.json --strategy ChanLun_EMA_Align --strategy-path ./user_data/Chan/strategies --timerange 20250721-20250901
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
@@ -530,6 +530,9 @@ def analyze_chan(df, symbol=None, timeframe=None):
|
|||||||
bi_zs_list = [zs for group in bi_zs_nested for zs in (group or [])] if bi_zs_nested else []
|
bi_zs_list = [zs for group in bi_zs_nested for zs in (group or [])] if bi_zs_nested else []
|
||||||
except Exception:
|
except Exception:
|
||||||
bi_zs_list = []
|
bi_zs_list = []
|
||||||
|
bsp_list = []
|
||||||
|
if len(bi_zs_list) > 0:
|
||||||
|
bsp_list = chan.find_third_bsp(bi_list, bi_zs_list)
|
||||||
# 添加买卖点识别
|
# 添加买卖点识别
|
||||||
for bi in bi_list:
|
for bi in bi_list:
|
||||||
bi.cal_macdhist()
|
bi.cal_macdhist()
|
||||||
|
|||||||
Reference in New Issue
Block a user