添加k线动能理论
This commit is contained in:
+42
-11
@@ -1,4 +1,4 @@
|
||||
from ChanEnum import Chan_FX_TYPE, Chan_KLU_TYPE, Chan_K_DIR
|
||||
from ChanEnum import Chan_FX_TYPE, Chan_KLU_TYPE, Chan_K_DIR, Chan_MACD_STATE, Chan_MACDHIST_STATE
|
||||
class ChanKLU:
|
||||
def __init__(self, time, open, high, low, close, volume):
|
||||
# _time, _close, _open, _high, _low, _extra_info={}
|
||||
@@ -42,15 +42,24 @@ class ChanKLU:
|
||||
self.fx_confirmed = False # 分型是否确认
|
||||
self.klu_type = None
|
||||
self.cal_klu_min_max()
|
||||
self.range = self.high - self.low
|
||||
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.body_ratio = self.body / self.range
|
||||
self.upper_shadow_ratio = self.upper_shadow / self.body
|
||||
self.lower_shadow_ratio = self.lower_shadow / self.body
|
||||
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
|
||||
self.strength = 0 if self.candle_dir == Chan_K_DIR.CROSS else self.cal_klu_strength()
|
||||
|
||||
self.ema52 = 0
|
||||
self.ema24 = 0
|
||||
self.macd_slop = 0
|
||||
self.signal_slop = 0
|
||||
self.hist_slop = 0
|
||||
self.hist_state = Chan_MACDHIST_STATE.UNKNOWN
|
||||
self.macd_state = Chan_MACD_STATE.UNKNOWN
|
||||
self.macd_hist_gap = 0
|
||||
#print(self.open, self.close, self.high, self.low, self.candle_dir, self.strength)
|
||||
def cal_klu_strength(self):
|
||||
strength = 0
|
||||
@@ -599,13 +608,35 @@ class ChanKLU:
|
||||
self.bblow365 = float(item['bblow365']) if 'bblow365' in item and item['bblow365'] else 0
|
||||
# 设置指标后更新实时分析
|
||||
self.update_realtime_analysis()
|
||||
|
||||
self.cal_macd_state()
|
||||
def cal_macd_state(self):
|
||||
if self.pre:
|
||||
pre_macd_slop = self.macd - self.pre.macd
|
||||
pre_signal_slop = self.signal - self.pre.signal
|
||||
pre_hist_slop = self.macdhist - self.pre.macdhist
|
||||
|
||||
if self.macd == 0 and self.signal == 0 and self.macdhist == 0:
|
||||
return Chan_MACD_STATE.UNKNOWN
|
||||
if self.pre and self.pre.macd_state != Chan_MACD_STATE.UNKNOWN:
|
||||
self.macd_slop = self.macd - self.pre.macd
|
||||
self.signal_slop = self.signal - self.pre.signal
|
||||
self.hist_slop = self.macdhist - self.pre.macdhist
|
||||
self.macd_hist_gap = abs(self.macdhist - self.macd)
|
||||
if self.pre.signal >= 0 and self.signal < 0 and self.ema52 > self.close and self.next and self.next.signal < 0:
|
||||
self.macd_state = Chan_MACD_STATE.CROSS0
|
||||
elif self.pre.signal <= 0 and self.signal > 0 and self.ema52 < self.close and self.next and self.next.signal > 0:
|
||||
self.macd_state = Chan_MACD_STATE.CROSS0
|
||||
elif self.macd > 0 and self.signal > 0 and self.macdhist > 0:
|
||||
if self.signal > self.macdhist:
|
||||
self.macd_state = Chan_MACD_STATE.GW
|
||||
if self.macdhist < self.pre.macdhist and self.macd_slop > 0 and self.signal_slop > 0 and self.macd_slop < self.pre.macd_slop and self.signal_slop < self.pre.signal_slop and self.macd_hist_gap > self.pre.macd_hist_gap:
|
||||
self.macd_state = Chan_MACD_STATE.GWK
|
||||
elif self.macd_slop > 0 and self.signal_slop > 0:
|
||||
self.macd_state = Chan_MACD_STATE.UP
|
||||
elif self.macd < 0 and self.signal < 0 and self.macdhist < 0:
|
||||
if self.signal < self.macdhist:
|
||||
self.macd_state = Chan_MACD_STATE.GW
|
||||
if self.macdhist > self.pre.macdhist and self.macd_slop < 0 and self.signal_slop < 0 and self.macd_slop > self.pre.macd_slop and self.signal_slop > self.pre.signal_slop and self.macd_hist_gap > self.pre.macd_hist_gap:
|
||||
self.macd_state = Chan_MACD_STATE.GWK
|
||||
elif self.macd_slop < 0 and self.signal_slop < 0:
|
||||
self.macd_state = Chan_MACD_STATE.DOWN
|
||||
else:
|
||||
self.macd_state = Chan_MACD_STATE.START
|
||||
return self.macd_state
|
||||
|
||||
def get_feature_data(self):
|
||||
|
||||
Reference in New Issue
Block a user