Change some klc and bi recognition
This commit is contained in:
+54
-24
@@ -1,7 +1,7 @@
|
||||
import copy
|
||||
from typing import Dict, Optional
|
||||
|
||||
from ChanEnum import Chan_FX_TYPE, Chan_KLINE_DIR, Chan_BI_DIR, Chan_KLC_FX
|
||||
from ChanEnum import Chan_FX_TYPE, Chan_KLINE_DIR, Chan_BI_DIR, Chan_KLC_FX, Chan_K_DIR
|
||||
import ChanKLU
|
||||
import ChanCTime
|
||||
|
||||
@@ -31,7 +31,15 @@ class ChanKLC():
|
||||
self.rsi = klu.rsi
|
||||
self.volume_ratio = klu.volume_ratio
|
||||
self.macdhist = 0
|
||||
self.strength_list = []
|
||||
self.body = klu.body
|
||||
self.upper_shadow = klu.upper_shadow
|
||||
self.lower_shadow = klu.lower_shadow
|
||||
self.body_ratio = klu.body_ratio
|
||||
self.upper_shadow_ratio = klu.upper_shadow_ratio
|
||||
self.lower_shadow_ratio = klu.lower_shadow_ratio
|
||||
self.candle_dir = klu.candle_dir
|
||||
self.range = klu.range
|
||||
self.strength = klu.strength
|
||||
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
|
||||
@@ -41,6 +49,10 @@ class ChanKLC():
|
||||
self.end_klu = klu
|
||||
self.end_time = klu.time
|
||||
self.close = klu.close
|
||||
self.cal_indicators()
|
||||
self.cal_shape_1()
|
||||
self.strength = self.cal_klc_strength()
|
||||
def cal_indicators(self):
|
||||
for index in range(1, len(self.klus)):
|
||||
self.volume += self.klus[index].volume
|
||||
self.rsi += self.klus[index].rsi
|
||||
@@ -50,16 +62,31 @@ 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)
|
||||
self.cal_self_strength()
|
||||
def cal_self_strength(self):
|
||||
strength = 0
|
||||
if self.klus:
|
||||
if len(self.klus) == 1:
|
||||
strength = 1
|
||||
else:
|
||||
if len(self.klus) > 1:
|
||||
strength = 0
|
||||
self.strength_list.append(strength)
|
||||
def cal_shape_1(self):
|
||||
for index in range(1, len(self.klus)):
|
||||
self.body += self.klus[index].body
|
||||
self.upper_shadow += self.klus[index].upper_shadow
|
||||
self.lower_shadow += self.klus[index].lower_shadow
|
||||
self.body_ratio += self.klus[index].body_ratio
|
||||
self.upper_shadow_ratio += self.klus[index].upper_shadow_ratio
|
||||
self.lower_shadow_ratio += self.klus[index].lower_shadow_ratio
|
||||
self.range += self.klus[index].range
|
||||
self.body = self.body / len(self.klus)
|
||||
self.upper_shadow = self.upper_shadow / len(self.klus)
|
||||
self.lower_shadow = self.lower_shadow / len(self.klus)
|
||||
self.body_ratio = self.body_ratio / len(self.klus)
|
||||
self.upper_shadow_ratio = self.upper_shadow_ratio / len(self.klus)
|
||||
self.lower_shadow_ratio = self.lower_shadow_ratio / len(self.klus)
|
||||
self.range = self.range / len(self.klus)
|
||||
def cal_shape_2(self):
|
||||
self.body = abs(self.close - self.open)
|
||||
self.upper_shadow = self.high - max(self.close, self.open)
|
||||
self.lower_shadow = min(self.close, self.open) - self.low
|
||||
self.body_ratio = self.body / self.open
|
||||
self.upper_shadow_ratio = self.upper_shadow / self.open
|
||||
self.lower_shadow_ratio = self.lower_shadow / self.open
|
||||
self.candle_dir = Chan_K_DIR.CROSS if self.close == self.open else Chan_K_DIR.BULL if self.close > self.open else Chan_K_DIR.BEAR
|
||||
self.range = self.high - self.low
|
||||
def set_next(self, klc):
|
||||
self.next = klc
|
||||
def set_pre(self, klc):
|
||||
@@ -1171,10 +1198,20 @@ class ChanKLC():
|
||||
|
||||
return features
|
||||
|
||||
def cal_klc_strength(self):
|
||||
strength = 0
|
||||
if not self.end_klu:
|
||||
return strength
|
||||
if len(self.klus) > 0:
|
||||
for klu in self.klus:
|
||||
strength += klu.strength
|
||||
return strength
|
||||
def cal_fx_strength(self, klc_offset=2):
|
||||
strength = 0
|
||||
if self.fx == Chan_FX_TYPE.UNKNOWN or not self.pre or not self.next:
|
||||
if not self.end_klu:
|
||||
return 0
|
||||
if self.fx == Chan_FX_TYPE.UNKNOWN or not self.pre or not self.next:
|
||||
return strength
|
||||
else:
|
||||
if self.pre and self.next:
|
||||
klc1 = self.pre
|
||||
@@ -1182,34 +1219,27 @@ class ChanKLC():
|
||||
klc3 = self.next
|
||||
if self.bi:
|
||||
if self.bi.dir == Chan_BI_DIR.UP and self.fx == Chan_FX_TYPE.BOTTOM:
|
||||
return 0
|
||||
return strength
|
||||
if self.bi.dir == Chan_BI_DIR.DOWN and self.fx == Chan_FX_TYPE.TOP:
|
||||
return 0
|
||||
return strength
|
||||
if self.bi.dir == Chan_BI_DIR.UP:
|
||||
if self.klc_fx_type == Chan_KLC_FX.TOP1:
|
||||
strength += self.check_bi_end(self.bi)
|
||||
elif self.klc_fx_type == Chan_KLC_FX.TOP2:
|
||||
strength += self.check_bi_end(self.bi)
|
||||
else:
|
||||
if self.klc_fx_type == Chan_KLC_FX.BOTTOM1 or self.klc_fx_type == Chan_KLC_FX.BOTTOM2:
|
||||
if self.klc_fx_type == Chan_KLC_FX.BOTTOM1:
|
||||
strength += self.check_bi_end(self.bi)
|
||||
elif self.klc_fx_type == Chan_KLC_FX.BOTTOM2:
|
||||
strength += self.check_bi_end(self.bi)
|
||||
else:
|
||||
return 0
|
||||
return strength
|
||||
return strength
|
||||
def check_bi_end(self, bi):
|
||||
if bi.dir == Chan_BI_DIR.UP:
|
||||
return 1
|
||||
else:
|
||||
return 1
|
||||
def cal_klu_strength(self, klc1, klc2, klc3):
|
||||
klu_list = []
|
||||
klu_list.extend(klc1.klus)
|
||||
klu_list.extend(klc2.klus)
|
||||
klu_list.extend(klc3.klus)
|
||||
|
||||
return
|
||||
def calculate_fx_strength(self):
|
||||
"""
|
||||
基于专业缠论理论的分型强度评估体系
|
||||
|
||||
Reference in New Issue
Block a user