添加背离计算
This commit is contained in:
+59
-11
@@ -1,8 +1,9 @@
|
||||
from ChanEnum import Chan_MACD_STATE, Chan_MACDUNITTF_DIR, Chan_MACDHISTSET_DIR
|
||||
from ChanEnum import Chan_MACD_STATE, Chan_MACDUNITTF_DIR, Chan_MACDHISTSET_DIR, Chan_MACDUNITTF_DIV
|
||||
|
||||
|
||||
class ChanMACDUnitTF():
|
||||
def __init__(self, start_time, start_klu, pre_unittf, dir, start_type):
|
||||
def __init__(self, index, start_time, start_klu, pre_unittf, dir, start_type, start_histset):
|
||||
self.index = index
|
||||
self.start_time = start_time
|
||||
self.end_time = None
|
||||
self.start_klu = start_klu
|
||||
@@ -10,13 +11,19 @@ class ChanMACDUnitTF():
|
||||
self.klu_list = []
|
||||
self.klu_list.append(start_klu)
|
||||
self.histset_list = []
|
||||
self.histset_list.append(start_histset)
|
||||
self.div_count = 0
|
||||
start_histset.set_middle_klu(start_klu)
|
||||
self.next = None
|
||||
self.pre = pre_unittf
|
||||
self.unittf_dir = dir
|
||||
self.start_type = start_type
|
||||
self.end_type = None
|
||||
self.near0_count = 1
|
||||
self.peak_klu = None
|
||||
self.div_type = Chan_MACDUNITTF_DIV.UNDIV
|
||||
self.div_peak_list = []
|
||||
self.div_low_list = []
|
||||
self.rev_low_klu = None
|
||||
def set_next(self, next_unittf):
|
||||
self.next = next_unittf
|
||||
def add_histset(self, histset):
|
||||
@@ -25,21 +32,62 @@ class ChanMACDUnitTF():
|
||||
self.klu_list.append(klu)
|
||||
self.cal_peak_div()
|
||||
def cal_peak_div(self):
|
||||
self.div_count = 0
|
||||
self.div_peak_list = []
|
||||
self.div_low_list = []
|
||||
self.rev_low_klu = None
|
||||
self.peak_klu = None
|
||||
if len(self.histset_list) == 0:
|
||||
return
|
||||
if len(self.histset_list) == 1:
|
||||
self.peak_klu = self.histset_list[0].find_peak_from(self.start_klu)
|
||||
self.div_type = self.histset_list[0].unittf_div
|
||||
self.peak_klu = self.histset_list[0].peak_klu
|
||||
else:
|
||||
for histset in self.histset_list:
|
||||
if histset.peak_klu and self.peak_klu:
|
||||
if abs(histset.peak_klu.macdhist) > abs(self.peak_klu.macdhist):
|
||||
self.peak_klu = histset.peak_klu
|
||||
for index in range(0, len(self.histset_list)):
|
||||
histset = self.histset_list[index]
|
||||
if self.same_dir(histset):
|
||||
if self.peak_klu:
|
||||
if histset.peak_klu and histset.end_time:
|
||||
if abs(histset.peak_klu.macdhist) >= abs(self.peak_klu.macdhist):
|
||||
self.peak_klu = histset.peak_klu
|
||||
self.div_type = Chan_MACDUNITTF_DIV.UNDIV
|
||||
self.div_count = 0
|
||||
else:
|
||||
self.div_type = Chan_MACDUNITTF_DIV.DISCRETE
|
||||
self.div_count += 1
|
||||
self.div_peak_list.append(histset.peak_klu)
|
||||
else:
|
||||
histset.set_unittf_div(True)
|
||||
if histset.peak_klu:
|
||||
self.peak_klu = histset.peak_klu
|
||||
else:
|
||||
if self.rev_low_klu:
|
||||
if histset.low_klu:
|
||||
if abs(histset.low_klu.macdhist) < abs(self.rev_low_klu.macdhist):
|
||||
self.rev_low_klu = histset.low_klu
|
||||
self.div_low_list.append(histset.low_klu)
|
||||
else:
|
||||
if histset.low_klu:
|
||||
self.rev_low_klu = histset.low_klu
|
||||
self.div_low_list.append(histset.low_klu)
|
||||
def same_dir(self, histset):
|
||||
if self.unittf_dir == Chan_MACDUNITTF_DIR.ABOVE:
|
||||
return histset.histset_dir == Chan_MACDHISTSET_DIR.ABOVE
|
||||
else:
|
||||
return histset.histset_dir == Chan_MACDHISTSET_DIR.UNDER
|
||||
def set_end_klu(self, end_klu, end_type):
|
||||
self.add_klu(end_klu)
|
||||
self.end_type = end_type
|
||||
self.end_klu = end_klu
|
||||
self.end_time = end_klu.time
|
||||
div_time = ""
|
||||
for div in self.div_peak_list:
|
||||
div_time += f"{div.time}, "
|
||||
histset_time = ""
|
||||
for histset in self.histset_list:
|
||||
histset_time += f"{histset.start_time}, "
|
||||
|
||||
if self.peak_klu:
|
||||
print(self.start_klu.time, self.peak_klu.time)
|
||||
print(self.index, self.start_klu.time, self.peak_klu.time, self.div_count, self.div_type, div_time, len(self.histset_list))
|
||||
else:
|
||||
print("None", len(self.histset_list))
|
||||
print(self.index, "None", len(self.histset_list))
|
||||
|
||||
Reference in New Issue
Block a user