添加笔中枢,删除了很多没有用的方法
This commit is contained in:
+107
-6
@@ -1,12 +1,12 @@
|
||||
import copy
|
||||
from typing import Dict, Optional
|
||||
|
||||
from ChanEnum import Chan_FX_TYPE, Chan_KLINE_DIR, Chan_SEG_DIR
|
||||
import ChanKLU
|
||||
from ChanEnum import Chan_FX_TYPE, Chan_KLINE_DIR, Chan_SEG_DIR, Chan_BI_DIR, Chan_ZS_DIR
|
||||
import ChanCTime
|
||||
from ChanBI import ChanBI
|
||||
from ChanBIZS import ChanBIZS
|
||||
class ChanSEG():
|
||||
def __init__(self, start_bi: ChanBI, index, ddir=Chan_SEG_DIR.UP):
|
||||
def __init__(self, start_bi: ChanBI, index, ddir=Chan_SEG_DIR.UP, pre_end_bi: ChanBI = None):
|
||||
self.start_bi = start_bi
|
||||
self.start_time = start_bi.start_time
|
||||
self.end_time = None
|
||||
@@ -28,6 +28,17 @@ class ChanSEG():
|
||||
self.sure_time = None
|
||||
self.macd_hist = 0
|
||||
self.macd_div = 0
|
||||
self.start_bi.set_seg(self)
|
||||
self.pre_end_bi = pre_end_bi
|
||||
if self.pre_end_bi:
|
||||
self.ini_seg()
|
||||
def ini_seg(self):
|
||||
next_bi = self.start_bi.next
|
||||
for index in range(self.start_bi.index+1, self.pre_end_bi.index):
|
||||
if next_bi:
|
||||
self.bi_list.append(next_bi)
|
||||
next_bi.set_seg(self)
|
||||
next_bi = next_bi.next
|
||||
def set_macdhist(self, macd_hist):
|
||||
self.macd_hist = macd_hist
|
||||
def set_macd_div(self, macd_div):
|
||||
@@ -63,14 +74,104 @@ class ChanSEG():
|
||||
self.is_sure = True
|
||||
self.format_bi_list()
|
||||
def format_bi_list(self):
|
||||
bi_list = []
|
||||
bi_list.append(self.start_bi)
|
||||
self.bi_list = []
|
||||
self.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.set_seg(self)
|
||||
next_bi = next_bi.next
|
||||
def add_bi(self, bi: ChanBI):
|
||||
if len(self.bi_list) > 0:
|
||||
self.bi_list.append(bi)
|
||||
self.bi_list.append(bi)
|
||||
bi.set_seg(self)
|
||||
def cal_bi_zs(self):
|
||||
zs_list = []
|
||||
if len(self.bi_list) > 3:
|
||||
last_zs = None
|
||||
zs_count = 0
|
||||
if self.dir == Chan_SEG_DIR.UP:
|
||||
for index in range(1, len(self.bi_list)):
|
||||
bi = self.bi_list[index]
|
||||
if len(zs_list) == 0 or (last_zs and last_zs.is_sure):
|
||||
if bi.next and bi.next.next and bi.next.next.is_sure and bi.check_bi_zs_overlap() and bi.dir == Chan_BI_DIR.DOWN:
|
||||
zg = min(bi.high, bi.next.high, bi.next.next.high)
|
||||
zd = max(bi.low, bi.next.low, bi.next.next.low)
|
||||
gg = max(bi.high, bi.next.high, bi.next.next.high)
|
||||
dd = min(bi.low, bi.next.low, bi.next.next.low)
|
||||
zs = ChanBIZS(bi, len(zs_list), Chan_ZS_DIR.UP)
|
||||
zs.set_zg(zg)
|
||||
zs.set_zd(zd)
|
||||
zs.set_gg(gg)
|
||||
zs.set_dd(dd)
|
||||
zs.add_bi(bi.next)
|
||||
zs.add_bi(bi.next.next)
|
||||
zs_list.append(zs)
|
||||
last_zs = zs
|
||||
else:
|
||||
if bi.index > last_zs.bi_list[-1].index and bi.dir == Chan_BI_DIR.DOWN and bi.is_sure:
|
||||
if bi.low < last_zs.zg:
|
||||
last_zs.add_bi(bi.pre)
|
||||
last_zs.add_bi(bi)
|
||||
else:
|
||||
last_zs.set_end_bi(last_zs.bi_list[-1], bi)
|
||||
if bi.next and bi.next.next and bi.next.next.is_sure and bi.next.next.index <= self.bi_list[-1].index and bi.check_bi_zs_overlap() and bi.dir == Chan_BI_DIR.DOWN:
|
||||
zg = min(bi.high, bi.next.high, bi.next.next.high)
|
||||
zd = max(bi.low, bi.next.low, bi.next.next.low)
|
||||
gg = max(bi.high, bi.next.high, bi.next.next.high)
|
||||
dd = min(bi.low, bi.next.low, bi.next.next.low)
|
||||
zs = ChanBIZS(bi, len(zs_list), Chan_ZS_DIR.UP)
|
||||
zs.set_zg(zg)
|
||||
zs.set_zd(zd)
|
||||
zs.set_gg(gg)
|
||||
zs.set_dd(dd)
|
||||
zs.add_bi(bi.next)
|
||||
zs.add_bi(bi.next.next)
|
||||
zs_list.append(zs)
|
||||
last_zs = zs
|
||||
else:
|
||||
for index in range(1, len(self.bi_list)):
|
||||
bi = self.bi_list[index]
|
||||
if len(zs_list) == 0 or (last_zs and last_zs.is_sure):
|
||||
if bi.next and bi.next.next and bi.next.next.is_sure and bi.check_bi_zs_overlap() and bi.dir == Chan_BI_DIR.UP:
|
||||
zg = min(bi.high, bi.next.high, bi.next.next.high)
|
||||
zd = max(bi.low, bi.next.low, bi.next.next.low)
|
||||
gg = max(bi.high, bi.next.high, bi.next.next.high)
|
||||
dd = min(bi.low, bi.next.low, bi.next.next.low)
|
||||
zs = ChanBIZS(bi, len(zs_list), Chan_ZS_DIR.DOWN)
|
||||
zs.set_zg(zg)
|
||||
zs.set_zd(zd)
|
||||
zs.set_gg(gg)
|
||||
zs.set_dd(dd)
|
||||
zs.add_bi(bi.next)
|
||||
zs.add_bi(bi.next.next)
|
||||
zs_list.append(zs)
|
||||
last_zs = zs
|
||||
else:
|
||||
if bi.index > last_zs.bi_list[-1].index and bi.dir == Chan_BI_DIR.UP and bi.is_sure:
|
||||
if bi.high > last_zs.zd:
|
||||
last_zs.add_bi(bi.pre)
|
||||
last_zs.add_bi(bi)
|
||||
else:
|
||||
last_zs.set_end_bi(last_zs.bi_list[-1], bi)
|
||||
if bi.next and bi.next.next and bi.next.next.is_sure and bi.next.next.index <= self.bi_list[-1].index and bi.check_bi_zs_overlap() and bi.dir == Chan_BI_DIR.UP:
|
||||
zg = min(bi.high, bi.next.high, bi.next.next.high)
|
||||
zd = max(bi.low, bi.next.low, bi.next.next.low)
|
||||
gg = max(bi.high, bi.next.high, bi.next.next.high)
|
||||
dd = min(bi.low, bi.next.low, bi.next.next.low)
|
||||
zs = ChanBIZS(bi, len(zs_list), Chan_ZS_DIR.DOWN)
|
||||
zs.set_zg(zg)
|
||||
zs.set_zd(zd)
|
||||
zs.set_gg(gg)
|
||||
zs.set_dd(dd)
|
||||
zs.add_bi(bi.next)
|
||||
zs.add_bi(bi.next.next)
|
||||
zs_list.append(zs)
|
||||
last_zs = zs
|
||||
if index == len(self.bi_list) - 1 and last_zs and not last_zs.is_sure:
|
||||
last_zs.set_end_bi(last_zs.bi_list[-1], last_zs.bi_list[-1])
|
||||
#print(self.start_time, len(zs_list))
|
||||
print(self.bi_list[-1].end_time, "end_bi")
|
||||
return zs_list
|
||||
Reference in New Issue
Block a user