添加klu的3种形态识别

This commit is contained in:
jackyu66git
2025-11-01 02:50:44 +08:00
parent 8bb3798a7c
commit 8e21ecb057
8 changed files with 287 additions and 117 deletions
+23 -21
View File
@@ -14,7 +14,7 @@ class ChanKLC():
self.low = klu.low
self.dir = ddir
self.index = index
self.klus = []
self.klu_list = []
self.add_klu(klu)
self.fx = Chan_FX_TYPE.UNKNOWN
self.next = None
@@ -49,6 +49,7 @@ class ChanKLC():
self.ema24 = klu.ema24
self.trend = Chan_PRICE_TREND.UNKNOWN
self.exception = klu.exception
self.klc_dir = Chan_KLINE_DIR.UP if klu.close > klu.open else Chan_KLINE_DIR.DOWN
def set_trend(self, trend):
self.trend = trend
def to_string(self):
@@ -64,22 +65,23 @@ class ChanKLC():
#self.cal_fx()
self.cal_bb_out()
def add_klu(self, klu):
self.klus.append(klu)
self.klu_list.append(klu)
def set_end_klu(self, klu):
self.end_klu = klu
self.end_time = klu.time
self.close = klu.close
for klu in self.klus:
for klu in self.klu_list:
if klu.separate_div > 0:
self.separate_div = True
if klu.continue_div:
self.continue_div = klu.continue_div
if klu.macd_state != Chan_MACD_STATE.UNKNOWN:
self.state = klu.macd_state
self.klc_dir = Chan_KLINE_DIR.UP if self.close > self.open else Chan_KLINE_DIR.DOWN
self.cal_indicators()
def cal_fx(self):
if self.klc_fx_type == Chan_KLC_FX.TOP1 or self.klc_fx_type == Chan_KLC_FX.TOP2:
#print(self.end_time, self.fx, self.macd, self.macdhist, len(self.klus))
#print(self.end_time, self.fx, self.macd, self.macdhist, len(self.klu_list))
if self.state == Chan_MACD_STATE.HIGH_EMPTY and self.macd > 0:
#print(self.end_time, self.state, self.macd, self.klc_fx_type)
self.klc_fx_type = Chan_KLC_FX.TOP6
@@ -100,7 +102,7 @@ class ChanKLC():
if self.signal < 0 and self.macd < self.signal:
self.klc_fx_type = Chan_KLC_FX.BOTTOM8
def cal_bb_out(self):
for klu in self.klus:
for klu in self.klu_list:
if self.klc_fx_type == Chan_KLC_FX.TOP1 or self.klc_fx_type == Chan_KLC_FX.TOP2:
#print(self.start_time, self.klc_fx_type, klu.high, klu.bb52upper, self.macd, self.next.macd, klu.time)
if self.high >= klu.bb52upper and klu.bb52upper > 0 and self.next and self.high > self.next.high:
@@ -112,22 +114,22 @@ class ChanKLC():
self.klc_fx_type = Chan_KLC_FX.BOTTOM4
print(self.end_time, self.klc_fx_type)
def cal_indicators(self):
for index in range(1, len(self.klus)):
self.volume += self.klus[index].volume
self.rsi += self.klus[index].rsi
self.volume_ratio += self.klus[index].volume_ratio
self.macdhist += self.klus[index].macdhist
self.ema52 += self.klus[index].ema52
self.ema24 += self.klus[index].ema24
self.rsi = self.rsi / len(self.klus)
self.volume_ratio = self.volume_ratio / len(self.klus)
self.volume = self.volume / len(self.klus)
self.macdhist = self.macdhist / len(self.klus)
self.ema52 = self.ema52 / len(self.klus)
self.ema24 = self.ema24 / len(self.klus)
if len(self.klus) > 0:
self.macd = self.klus[-1].macd
self.signal = self.klus[-1].signal
for index in range(1, len(self.klu_list)):
self.volume += self.klu_list[index].volume
self.rsi += self.klu_list[index].rsi
self.volume_ratio += self.klu_list[index].volume_ratio
self.macdhist += self.klu_list[index].macdhist
self.ema52 += self.klu_list[index].ema52
self.ema24 += self.klu_list[index].ema24
self.rsi = self.rsi / len(self.klu_list)
self.volume_ratio = self.volume_ratio / len(self.klu_list)
self.volume = self.volume / len(self.klu_list)
self.macdhist = self.macdhist / len(self.klu_list)
self.ema52 = self.ema52 / len(self.klu_list)
self.ema24 = self.ema24 / len(self.klu_list)
if len(self.klu_list) > 0:
self.macd = self.klu_list[-1].macd
self.signal = self.klu_list[-1].signal
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