[update] K线

This commit is contained in:
msincenselee 2021-04-14 16:04:15 +08:00
parent ed3320d7c5
commit a265deb3a1
2 changed files with 770 additions and 377 deletions

View File

@ -493,13 +493,13 @@ class CtaLineBar(object):
self.line_pre_high = [] # K线的前para_pre_len的的最高 self.line_pre_high = [] # K线的前para_pre_len的的最高
self.line_pre_low = [] # K线的前para_pre_len的的最低 self.line_pre_low = [] # K线的前para_pre_len的的最低
# 唐其安高点、低点清单(相当于缠论的分型) # 唐其安高点、低点清单(相当于缠论的分型)
self.tqn_high_list = [] # 所有的创新高的高点(分型)清单 { "price":xxx, "datetime": "yyyy-mm-dd HH:MM:SS"} self.tqa_high_list = [] # 所有的创新高的高点(分型)清单 { "price":xxx, "datetime": "yyyy-mm-dd HH:MM:SS"}
self.tqn_low_list = [] # 所有的创新低的低点(分型)清单 { "price":xxx, "datetime": "yyyy-mm-dd HH:MM:SS"} self.tqa_low_list = [] # 所有的创新低的低点(分型)清单 { "price":xxx, "datetime": "yyyy-mm-dd HH:MM:SS"}
# 唐其安笔清单,相当与缠论的笔,最后一笔是未完成的 # 唐其安笔清单,相当与缠论的笔,最后一笔是未完成的
self.tqn_bi_list = [] self.tqa_bi_list = []
# 唐其安中枢清单,相当于缠论的中枢 # 唐其安中枢清单,相当于缠论的中枢
self.cur_tqn_zs = {} # 当前唐其安中枢。 self.cur_tqa_zs = {} # 当前唐其安中枢。
self.tqn_zs_list = [] self.tqa_zs_list = []
self.line_ma1 = [] # K线的MA(para_ma1_len)均线不包含未走完的bar self.line_ma1 = [] # K线的MA(para_ma1_len)均线不包含未走完的bar
self.line_ma2 = [] # K线的MA(para_ma2_len)均线不包含未走完的bar self.line_ma2 = [] # K线的MA(para_ma2_len)均线不包含未走完的bar
@ -1462,35 +1462,35 @@ class CtaLineBar(object):
if len(self.line_macd) > 0: if len(self.line_macd) > 0:
d.update({'macd': self.line_macd[-1]}) d.update({'macd': self.line_macd[-1]})
# 当前不存在最后的高点,创建一个 # 当前不存在最后的高点,创建一个
if len(self.tqn_high_list) == 0: if len(self.tqa_high_list) == 0:
self.tqn_high_list.append(d) self.tqa_high_list.append(d)
return return
# 如果存在最后的高点,最后的低点 # 如果存在最后的高点,最后的低点
last_low_time = self.tqn_low_list[-1].get('datetime', None) if len(self.tqn_low_list) > 0 else None last_low_time = self.tqa_low_list[-1].get('datetime', None) if len(self.tqa_low_list) > 0 else None
last_high_time = self.tqn_high_list[-1].get('datetime', None) if len( last_high_time = self.tqa_high_list[-1].get('datetime', None) if len(
self.tqn_high_list) > 0 else None self.tqa_high_list) > 0 else None
last_high_price = self.tqn_high_list[-1].get('price') if len( last_high_price = self.tqa_high_list[-1].get('price') if len(
self.tqn_high_list) > 0 else None self.tqa_high_list) > 0 else None
# 低点的时间,比高点的时间更晚, 添加一个新的高点 # 低点的时间,比高点的时间更晚, 添加一个新的高点
if last_low_time is not None and last_high_time is not None and last_high_time < last_low_time: if last_low_time is not None and last_high_time is not None and last_high_time < last_low_time:
# 添加一个新的高点 # 添加一个新的高点
self.tqn_high_list.append(d) self.tqa_high_list.append(d)
# 创建一个未走完的笔,低点-> 高点 # 创建一个未走完的笔,低点-> 高点
self.create_tqn_bi(direction=Direction.LONG) self.create_tqa_bi(direction=Direction.LONG)
# 输出确定的一笔(高点->低点) =>csv文件 # 输出确定的一笔(高点->低点) =>csv文件
self.export_tqn_bi() self.export_tqa_bi()
# 计算是否有中枢 # 计算是否有中枢
self.update_tqn_zs() self.update_tqa_zs()
return return
# 延续当前的高点 # 延续当前的高点
if pre_high > last_high_price: if pre_high > last_high_price:
self.tqn_high_list[-1].update(d) self.tqa_high_list[-1].update(d)
self.update_tnq_bi(point=d, direction=Direction.LONG) self.update_tnq_bi(point=d, direction=Direction.LONG)
# 计算是否有中枢 # 计算是否有中枢
self.update_tqn_zs() self.update_tqa_zs()
# 产生新得低点 # 产生新得低点
if pre_low < self.line_pre_low[-2] and pre_high == self.line_pre_high[-2]: if pre_low < self.line_pre_low[-2] and pre_high == self.line_pre_high[-2]:
@ -1505,38 +1505,38 @@ class CtaLineBar(object):
d.update({'macd': self.line_macd[-1]}) d.update({'macd': self.line_macd[-1]})
# 当前不存在最后的低点,创建一个 # 当前不存在最后的低点,创建一个
if len(self.tqn_low_list) == 0: if len(self.tqa_low_list) == 0:
self.tqn_low_list.append(d) self.tqa_low_list.append(d)
return return
# 如果存在最后的高点,最后的低点 # 如果存在最后的高点,最后的低点
last_low_time = self.tqn_low_list[-1].get('datetime', None) if len( last_low_time = self.tqa_low_list[-1].get('datetime', None) if len(
self.tqn_low_list) > 0 else None self.tqa_low_list) > 0 else None
last_high_time = self.tqn_high_list[-1].get('datetime', None) if len( last_high_time = self.tqa_high_list[-1].get('datetime', None) if len(
self.tqn_high_list) > 0 else None self.tqa_high_list) > 0 else None
last_low_price = self.tqn_low_list[-1].get('price', None) if len( last_low_price = self.tqa_low_list[-1].get('price', None) if len(
self.tqn_low_list) > 0 else None self.tqa_low_list) > 0 else None
# 高点的时间,比低点的时间更晚, 添加一个新的低点 # 高点的时间,比低点的时间更晚, 添加一个新的低点
if last_low_time is not None and last_high_time is not None and last_low_time < last_high_time: if last_low_time is not None and last_high_time is not None and last_low_time < last_high_time:
# 添加一个新的低点 # 添加一个新的低点
self.tqn_low_list.append(d) self.tqa_low_list.append(d)
# 创建一个未走完的笔, 高点->低点 # 创建一个未走完的笔, 高点->低点
self.create_tqn_bi(direction=Direction.SHORT) self.create_tqa_bi(direction=Direction.SHORT)
# 输出确定的一笔(低点->高点) =>csv文件 # 输出确定的一笔(低点->高点) =>csv文件
self.export_tqn_bi() self.export_tqa_bi()
# 计算是否有中枢 # 计算是否有中枢
self.update_tqn_zs() self.update_tqa_zs()
return return
# 延续当前的低点 # 延续当前的低点
if pre_low < last_low_price: if pre_low < last_low_price:
self.tqn_low_list[-1].update(d) self.tqa_low_list[-1].update(d)
self.update_tnq_bi(point=d, direction=Direction.SHORT) self.update_tnq_bi(point=d, direction=Direction.SHORT)
# 计算是否有中枢 # 计算是否有中枢
self.update_tqn_zs() self.update_tqa_zs()
def create_tqn_bi(self, direction): def create_tqa_bi(self, direction):
""" """
创建唐其安的笔该笔未走完的 创建唐其安的笔该笔未走完的
:param direction: 笔的方向 direction Direction.Long, Direction.Short :param direction: 笔的方向 direction Direction.Long, Direction.Short
@ -1548,15 +1548,15 @@ class CtaLineBar(object):
else: else:
direction = -1 direction = -1
if len(self.tqn_bi_list) > self.max_hold_bars: # 维持最大缓存数量 超过则删除最前面 if len(self.tqa_bi_list) > self.max_hold_bars: # 维持最大缓存数量 超过则删除最前面
del self.tqn_bi_list[0] del self.tqa_bi_list[0]
# 从低=>高得线段, self.line_low_list[-1] => self.line_high_list[-1] # 从低=>高得线段, self.line_low_list[-1] => self.line_high_list[-1]
if direction == 1: if direction == 1:
if len(self.tqn_low_list) < 1: if len(self.tqa_low_list) < 1:
return return
low_point = self.tqn_low_list[-1] low_point = self.tqa_low_list[-1]
high_point = self.tqn_high_list[-1] high_point = self.tqa_high_list[-1]
d = { d = {
"start": low_point.get('datetime'), "start": low_point.get('datetime'),
"end": high_point.get('datetime'), "end": high_point.get('datetime'),
@ -1565,14 +1565,14 @@ class CtaLineBar(object):
"high": high_point.get('price'), "high": high_point.get('price'),
"low": low_point.get('price') "low": low_point.get('price')
} }
self.tqn_bi_list.append(d) self.tqa_bi_list.append(d)
# 从高=>低得线段, self.line_high_list[-1] => self.line_low_list[-1] # 从高=>低得线段, self.line_high_list[-1] => self.line_low_list[-1]
else: else:
if len(self.tqn_high_list) < 1: if len(self.tqa_high_list) < 1:
return return
high_point = self.tqn_high_list[-1] high_point = self.tqa_high_list[-1]
low_point = self.tqn_low_list[-1] low_point = self.tqa_low_list[-1]
d = { d = {
"start": high_point.get('datetime'), "start": high_point.get('datetime'),
"end": low_point.get('datetime'), "end": low_point.get('datetime'),
@ -1581,7 +1581,7 @@ class CtaLineBar(object):
"high": high_point.get('price'), "high": high_point.get('price'),
"low": low_point.get('price') "low": low_point.get('price')
} }
self.tqn_bi_list.append(d) self.tqa_bi_list.append(d)
def update_tnq_bi(self, point, direction): def update_tnq_bi(self, point, direction):
""" """
@ -1590,7 +1590,7 @@ class CtaLineBar(object):
:param direction: :param direction:
:return: :return:
""" """
if len(self.tqn_bi_list) < 1: if len(self.tqa_bi_list) < 1:
return return
# Direction => int # Direction => int
@ -1599,7 +1599,7 @@ class CtaLineBar(object):
else: else:
direction = -1 direction = -1
bi = self.tqn_bi_list[-1] bi = self.tqa_bi_list[-1]
if bi.get('direction') != direction: if bi.get('direction') != direction:
return return
# 方向为多 # 方向为多
@ -1617,7 +1617,7 @@ class CtaLineBar(object):
"low": point.get('price'), "low": point.get('price'),
}) })
def export_tqn_bi(self): def export_tqa_bi(self):
""" """
唐其安高点低点形成的笔输出.csv文件 唐其安高点低点形成的笔输出.csv文件
start.end,direction,height,high,low start.end,direction,height,high,low
@ -1628,12 +1628,12 @@ class CtaLineBar(object):
if self.export_tqa_bi_filename is None: if self.export_tqa_bi_filename is None:
return return
if len(self.tqn_bi_list) < 2: if len(self.tqa_bi_list) < 2:
return return
# 直接插入倒数第二条记录,即已经走完的笔 # 直接插入倒数第二条记录,即已经走完的笔
self.append_data(file_name=self.export_tqa_bi_filename, self.append_data(file_name=self.export_tqa_bi_filename,
dict_data=self.tqn_bi_list[-2], dict_data=self.tqa_bi_list[-2],
field_names=["start", "end", "direction", "height", "high", "low"] field_names=["start", "end", "direction", "height", "high", "low"]
) )
@ -1645,10 +1645,10 @@ class CtaLineBar(object):
# #
# 从低=>高得线段, self.line_low_list[-2] => self.line_high_list[-1] # 从低=>高得线段, self.line_low_list[-2] => self.line_high_list[-1]
# if direction == 1: # if direction == 1:
# if len(self.tqn_low_list) < 2: # if len(self.tqa_low_list) < 2:
# return # return
# low_point = self.tqn_low_list[-2] # low_point = self.tqa_low_list[-2]
# high_point = self.tqn_high_list[-1] # high_point = self.tqa_high_list[-1]
# d = { # d = {
# "start": low_point.get('datetime'), # "start": low_point.get('datetime'),
# "end": high_point.get('datetime'), # "end": high_point.get('datetime'),
@ -1657,7 +1657,7 @@ class CtaLineBar(object):
# "high": high_point.get('price'), # "high": high_point.get('price'),
# "low": low_point.get('price') # "low": low_point.get('price')
# } # }
# if len(self.tqn_bi_list) < 2: # if len(self.tqa_bi_list) < 2:
# return # return
# #
# self.append_data(file_name=self.export_bi_filename, # self.append_data(file_name=self.export_bi_filename,
@ -1666,10 +1666,10 @@ class CtaLineBar(object):
# ) # )
# 从高=>低得线段, self.line_high_list[-2] => self.line_low_list[-1] # 从高=>低得线段, self.line_high_list[-2] => self.line_low_list[-1]
# else: # else:
# if len(self.tqn_high_list) < 2: # if len(self.tqa_high_list) < 2:
# return # return
# high_point = self.tqn_high_list[-2] # high_point = self.tqa_high_list[-2]
# low_point = self.tqn_low_list[-1] # low_point = self.tqa_low_list[-1]
# d = { # d = {
# "start": high_point.get('datetime'), # "start": high_point.get('datetime'),
# "end": low_point.get('datetime'), # "end": low_point.get('datetime'),
@ -1683,7 +1683,7 @@ class CtaLineBar(object):
# field_names=["start", "end", "direction", "height", "high", "low"] # field_names=["start", "end", "direction", "height", "high", "low"]
# ) # )
def update_tqn_zs(self): def update_tqa_zs(self):
""" """
更新唐其安中枢 更新唐其安中枢
这里跟缠论的中枢不同主要根据最后一笔判断是否与前2前三形成中枢 这里跟缠论的中枢不同主要根据最后一笔判断是否与前2前三形成中枢
@ -1692,19 +1692,19 @@ class CtaLineBar(object):
如果形成更新如果不形成则剔除 如果形成更新如果不形成则剔除
:return: :return:
""" """
if len(self.tqn_bi_list) < 4: if len(self.tqa_bi_list) < 4:
return return
cur_bi = self.tqn_bi_list[-1] # 当前笔 cur_bi = self.tqa_bi_list[-1] # 当前笔
second_bi = self.tqn_bi_list[-2] # 倒数第二笔 second_bi = self.tqa_bi_list[-2] # 倒数第二笔
third_bi = self.tqn_bi_list[-3] # 倒数第三笔 third_bi = self.tqa_bi_list[-3] # 倒数第三笔
four_bi = self.tqn_bi_list[-4] # 倒数第四笔 four_bi = self.tqa_bi_list[-4] # 倒数第四笔
# 当前笔的方向 # 当前笔的方向
direction = cur_bi.get('direction') direction = cur_bi.get('direction')
# 当前没有中枢 # 当前没有中枢
if len(self.cur_tqn_zs) == 0: if len(self.cur_tqa_zs) == 0:
# 1,3 的重叠的线段 # 1,3 的重叠的线段
first_third_high = min(third_bi.get('high'), cur_bi.get('high')) first_third_high = min(third_bi.get('high'), cur_bi.get('high'))
first_third_low = max(third_bi.get('low'), cur_bi.get('low')) first_third_low = max(third_bi.get('low'), cur_bi.get('low'))
@ -1716,7 +1716,7 @@ class CtaLineBar(object):
# 上涨中 1-32-4 形成重叠 # 上涨中 1-32-4 形成重叠
if second_four_low <= first_third_low < second_four_high <= first_third_high: if second_four_low <= first_third_low < second_four_high <= first_third_high:
# 中枢的方向按照第四笔 # 中枢的方向按照第四笔
self.cur_tqn_zs = { self.cur_tqa_zs = {
"direction": four_bi.get('direction'), # 段的方向:进入笔的方向 "direction": four_bi.get('direction'), # 段的方向:进入笔的方向
"start": four_bi.get('end'), # zs的开始 "start": four_bi.get('end'), # zs的开始
"end": cur_bi.get("end"), # zs的结束时间 "end": cur_bi.get("end"), # zs的结束时间
@ -1728,15 +1728,15 @@ class CtaLineBar(object):
"exit_start": cur_bi.get('start') "exit_start": cur_bi.get('start')
} }
# 更新中枢高度 # 更新中枢高度
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"height": self.cur_tqn_zs.get('high') - self.cur_tqn_zs.get('low') "height": self.cur_tqa_zs.get('high') - self.cur_tqa_zs.get('low')
}) })
return return
# 下跌中 1-32-4 形成重叠 # 下跌中 1-32-4 形成重叠
if first_third_low <= second_four_low < first_third_high <= second_four_high: if first_third_low <= second_four_low < first_third_high <= second_four_high:
# 中枢的方向按照第四笔 # 中枢的方向按照第四笔
self.cur_tqn_zs = { self.cur_tqa_zs = {
"direction": four_bi.get('direction'), # 段的方向:进入笔的方向 "direction": four_bi.get('direction'), # 段的方向:进入笔的方向
"start": four_bi.get('end'), # zs的开始 "start": four_bi.get('end'), # zs的开始
"end": cur_bi.get("end"), # zs的结束时间 "end": cur_bi.get("end"), # zs的结束时间
@ -1748,8 +1748,8 @@ class CtaLineBar(object):
"exit_start": cur_bi.get('start') "exit_start": cur_bi.get('start')
} }
# 更新中枢高度 # 更新中枢高度
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"height": self.cur_tqn_zs.get('high') - self.cur_tqn_zs.get('low') "height": self.cur_tqa_zs.get('high') - self.cur_tqa_zs.get('low')
}) })
return return
@ -1757,112 +1757,112 @@ class CtaLineBar(object):
# 当前存在中枢 # 当前存在中枢
# 最后一笔是多,且低点在中枢高点上方,中枢确认结束 # 最后一笔是多,且低点在中枢高点上方,中枢确认结束
if direction == 1 and cur_bi.get('low') > self.cur_tqn_zs.get('high'): if direction == 1 and cur_bi.get('low') > self.cur_tqa_zs.get('high'):
self.export_tqa_zs() self.export_tqa_zs()
self.cur_tqn_zs = {} self.cur_tqa_zs = {}
return return
# 最后一笔是空,且高点在中枢下方,中枢确认结束 # 最后一笔是空,且高点在中枢下方,中枢确认结束
if direction == -1 and cur_bi.get('high') < self.cur_tqn_zs.get('low'): if direction == -1 and cur_bi.get('high') < self.cur_tqa_zs.get('low'):
self.export_tqa_zs() self.export_tqa_zs()
self.cur_tqn_zs = {} self.cur_tqa_zs = {}
return return
# 当前笔是zs的最后一笔 # 当前笔是zs的最后一笔
if cur_bi.get("start") == self.cur_tqn_zs.get("exit_start"): if cur_bi.get("start") == self.cur_tqa_zs.get("exit_start"):
# 当前笔是做多,判断是否创新高 # 当前笔是做多,判断是否创新高
if direction == 1: if direction == 1:
# 对比中枢之前所有的确认高点,不能超过 # 对比中枢之前所有的确认高点,不能超过
zs_highs = self.cur_tqn_zs.get("highs", [self.cur_tqn_zs.get('high')]) zs_highs = self.cur_tqa_zs.get("highs", [self.cur_tqa_zs.get('high')])
min_high = min(zs_highs) min_high = min(zs_highs)
new_high = min(min_high, cur_bi.get('high')) new_high = min(min_high, cur_bi.get('high'))
# 当前笔的高度为最短,在生长,则更新中枢的结束时间和高度 # 当前笔的高度为最短,在生长,则更新中枢的结束时间和高度
if min_high >= new_high > self.cur_tqn_zs.get('high'): if min_high >= new_high > self.cur_tqa_zs.get('high'):
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"end": cur_bi.get('end'), "end": cur_bi.get('end'),
"high": new_high}) "high": new_high})
# 更新中枢高度 # 更新中枢高度
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"height": self.cur_tqn_zs.get('high') - self.cur_tqn_zs.get('low') "height": self.cur_tqa_zs.get('high') - self.cur_tqa_zs.get('low')
}) })
else: else:
# 对比中枢之前所有的确认低点,不能超过 # 对比中枢之前所有的确认低点,不能超过
zs_lows = self.cur_tqn_zs.get("lows", [self.cur_tqn_zs.get('low')]) zs_lows = self.cur_tqa_zs.get("lows", [self.cur_tqa_zs.get('low')])
max_low = max(zs_lows) max_low = max(zs_lows)
new_low = max(max_low, cur_bi.get('low')) new_low = max(max_low, cur_bi.get('low'))
# 下跌笔在生长,中枢底部在扩展 # 下跌笔在生长,中枢底部在扩展
if max_low < new_low < self.cur_tqn_zs.get('low'): if max_low < new_low < self.cur_tqa_zs.get('low'):
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"end": cur_bi.get('end'), "end": cur_bi.get('end'),
"low": new_low}) "low": new_low})
# 更新中枢高度 # 更新中枢高度
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"height": self.cur_tqn_zs.get('high') - self.cur_tqn_zs.get('low') "height": self.cur_tqa_zs.get('high') - self.cur_tqa_zs.get('low')
}) })
# 当前笔 不是中枢最后一笔, 方向是回归中枢的 # 当前笔 不是中枢最后一笔, 方向是回归中枢的
else: else:
# 向下的一笔,且回落中枢高位下方,变成中枢的最后一笔 # 向下的一笔,且回落中枢高位下方,变成中枢的最后一笔
if direction == -1 and cur_bi.get('low') < self.cur_tqn_zs.get('high') \ if direction == -1 and cur_bi.get('low') < self.cur_tqa_zs.get('high') \
and cur_bi.get('high') > self.cur_tqn_zs.get('low'): and cur_bi.get('high') > self.cur_tqa_zs.get('low'):
# 对比中枢之前所有的确认低点,不能超过 # 对比中枢之前所有的确认低点,不能超过
zs_lows = self.cur_tqn_zs.get("lows", [self.cur_tqn_zs.get('low')]) zs_lows = self.cur_tqa_zs.get("lows", [self.cur_tqa_zs.get('low')])
max_low = max(zs_lows) max_low = max(zs_lows)
new_low = max(max_low, cur_bi.get('low')) new_low = max(max_low, cur_bi.get('low'))
# 下跌笔在生长,中枢底部在扩展 # 下跌笔在生长,中枢底部在扩展
if max_low < new_low < self.cur_tqn_zs.get('low'): if max_low < new_low < self.cur_tqa_zs.get('low'):
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"end": cur_bi.get('end'), "end": cur_bi.get('end'),
"low": new_low}) "low": new_low})
# 更新中枢高度 # 更新中枢高度
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"height": self.cur_tqn_zs.get('high') - self.cur_tqn_zs.get('low') "height": self.cur_tqa_zs.get('high') - self.cur_tqa_zs.get('low')
}) })
# 更新中枢的确认高点,更新最后一笔 # 更新中枢的确认高点,更新最后一笔
zs_highs = self.cur_tqn_zs.get("highs", [self.cur_tqn_zs.get('high')]) zs_highs = self.cur_tqa_zs.get("highs", [self.cur_tqa_zs.get('high')])
zs_highs.append(cur_bi.get('high')) zs_highs.append(cur_bi.get('high'))
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"highs": zs_highs, # 确认的高点清单(后续不能超过) "highs": zs_highs, # 确认的高点清单(后续不能超过)
"exit_direction": cur_bi.get('direction'), # 离开笔的方向 "exit_direction": cur_bi.get('direction'), # 离开笔的方向
"exit_start": cur_bi.get('start') "exit_start": cur_bi.get('start')
}) })
# 最后一笔的时间,若比中枢的结束时间晚,就更新 # 最后一笔的时间,若比中枢的结束时间晚,就更新
if self.cur_tqn_zs.get('end') < cur_bi.get('start'): if self.cur_tqa_zs.get('end') < cur_bi.get('start'):
self.cur_tqn_zs.update({"end": cur_bi.get("start")}) self.cur_tqa_zs.update({"end": cur_bi.get("start")})
# 向上的一笔,回抽中枢下轨上方,变成中枢的一笔 # 向上的一笔,回抽中枢下轨上方,变成中枢的一笔
if direction == 1 and cur_bi.get('high') > self.cur_tqn_zs.get('low') \ if direction == 1 and cur_bi.get('high') > self.cur_tqa_zs.get('low') \
and cur_bi.get('low') < self.cur_tqn_zs.get('high'): and cur_bi.get('low') < self.cur_tqa_zs.get('high'):
# 对比中枢之前所有的确认高点,不能超过 # 对比中枢之前所有的确认高点,不能超过
zs_highs = self.cur_tqn_zs.get("highs", [self.cur_tqn_zs.get('high')]) zs_highs = self.cur_tqa_zs.get("highs", [self.cur_tqa_zs.get('high')])
min_high = min(zs_highs) min_high = min(zs_highs)
new_high = min(min_high, cur_bi.get('high')) new_high = min(min_high, cur_bi.get('high'))
# 当前笔的高度为最短,在生长,则更新中枢的结束时间和高度 # 当前笔的高度为最短,在生长,则更新中枢的结束时间和高度
if min_high >= new_high > self.cur_tqn_zs.get('high'): if min_high >= new_high > self.cur_tqa_zs.get('high'):
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"end": cur_bi.get('end'), "end": cur_bi.get('end'),
"high": new_high}) "high": new_high})
# 更新中枢高度 # 更新中枢高度
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"height": self.cur_tqn_zs.get('high') - self.cur_tqn_zs.get('low') "height": self.cur_tqa_zs.get('high') - self.cur_tqa_zs.get('low')
}) })
# 更新中枢的确认低点,更新最后一笔 # 更新中枢的确认低点,更新最后一笔
zs_lows = self.cur_tqn_zs.get("lows", [self.cur_tqn_zs.get('low')]) zs_lows = self.cur_tqa_zs.get("lows", [self.cur_tqa_zs.get('low')])
zs_lows.append(cur_bi.get('low')) zs_lows.append(cur_bi.get('low'))
self.cur_tqn_zs.update({ self.cur_tqa_zs.update({
"lows": zs_lows, # 确认的低点清单(后续不能超过) "lows": zs_lows, # 确认的低点清单(后续不能超过)
"exit_direction": cur_bi.get('direction'), # 离开笔的方向 "exit_direction": cur_bi.get('direction'), # 离开笔的方向
"exit_start": cur_bi.get('start') "exit_start": cur_bi.get('start')
}) })
# 最后一笔的时间,若比中枢的结束时间晚,就更新 # 最后一笔的时间,若比中枢的结束时间晚,就更新
if self.cur_tqn_zs.get('end') < cur_bi.get('start'): if self.cur_tqa_zs.get('end') < cur_bi.get('start'):
self.cur_tqn_zs.update({"end": cur_bi.get("start")}) self.cur_tqa_zs.update({"end": cur_bi.get("start")})
def export_tqa_zs(self): def export_tqa_zs(self):
""" """
@ -1872,12 +1872,12 @@ class CtaLineBar(object):
if self.export_tqa_zs_filename is None: if self.export_tqa_zs_filename is None:
return return
if len(self.cur_tqn_zs) < 1: if len(self.cur_tqa_zs) < 1:
return return
# 将当前中枢的信息写入 # 将当前中枢的信息写入
self.append_data(file_name=self.export_tqa_zs_filename, self.append_data(file_name=self.export_tqa_zs_filename,
dict_data=self.cur_tqn_zs, dict_data=self.cur_tqa_zs,
field_names=["start", "end", "direction", "height", "high", "low"] field_names=["start", "end", "direction", "height", "high", "low"]
) )
@ -2173,14 +2173,16 @@ class CtaLineBar(object):
golden_cross = False golden_cross = False
dead_cross = False dead_cross = False
if self.line_ma1[-1] > self.line_ma1[-2] \ # if self.line_ma1[-1] > self.line_ma1[-2] \
and self.line_ma1[-1] > self.line_ma2[-1] \ # and self.line_ma1[-1] > self.line_ma2[-1] \
and self.line_ma1[-2] <= self.line_ma2[-2]: # and self.line_ma1[-2] <= self.line_ma2[-2]:
if self.ma12_count <=0 and self.line_ma1[-1] > self.line_ma2[-1]:
golden_cross = True golden_cross = True
if self.line_ma1[-1] < self.line_ma1[-2] \ # if self.line_ma1[-1] < self.line_ma1[-2] \
and self.line_ma1[-1] < self.line_ma2[-1] \ # and self.line_ma1[-1] < self.line_ma2[-1] \
and self.line_ma1[-2] >= self.line_ma2[-2]: # and self.line_ma1[-2] >= self.line_ma2[-2]:
if self.ma12_count >=0 and self.line_ma1[-1] < self.line_ma2[-1]:
dead_cross = True dead_cross = True
if self.ma12_count <= 0: if self.ma12_count <= 0:
@ -2212,14 +2214,16 @@ class CtaLineBar(object):
if len(self.line_ma2) >= 2 and len(self.line_ma3) > 2: if len(self.line_ma2) >= 2 and len(self.line_ma3) > 2:
golden_cross = False golden_cross = False
dead_cross = False dead_cross = False
if self.line_ma2[-1] > self.line_ma2[-2] \ # if self.line_ma2[-1] > self.line_ma2[-2] \
and self.line_ma2[-1] > self.line_ma3[-1] \ # and self.line_ma2[-1] > self.line_ma3[-1] \
and self.line_ma2[-2] <= self.line_ma3[-2]: # and self.line_ma2[-2] <= self.line_ma3[-2]:
if self.ma23_count <=0 and self.line_ma2[-1] > self.line_ma3[-1]:
golden_cross = True golden_cross = True
if self.line_ma2[-1] < self.line_ma2[-2] \ # if self.line_ma2[-1] < self.line_ma2[-2] \
and self.line_ma2[-1] < self.line_ma3[-1] \ # and self.line_ma2[-1] < self.line_ma3[-1] \
and self.line_ma2[-2] >= self.line_ma3[-2]: # and self.line_ma2[-2] >= self.line_ma3[-2]:
if self.ma23_count >= 0 and self.line_ma2[-1] < self.line_ma3[-1]:
dead_cross = True dead_cross = True
if self.ma23_count <= 0: if self.ma23_count <= 0:
@ -2251,14 +2255,16 @@ class CtaLineBar(object):
if len(self.line_ma1) >= 2 and len(self.line_ma3) > 2: if len(self.line_ma1) >= 2 and len(self.line_ma3) > 2:
golden_cross = False golden_cross = False
dead_cross = False dead_cross = False
if self.line_ma1[-1] > self.line_ma1[-2] \ # if self.line_ma1[-1] > self.line_ma1[-2] \
and self.line_ma1[-1] > self.line_ma3[-1] \ # and self.line_ma1[-1] > self.line_ma3[-1] \
and self.line_ma1[-2] <= self.line_ma3[-2]: # and self.line_ma1[-2] <= self.line_ma3[-2]:
if self.ma13_count <=0 and self.line_ma1[-1] > self.line_ma3[-1]:
golden_cross = True golden_cross = True
if self.line_ma1[-1] < self.line_ma1[-2] \ # if self.line_ma1[-1] < self.line_ma1[-2] \
and self.line_ma1[-1] < self.line_ma3[-1] \ # and self.line_ma1[-1] < self.line_ma3[-1] \
and self.line_ma1[-2] >= self.line_ma3[-2]: # and self.line_ma1[-2] >= self.line_ma3[-2]:
if self.ma13_count >=0 and self.line_ma1[-1] < self.line_ma3[-1]:
dead_cross = True dead_cross = True
if self.ma13_count <= 0: if self.ma13_count <= 0:
@ -4123,7 +4129,7 @@ class CtaLineBar(object):
return False return False
# 底部背离,只能在零轴下方才判断 # 底部背离,只能在零轴下方才判断
if s1_dif_min > 0 or s1_dif_min > 0: if s1_dif_min > 0 or s2_dif_min > 0:
return False return False
# 价格创新低dif没有创新低 # 价格创新低dif没有创新低
@ -5570,13 +5576,15 @@ class CtaLineBar(object):
"""返回段得平均高度""" """返回段得平均高度"""
if not self.chanlun_calculated: if not self.chanlun_calculated:
self.__count_chanlun() self.__count_chanlun()
return round(sum([d.height for d in self.duan_list[-duan_len:]]) / duan_len, self.round_n) duan_list = self.duan_list[-duan_len:]
return round(sum([d.height for d in duan_list]) / max(1,len(duan_list)), self.round_n)
def bi_height_ma(self, bi_len=20): def bi_height_ma(self, bi_len=20):
"""返回分笔得平均高度""" """返回分笔得平均高度"""
if not self.chanlun_calculated: if not self.chanlun_calculated:
self.__count_chanlun() self.__count_chanlun()
return round(sum([bi.height for bi in self.bi_list[-bi_len:]]) / bi_len, self.round_n) bi_list = self.bi_list[-bi_len:]
return round(sum([bi.height for bi in bi_list]) / max(1,len(bi_list)), self.round_n)
def export_chan(self): def export_chan(self):
""" """

File diff suppressed because it is too large Load Diff