Revert chan to the most valuable one
This commit is contained in:
+7
-93
@@ -31,10 +31,6 @@ class ChanKLC():
|
||||
self.rsi = klu.rsi
|
||||
self.volume_ratio = klu.volume_ratio
|
||||
self.macdhist = 0
|
||||
|
||||
# === 新增:KLC类型 ===
|
||||
self.klc_type = None # KLC类型:大阳线、大阴线、小阳线、小阴线
|
||||
|
||||
def set_klc_fx_type(self, klc_fx_type):
|
||||
#print(self.start_time, klc_fx_type, self.get_feature_data()['klu_macd'], self.get_feature_data()['klu_macdhist'], self.get_feature_data()['klu_rsi'])
|
||||
self.klc_fx_type = klc_fx_type
|
||||
@@ -53,13 +49,7 @@ class ChanKLC():
|
||||
self.volume_ratio = self.volume_ratio / len(self.klus)
|
||||
self.volume = self.volume / len(self.klus)
|
||||
self.macdhist = self.macdhist / len(self.klus)
|
||||
def contain_klu_fx(self):
|
||||
if len(self.klus) > 0:
|
||||
for klu in self.klus:
|
||||
klu.update_realtime_analysis()
|
||||
if klu.fx_type == self.fx and klu.fx_strength > 1.8:
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_next(self, klc):
|
||||
self.next = klc
|
||||
def set_pre(self, klc):
|
||||
@@ -1157,78 +1147,6 @@ class ChanKLC():
|
||||
|
||||
return features
|
||||
|
||||
def check_fx_klu_strength(self):
|
||||
if self.pre and self.next and self.next.end_klu:
|
||||
strength = 0
|
||||
klc1 = self.pre
|
||||
klc2 = self
|
||||
klc3 = self.next
|
||||
# 检查包含关系
|
||||
inc = self.check_include_relation(klc1, klc2, klc3)
|
||||
if not inc:
|
||||
# 检查分型类型
|
||||
if self.fx == Chan_FX_TYPE.TOP:
|
||||
# (1)没有包含关系+1
|
||||
strength += 0
|
||||
print(self.start_time, "1")
|
||||
# (2)第1条K线是一条大阳线,而第2、3条K线是小阴线、小阳线,那么这个分型结构的意义就不大了,强度 -1
|
||||
if self.pre.cal_klu_min_max() > 0.5 and self.cal_klu_min_max() < 0.2 and self.next.cal_klu_min_max() < 0.2:
|
||||
strength += -1
|
||||
print(self.start_time, "2")
|
||||
# (3)第2条K线有长上影线或者就是大阴线,而第3条K线不能以阳线收在第2条K线区间的一半之上,那么该顶分型的力度就比较大
|
||||
if ((self.close < self.open and self.cal_klu_min_max() > 0.5) or self.cal_klu_upper_shadow() > 0.6) and not (self.next.close > self.next.open and self.next.close > (self.high-self.low)/2):
|
||||
strength += 1
|
||||
print(self.start_time, "3")
|
||||
else:
|
||||
if self.fx == Chan_FX_TYPE.TOP:
|
||||
# (4)第2条K线和第3条K线为包含关系,而第3条K线为大阴线(直接把为阳线的第2条K线“吃掉”),这是最坏的一种包含关系。
|
||||
if self.start_klu.index - self.end_klu.index < 0:
|
||||
klu1 = self.start_klu
|
||||
klu2 = self.klus[1]
|
||||
print(self.start_time, self.end_time, "length: ", len(self.klus), klu1.index, klu2.index)
|
||||
if klu2.close < klu2.open and 100*abs(klu2.open - klu2.close) / klu2.open > 0.5 and klu1.high <= klu2.high and klu1.low >= klu2.low:
|
||||
strength += 1
|
||||
print(self.start_time, "4")
|
||||
# (5)第3条K线如果跌破第1条K线的底而且不能高于第1条K线区间的一半之上,则属于较弱的一种,也就是说这种顶分型出现后股价见顶的可能性不大。
|
||||
if self.next.low < self.pre.low and self.next.high < (self.pre.high + self.pre.low)/2:
|
||||
strength += -1
|
||||
print(self.start_time, "5")
|
||||
return strength
|
||||
else:
|
||||
return 0
|
||||
def cal_klu_upper_shadow(self):
|
||||
"""
|
||||
计算KLC的上影线长度
|
||||
上影线 = 最高价 - max(开盘价, 收盘价)
|
||||
"""
|
||||
if self.high <= 0: # 避免无效数据
|
||||
return 0
|
||||
|
||||
# 计算上影线长度
|
||||
upper_shadow = self.high - max(self.open, self.close)
|
||||
|
||||
# 计算相对上影线长度(相对于整个K线区间)
|
||||
total_range = self.high - self.low
|
||||
if total_range > 0:
|
||||
upper_shadow_ratio = upper_shadow / total_range
|
||||
else:
|
||||
upper_shadow_ratio = 0
|
||||
|
||||
return upper_shadow_ratio
|
||||
def cal_klu_min_max(self):
|
||||
"""
|
||||
计算KLC类型:大阳线、大阴线、小阳线、小阴线
|
||||
"""
|
||||
if self.open <= 0: # 避免除零错误
|
||||
return 0
|
||||
line_type = 1000*abs(self.open - self.close) / self.open
|
||||
print(self.start_time, line_type)
|
||||
return line_type
|
||||
def check_include_relation(self, klc1, klc2, klc3):
|
||||
if klc1.start_klu.index - klc1.end_klu.index == 0 and klc2.start_klu.index - klc2.end_klu.index == 0 and klc3.start_klu.index - klc3.end_klu.index == 0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
def cal_fx_strength(self):
|
||||
"""
|
||||
用self.pre和self.next实现分型强弱判断
|
||||
@@ -1246,12 +1164,11 @@ class ChanKLC():
|
||||
-2: 弱分型(明显中继)
|
||||
-3: 极弱分型(无效分型)
|
||||
"""
|
||||
#return self.check_fx_klu_strength()
|
||||
# 检查是否为分型,且有前后K线数据
|
||||
if self.fx == Chan_FX_TYPE.UNKNOWN or self.klc_fx_type == Chan_FX_TYPE.UNKNOWN:
|
||||
if self.fx == Chan_FX_TYPE.UNKNOWN:
|
||||
return 0
|
||||
if not self.pre or not self.next:
|
||||
return -100
|
||||
return 100
|
||||
# === 核心判断:分型在笔中的位置 ===
|
||||
|
||||
# 1. 检查这个分型是否能够终结当前笔
|
||||
@@ -1283,7 +1200,6 @@ class ChanKLC():
|
||||
|
||||
# 分型质量调整
|
||||
base_score += fx_quality
|
||||
#base_score += self.check_fx_klu_strength()
|
||||
#print(self.start_time, base_score, is_bi_end, post_fx_confirmation, fx_quality)
|
||||
# 限制在-3到3范围内
|
||||
return max(-3, min(3, base_score))
|
||||
@@ -1334,7 +1250,7 @@ class ChanKLC():
|
||||
first_low = self.pre.low
|
||||
middle_low = self.low
|
||||
key_support = min(first_low, middle_low)
|
||||
last_klc = None
|
||||
|
||||
for i, klc in enumerate(subsequent_klcs):
|
||||
# 检查是否跌破关键支撑
|
||||
if klc.low < key_support:
|
||||
@@ -1347,8 +1263,7 @@ class ChanKLC():
|
||||
# 检查下跌趋势
|
||||
if i > 0 and klc.close < subsequent_klcs[i-1].close:
|
||||
downward_trend += 1
|
||||
last_klc = klc
|
||||
print(last_klc.start_time, last_klc.end_time)
|
||||
|
||||
# 强烈笔终结:跌破关键位且无新高
|
||||
if broken_key_levels >= 1 and new_highs == 0 and downward_trend >= 2:
|
||||
return 2
|
||||
@@ -1381,7 +1296,7 @@ class ChanKLC():
|
||||
first_high = self.pre.high
|
||||
middle_high = self.high
|
||||
key_resistance = max(first_high, middle_high)
|
||||
last_klc = None
|
||||
|
||||
for i, klc in enumerate(subsequent_klcs):
|
||||
# 检查是否突破关键阻力
|
||||
if klc.high > key_resistance:
|
||||
@@ -1394,8 +1309,7 @@ class ChanKLC():
|
||||
# 检查上涨趋势
|
||||
if i > 0 and klc.close > subsequent_klcs[i-1].close:
|
||||
upward_trend += 1
|
||||
last_klc = klc
|
||||
print(last_klc.start_time, last_klc.end_time)
|
||||
|
||||
# 强烈笔终结:突破关键位且无新低
|
||||
if broken_key_levels >= 1 and new_lows == 0 and upward_trend >= 2:
|
||||
return 2
|
||||
|
||||
Reference in New Issue
Block a user