Add seg calculation
This commit is contained in:
+67
-11
@@ -405,6 +405,7 @@ class ChanLun():
|
|||||||
up_sbi_list = []
|
up_sbi_list = []
|
||||||
last_up_sbi = ChanSBI(last_up_bi, len(up_sbi_list), last_up_bi.dir)
|
last_up_sbi = ChanSBI(last_up_bi, len(up_sbi_list), last_up_bi.dir)
|
||||||
up_sbi_list.append(last_up_sbi)
|
up_sbi_list.append(last_up_sbi)
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#up_sbi_list.append(last_up_sbi)
|
#up_sbi_list.append(last_up_sbi)
|
||||||
#print(last_up_bi.start_time, last_up_sbi.start_bi.start_time, "Reset up sbi list 1")
|
#print(last_up_bi.start_time, last_up_sbi.start_bi.start_time, "Reset up sbi list 1")
|
||||||
#print(bi.start_time, look_for_top, "UP 2")
|
#print(bi.start_time, look_for_top, "UP 2")
|
||||||
@@ -417,6 +418,7 @@ class ChanLun():
|
|||||||
up_sbi_list = []
|
up_sbi_list = []
|
||||||
last_up_sbi = ChanSBI(last_up_bi, len(up_sbi_list), last_up_bi.dir)
|
last_up_sbi = ChanSBI(last_up_bi, len(up_sbi_list), last_up_bi.dir)
|
||||||
up_sbi_list.append(last_up_sbi)
|
up_sbi_list.append(last_up_sbi)
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#up_sbi_list.append(last_up_sbi)
|
#up_sbi_list.append(last_up_sbi)
|
||||||
#print(last_up_bi.start_time, last_up_sbi.start_bi.start_time, "Reset up sbi list 2")
|
#print(last_up_bi.start_time, last_up_sbi.start_bi.start_time, "Reset up sbi list 2")
|
||||||
#print(bi.start_time, look_for_top, "UP 3")
|
#print(bi.start_time, look_for_top, "UP 3")
|
||||||
@@ -432,9 +434,11 @@ class ChanLun():
|
|||||||
up_sbi_list = []
|
up_sbi_list = []
|
||||||
last_up_sbi = ChanSBI(last_up_bi, len(up_sbi_list), last_up_bi.dir)
|
last_up_sbi = ChanSBI(last_up_bi, len(up_sbi_list), last_up_bi.dir)
|
||||||
up_sbi_list.append(last_up_sbi)
|
up_sbi_list.append(last_up_sbi)
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#up_sbi_list.append(last_up_sbi)
|
#up_sbi_list.append(last_up_sbi)
|
||||||
#print(last_up_bi.start_time, last_up_sbi.start_bi.start_time, "Reset up sbi list 3")
|
#print(last_up_bi.start_time, last_up_sbi.start_bi.start_time, "Reset up sbi list 3")
|
||||||
last_down_sbi = down_sbi
|
last_down_sbi = down_sbi
|
||||||
|
last_seg.add_bi(bi)
|
||||||
else:
|
else:
|
||||||
if len(down_sbi_list) == 1:
|
if len(down_sbi_list) == 1:
|
||||||
included = last_down_sbi.check_bi_included(bi)
|
included = last_down_sbi.check_bi_included(bi)
|
||||||
@@ -445,10 +449,12 @@ class ChanLun():
|
|||||||
down_sbi.set_pre(last_down_sbi)
|
down_sbi.set_pre(last_down_sbi)
|
||||||
down_sbi_list.append(down_sbi)
|
down_sbi_list.append(down_sbi)
|
||||||
last_down_sbi = down_sbi
|
last_down_sbi = down_sbi
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#print(bi.start_time, look_for_top, "UP 4")
|
#print(bi.start_time, look_for_top, "UP 4")
|
||||||
else:
|
else:
|
||||||
last_down_sbi = ChanSBI(bi, len(down_sbi_list), bi.dir)
|
last_down_sbi = ChanSBI(bi, len(down_sbi_list), bi.dir)
|
||||||
down_sbi_list.append(last_down_sbi)
|
down_sbi_list.append(last_down_sbi)
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#print(bi.start_time, look_for_top, "UP 5")
|
#print(bi.start_time, look_for_top, "UP 5")
|
||||||
else:
|
else:
|
||||||
if last_up_sbi:
|
if last_up_sbi:
|
||||||
@@ -460,6 +466,7 @@ class ChanLun():
|
|||||||
up_sbi.set_pre(last_up_sbi)
|
up_sbi.set_pre(last_up_sbi)
|
||||||
up_sbi_list.append(up_sbi)
|
up_sbi_list.append(up_sbi)
|
||||||
last_up_sbi = up_sbi
|
last_up_sbi = up_sbi
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#print(bi.start_time, look_for_top, "UP 6")
|
#print(bi.start_time, look_for_top, "UP 6")
|
||||||
# Last seg is down
|
# Last seg is down
|
||||||
else:
|
else:
|
||||||
@@ -492,6 +499,7 @@ class ChanLun():
|
|||||||
down_sbi_list = []
|
down_sbi_list = []
|
||||||
last_down_sbi = ChanSBI(last_down_bi, len(down_sbi_list), last_down_bi.dir)
|
last_down_sbi = ChanSBI(last_down_bi, len(down_sbi_list), last_down_bi.dir)
|
||||||
down_sbi_list.append(last_down_sbi)
|
down_sbi_list.append(last_down_sbi)
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#down_sbi_list.append(last_down_sbi)
|
#down_sbi_list.append(last_down_sbi)
|
||||||
#print(last_down_bi.start_time, last_down_sbi.start_bi.start_time, "Reset down sbi list 1")
|
#print(last_down_bi.start_time, last_down_sbi.start_bi.start_time, "Reset down sbi list 1")
|
||||||
#print(bi.start_time, look_for_top, "DOWN 2")
|
#print(bi.start_time, look_for_top, "DOWN 2")
|
||||||
@@ -504,6 +512,7 @@ class ChanLun():
|
|||||||
down_sbi_list = []
|
down_sbi_list = []
|
||||||
last_down_sbi = ChanSBI(last_down_bi, len(down_sbi_list), last_down_bi.dir)
|
last_down_sbi = ChanSBI(last_down_bi, len(down_sbi_list), last_down_bi.dir)
|
||||||
down_sbi_list.append(last_down_sbi)
|
down_sbi_list.append(last_down_sbi)
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#down_sbi_list.append(last_down_sbi)
|
#down_sbi_list.append(last_down_sbi)
|
||||||
#print(last_down_bi.start_time, last_down_sbi.start_bi.start_time, "Reset down sbi list 2")
|
#print(last_down_bi.start_time, last_down_sbi.start_bi.start_time, "Reset down sbi list 2")
|
||||||
#print(bi.start_time, look_for_top, "DOWN 3")
|
#print(bi.start_time, look_for_top, "DOWN 3")
|
||||||
@@ -519,9 +528,11 @@ class ChanLun():
|
|||||||
down_sbi_list = []
|
down_sbi_list = []
|
||||||
last_down_sbi = ChanSBI(last_down_bi, len(down_sbi_list), last_down_bi.dir)
|
last_down_sbi = ChanSBI(last_down_bi, len(down_sbi_list), last_down_bi.dir)
|
||||||
down_sbi_list.append(last_down_sbi)
|
down_sbi_list.append(last_down_sbi)
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#down_sbi_list.append(last_down_sbi)
|
#down_sbi_list.append(last_down_sbi)
|
||||||
#print(last_down_bi.start_time, last_down_sbi.start_bi.start_time, "Reset down sbi list 3")
|
#print(last_down_bi.start_time, last_down_sbi.start_bi.start_time, "Reset down sbi list 3")
|
||||||
last_up_sbi = up_sbi
|
last_up_sbi = up_sbi
|
||||||
|
last_seg.add_bi(bi)
|
||||||
else:
|
else:
|
||||||
if len(up_sbi_list) == 1:
|
if len(up_sbi_list) == 1:
|
||||||
#last_up_sbi = up_sbi_list[-1]
|
#last_up_sbi = up_sbi_list[-1]
|
||||||
@@ -533,10 +544,12 @@ class ChanLun():
|
|||||||
up_sbi.set_pre(last_up_sbi)
|
up_sbi.set_pre(last_up_sbi)
|
||||||
up_sbi_list.append(up_sbi)
|
up_sbi_list.append(up_sbi)
|
||||||
last_up_sbi = up_sbi
|
last_up_sbi = up_sbi
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#print(bi.start_time, look_for_top, "DOWN 4")
|
#print(bi.start_time, look_for_top, "DOWN 4")
|
||||||
else:
|
else:
|
||||||
last_up_sbi = ChanSBI(bi, len(up_sbi_list), bi.dir)
|
last_up_sbi = ChanSBI(bi, len(up_sbi_list), bi.dir)
|
||||||
up_sbi_list.append(last_up_sbi)
|
up_sbi_list.append(last_up_sbi)
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#print(bi.start_time, look_for_top, "DOWN 5")
|
#print(bi.start_time, look_for_top, "DOWN 5")
|
||||||
else:
|
else:
|
||||||
if last_down_sbi:
|
if last_down_sbi:
|
||||||
@@ -548,6 +561,7 @@ class ChanLun():
|
|||||||
down_sbi.set_pre(last_down_sbi)
|
down_sbi.set_pre(last_down_sbi)
|
||||||
down_sbi_list.append(down_sbi)
|
down_sbi_list.append(down_sbi)
|
||||||
last_down_sbi = down_sbi
|
last_down_sbi = down_sbi
|
||||||
|
last_seg.add_bi(bi)
|
||||||
#print(bi.start_time, look_for_top, look_for_bottom, "DOWN 6")
|
#print(bi.start_time, look_for_top, look_for_bottom, "DOWN 6")
|
||||||
# len(seg_list) = 0
|
# len(seg_list) = 0
|
||||||
else:
|
else:
|
||||||
@@ -572,13 +586,55 @@ class ChanLun():
|
|||||||
else:
|
else:
|
||||||
last_down_bi = bi
|
last_down_bi = bi
|
||||||
down_bi_list.append(bi)
|
down_bi_list.append(bi)
|
||||||
if len(seg_list) > 0:
|
if len(seg_list) > 1:
|
||||||
seg = seg_list[-1]
|
seg = seg_list[-1]
|
||||||
if seg.end_bi and len(bi_list) > seg.end_bi.index + 1:
|
last_seg = seg_list[-2]
|
||||||
bi_index = seg.end_bi.index
|
last_seg_bi = last_seg.bi_list[-3]
|
||||||
for index in range(bi_index+1, len(bi_list)):
|
bi_index = seg.start_bi.index
|
||||||
bi = bi_list[index]
|
for i in range(bi_index, len(bi_list) - 1):
|
||||||
|
# last seg is down
|
||||||
|
if seg.dir == Chan_SEG_DIR.UP:
|
||||||
|
if bi_list[i].dir == Chan_BI_DIR.UP:
|
||||||
|
last_seg_peak = last_seg_bi.high
|
||||||
|
if bi_list[i].high > last_seg_peak:
|
||||||
|
# The confirmed
|
||||||
|
print("Last UP seg is broken, create a new seg. 1")
|
||||||
|
seg.pre_set_end_bi(bi_list[i])
|
||||||
|
seg = ChanSEG(bi_list[i+1], len(seg_list), Chan_SEG_DIR.DOWN)
|
||||||
|
seg_list.append(seg)
|
||||||
|
last_seg = seg_list[-2]
|
||||||
|
if len(last_seg.bi_list) > 3:
|
||||||
|
last_seg_bi = last_seg.bi_list[-3]
|
||||||
|
|
||||||
|
else:
|
||||||
|
if bi_list[i].dir == Chan_BI_DIR.DOWN:
|
||||||
|
last_seg_peak = last_seg_bi.low
|
||||||
|
if bi_list[i].low < last_seg_peak:
|
||||||
|
print("Last DOWN seg is broken, create a new seg. 1")
|
||||||
|
seg.pre_set_end_bi(bi_list[i])
|
||||||
|
seg = ChanSEG(bi_list[i+1], len(seg_list), Chan_SEG_DIR.UP)
|
||||||
|
seg_list.append(seg)
|
||||||
|
last_seg = seg_list[-2]
|
||||||
|
if len(last_seg.bi_list) > 3:
|
||||||
|
last_seg_bi = last_seg.bi_list[-3]
|
||||||
|
else:
|
||||||
|
if len(seg_list) == 1:
|
||||||
|
last_seg = seg_list[-1]
|
||||||
|
bi_index = last_seg.bi_list[0].index
|
||||||
|
for i in range(bi_index, len(bi_list) - 1):
|
||||||
|
if i > bi_index + 2:
|
||||||
|
last_seg_peak = bi_list[i-2].high
|
||||||
|
# last seg is down
|
||||||
|
if last_seg.dir == Chan_SEG_DIR.DOWN:
|
||||||
|
if bi_list[i].dir == Chan_BI_DIR.UP:
|
||||||
|
if bi_list[i].high > last_seg_peak:
|
||||||
|
print("Last seg is broken, create a new seg. 2")
|
||||||
|
last_seg.pre_set_end_bi(bi_list[i-1])
|
||||||
|
seg = ChanSEG(bi_list[i], len(seg_list), Chan_SEG_DIR.UP)
|
||||||
|
seg_list.append(seg)
|
||||||
|
last_seg = seg
|
||||||
|
last_seg_bi = bi_list[i]
|
||||||
|
break
|
||||||
return seg_list
|
return seg_list
|
||||||
|
|
||||||
def get_bi_zs_list(self, bi_list):
|
def get_bi_zs_list(self, bi_list):
|
||||||
@@ -754,7 +810,7 @@ class ChanLun():
|
|||||||
bi_list.append(bi)
|
bi_list.append(bi)
|
||||||
last_top = klc
|
last_top = klc
|
||||||
klc.set_bi(bi)
|
klc.set_bi(bi)
|
||||||
#print(klc.start_time, bi.start_time, bi.end_time, bi.dir, bi.high, bi.low)
|
#print(klc.start_time, bi.start_time, bi.end_time, bi.dir, bi.high, bi.low, bi.is_sure)
|
||||||
else:
|
else:
|
||||||
if last_bottom and last_bi.dir == Chan_BI_DIR.UP:
|
if last_bottom and last_bi.dir == Chan_BI_DIR.UP:
|
||||||
if last_top and klc.low < last_bi.low:
|
if last_top and klc.low < last_bi.low:
|
||||||
@@ -767,7 +823,7 @@ class ChanLun():
|
|||||||
bi_list.append(bi)
|
bi_list.append(bi)
|
||||||
last_bottom = klc
|
last_bottom = klc
|
||||||
klc.set_bi(bi)
|
klc.set_bi(bi)
|
||||||
#print(klc.start_time, bi.start_time, bi.end_time, bi.dir, bi.high, bi.low)
|
#print(klc.start_time, bi.start_time, bi.end_time, bi.dir, bi.high, bi.low, bi.is_sure)
|
||||||
else:
|
else:
|
||||||
if fx == Chan_FX_TYPE.TOP:
|
if fx == Chan_FX_TYPE.TOP:
|
||||||
if last_top:
|
if last_top:
|
||||||
@@ -787,7 +843,7 @@ class ChanLun():
|
|||||||
last_top = klc
|
last_top = klc
|
||||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Change 1")
|
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Change 1")
|
||||||
klc.set_klc_fx_type(Chan_KLC_FX.TOP1)
|
klc.set_klc_fx_type(Chan_KLC_FX.TOP1)
|
||||||
print(klc.end_time, klc.fx, "一类卖点Sell 1")
|
#print(klc.end_time, klc.fx, "一类卖点Sell 1")
|
||||||
#klc.set_fx(fx)
|
#klc.set_fx(fx)
|
||||||
#klc.set_state("10")
|
#klc.set_state("10")
|
||||||
bi_list[-1].add_klc(klc)
|
bi_list[-1].add_klc(klc)
|
||||||
@@ -837,7 +893,7 @@ class ChanLun():
|
|||||||
bi.add_klc(klc)
|
bi.add_klc(klc)
|
||||||
bi_list.append(bi)
|
bi_list.append(bi)
|
||||||
last_top = klc
|
last_top = klc
|
||||||
print(klc.end_time, klc.fx, bi_list[-1].dir, "Last Top Change 2")
|
#print(klc.end_time, klc.fx, bi_list[-1].dir, "Last Top Change 2")
|
||||||
klc.set_klc_fx_type(Chan_KLC_FX.TOP2)
|
klc.set_klc_fx_type(Chan_KLC_FX.TOP2)
|
||||||
#klc.set_state('30')
|
#klc.set_state('30')
|
||||||
bi_list[-1].add_klc(klc)
|
bi_list[-1].add_klc(klc)
|
||||||
@@ -1132,7 +1188,7 @@ class ChanLun():
|
|||||||
if in_again and (bi.low > last_zs.zg or bi.high < last_zs.zd):
|
if in_again and (bi.low > last_zs.zg or bi.high < last_zs.zd):
|
||||||
last_zs.set_bi_out(bi, seg)
|
last_zs.set_bi_out(bi, seg)
|
||||||
last_zs.set_last_bi_in(bi_list[index - 1])
|
last_zs.set_last_bi_in(bi_list[index - 1])
|
||||||
last_zs.set_end_seg(seg.next.next)
|
#last_zs.set_end_seg(seg.next.next)
|
||||||
bi_out_count += 1
|
bi_out_count += 1
|
||||||
first_bi_out = bi
|
first_bi_out = bi
|
||||||
if (bi.dir == Chan_BI_DIR.UP and seg.dir == Chan_SEG_DIR.DOWN) or (bi.dir == Chan_BI_DIR.DOWN and seg.dir == Chan_SEG_DIR.UP):
|
if (bi.dir == Chan_BI_DIR.UP and seg.dir == Chan_SEG_DIR.DOWN) or (bi.dir == Chan_BI_DIR.DOWN and seg.dir == Chan_SEG_DIR.UP):
|
||||||
@@ -1168,7 +1224,7 @@ class ChanLun():
|
|||||||
if in_again and (bi.low > last_zs.zg or bi.high < last_zs.zd):
|
if in_again and (bi.low > last_zs.zg or bi.high < last_zs.zd):
|
||||||
last_zs.set_bi_out(bi, seg)
|
last_zs.set_bi_out(bi, seg)
|
||||||
last_zs.set_last_bi_in(bi_list[index - 1])
|
last_zs.set_last_bi_in(bi_list[index - 1])
|
||||||
last_zs.set_end_seg(seg.next.next)
|
#last_zs.set_end_seg(seg.next.next)
|
||||||
bi_out_count += 1
|
bi_out_count += 1
|
||||||
first_bi_out = bi
|
first_bi_out = bi
|
||||||
if (bi.dir == Chan_BI_DIR.UP and seg.dir == Chan_SEG_DIR.DOWN) or (bi.dir == Chan_BI_DIR.DOWN and seg.dir == Chan_SEG_DIR.UP):
|
if (bi.dir == Chan_BI_DIR.UP and seg.dir == Chan_SEG_DIR.DOWN) or (bi.dir == Chan_BI_DIR.DOWN and seg.dir == Chan_SEG_DIR.UP):
|
||||||
|
|||||||
+13
-1
@@ -43,6 +43,7 @@ class ChanSEG():
|
|||||||
self.end_time = bi.end_klc.end_time
|
self.end_time = bi.end_klc.end_time
|
||||||
if sure_bi.is_sure:
|
if sure_bi.is_sure:
|
||||||
self.sure_time = sure_bi.sure_time
|
self.sure_time = sure_bi.sure_time
|
||||||
|
self.format_bi_list()
|
||||||
def pre_set_end_bi(self, bi: ChanBI):
|
def pre_set_end_bi(self, bi: ChanBI):
|
||||||
self.end_bi = bi
|
self.end_bi = bi
|
||||||
if bi:
|
if bi:
|
||||||
@@ -51,6 +52,7 @@ class ChanSEG():
|
|||||||
else:
|
else:
|
||||||
self.low = bi.low
|
self.low = bi.low
|
||||||
self.end_time = bi.end_klc.end_time
|
self.end_time = bi.end_klc.end_time
|
||||||
|
self.format_bi_list()
|
||||||
def set_pre(self, seg):
|
def set_pre(self, seg):
|
||||||
self.pre = seg
|
self.pre = seg
|
||||||
def set_next(self, seg):
|
def set_next(self, seg):
|
||||||
@@ -59,6 +61,16 @@ class ChanSEG():
|
|||||||
if sure_bi.is_sure:
|
if sure_bi.is_sure:
|
||||||
self.sure_time = sure_bi.sure_time
|
self.sure_time = sure_bi.sure_time
|
||||||
self.is_sure = True
|
self.is_sure = True
|
||||||
|
self.format_bi_list()
|
||||||
|
def format_bi_list(self):
|
||||||
|
bi_list = []
|
||||||
|
bi_list.append(self.start_bi)
|
||||||
|
if self.end_bi:
|
||||||
|
next_bi = self.start_bi.next
|
||||||
|
for i in range(self.start_bi.index, self.end_bi.index):
|
||||||
|
if next_bi:
|
||||||
|
self.bi_list.append(next_bi)
|
||||||
|
next_bi = next_bi.next
|
||||||
def add_bi(self, bi: ChanBI):
|
def add_bi(self, bi: ChanBI):
|
||||||
if len(self.bi_list) > 1:
|
if len(self.bi_list) > 0:
|
||||||
self.bi_list.append(bi)
|
self.bi_list.append(bi)
|
||||||
Reference in New Issue
Block a user