No need to add nor change
This commit is contained in:
+9
-2
@@ -30,8 +30,15 @@ class Chan_KLINE_DIR(Enum):
|
|||||||
DOWN = auto()
|
DOWN = auto()
|
||||||
COMBINE = auto()
|
COMBINE = auto()
|
||||||
INCLUDED = auto()
|
INCLUDED = auto()
|
||||||
|
class Chan_KLU_TYPE(Enum):
|
||||||
|
BigBull = auto()
|
||||||
|
MiddleBull = auto()
|
||||||
|
SmallBull = auto()
|
||||||
|
BigBear = auto()
|
||||||
|
MiddleBear = auto()
|
||||||
|
SmallBear = auto()
|
||||||
|
Cross = auto()
|
||||||
|
|
||||||
class Chan_FX_TYPE(Enum):
|
class Chan_FX_TYPE(Enum):
|
||||||
BOTTOM = auto()
|
BOTTOM = auto()
|
||||||
TOP = auto()
|
TOP = auto()
|
||||||
|
|||||||
+663
-1174
File diff suppressed because it is too large
Load Diff
+34
-2
@@ -1,4 +1,4 @@
|
|||||||
from ChanEnum import Chan_FX_TYPE
|
from ChanEnum import Chan_FX_TYPE, Chan_KLU_TYPE
|
||||||
class ChanKLU:
|
class ChanKLU:
|
||||||
def __init__(self, time, open, high, low, close, volume):
|
def __init__(self, time, open, high, low, close, volume):
|
||||||
# _time, _close, _open, _high, _low, _extra_info={}
|
# _time, _close, _open, _high, _low, _extra_info={}
|
||||||
@@ -23,13 +23,45 @@ class ChanKLU:
|
|||||||
self.rsi = 0
|
self.rsi = 0
|
||||||
self.volume_ratio = 0
|
self.volume_ratio = 0
|
||||||
|
|
||||||
|
# === 新增:K线类型 ===
|
||||||
|
self.kline_type = None # K线类型:大阳线、大阴线、小阳线、小阴线
|
||||||
|
|
||||||
# === 新增:实时分型相关属性 ===
|
# === 新增:实时分型相关属性 ===
|
||||||
self.pre = None # 前一根K线
|
self.pre = None # 前一根K线
|
||||||
self.next = None # 后一根K线
|
self.next = None # 后一根K线
|
||||||
self.fx_type = Chan_FX_TYPE.UNKNOWN # 分型类型:0=无分型,1=顶分型,-1=底分型
|
self.fx_type = Chan_FX_TYPE.UNKNOWN # 分型类型:0=无分型,1=顶分型,-1=底分型
|
||||||
self.fx_strength = 0 # 分型强度:0-100
|
self.fx_strength = 0 # 分型强度:0-100
|
||||||
self.fx_confirmed = False # 分型是否确认
|
self.fx_confirmed = False # 分型是否确认
|
||||||
|
self.klu_type = None
|
||||||
|
self.cal_klu_min_max()
|
||||||
|
def cal_klu_min_max(self):
|
||||||
|
"""
|
||||||
|
计算K线类型:大阳线、大阴线、小阳线、小阴线
|
||||||
|
"""
|
||||||
|
if self.open <= 0: # 避免除零错误
|
||||||
|
self.kline_type = None
|
||||||
|
return
|
||||||
|
|
||||||
|
# 计算涨跌幅
|
||||||
|
price_change_ratio = (self.close - self.open) / self.open
|
||||||
|
strength = 0
|
||||||
|
# 判断K线类型
|
||||||
|
if price_change_ratio > 0.005: # 涨幅超过2%
|
||||||
|
self.kline_type = Chan_KLU_TYPE.BigBull
|
||||||
|
strength += abs(price_change_ratio)
|
||||||
|
elif price_change_ratio > 0: # 涨幅0-2%
|
||||||
|
self.kline_type = Chan_KLU_TYPE.SmallBull
|
||||||
|
strength += abs(price_change_ratio)
|
||||||
|
elif price_change_ratio < -0.005: # 跌幅超过2%
|
||||||
|
self.kline_type = Chan_KLU_TYPE.BigBear
|
||||||
|
strength += abs(price_change_ratio)
|
||||||
|
elif price_change_ratio < 0: # 跌幅0-2%
|
||||||
|
self.kline_type = Chan_KLU_TYPE.SmallBear
|
||||||
|
strength += abs(price_change_ratio)
|
||||||
|
else: # 开盘价等于收盘价
|
||||||
|
self.kline_type = Chan_KLU_TYPE.Cross
|
||||||
|
strength += abs(price_change_ratio)
|
||||||
|
return strength
|
||||||
def set_next(self, next):
|
def set_next(self, next):
|
||||||
self.next = next
|
self.next = next
|
||||||
self.update_realtime_analysis()
|
self.update_realtime_analysis()
|
||||||
|
|||||||
+6
-4
@@ -697,10 +697,11 @@ class ChanLun():
|
|||||||
else:
|
else:
|
||||||
# A new top found
|
# A new top found
|
||||||
#last_top.set_fx(Chan_FX_TYPE.UNKNOWN)
|
#last_top.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||||
|
#print(klc.start_time, last_top.start_time, klc.cal_fx_strength(), "一类卖点Sell 1")
|
||||||
last_top = klc
|
last_top = klc
|
||||||
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Change 1")
|
#print(klc.start_time, klc.fx, bi_list[-1].dir, "Last Top Change 1")
|
||||||
klc.set_klc_fx_type(Chan_KLC_FX.TOP1)
|
klc.set_klc_fx_type(Chan_KLC_FX.TOP1)
|
||||||
#print(klc.start_time, klc.fx, "一类卖点Sell 1")
|
|
||||||
#klc.set_fx(fx)
|
#klc.set_fx(fx)
|
||||||
#klc.set_state("10")
|
#klc.set_state("10")
|
||||||
bi_list[-1].add_klc(klc)
|
bi_list[-1].add_klc(klc)
|
||||||
@@ -731,6 +732,7 @@ class ChanLun():
|
|||||||
#klc.set_state("10")
|
#klc.set_state("10")
|
||||||
#print(klc.start_time, klc.fx, "笔卖点Sell 1")
|
#print(klc.start_time, klc.fx, "笔卖点Sell 1")
|
||||||
klc.set_klc_fx_type(Chan_KLC_FX.TOP2)
|
klc.set_klc_fx_type(Chan_KLC_FX.TOP2)
|
||||||
|
#print(klc.start_time, last_top.start_time, klc.fx, "二类卖点Sell 2")
|
||||||
bi_list[-1].add_klc(klc)
|
bi_list[-1].add_klc(klc)
|
||||||
klc.set_bi(bi_list[-1])
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
@@ -755,7 +757,7 @@ class ChanLun():
|
|||||||
#klc.set_state('30')
|
#klc.set_state('30')
|
||||||
bi_list[-1].add_klc(klc)
|
bi_list[-1].add_klc(klc)
|
||||||
klc.set_bi(bi_list[-1])
|
klc.set_bi(bi_list[-1])
|
||||||
#print(klc.start_time, last_bottom.start_time, "Normal TOP Found, Confirm down bi 4")
|
#print(klc.start_time, last_top.start_time, "Normal TOP Found, Confirm down bi 4")
|
||||||
#print(klc.start_time, klc.fx, "笔卖点Sell 2")
|
#print(klc.start_time, klc.fx, "笔卖点Sell 2")
|
||||||
# last bottom = None
|
# last bottom = None
|
||||||
else:
|
else:
|
||||||
@@ -1220,8 +1222,8 @@ class ChanLun():
|
|||||||
klc.set_pre(last_klc)
|
klc.set_pre(last_klc)
|
||||||
last_klc.set_end_klu(last_klu)
|
last_klc.set_end_klu(last_klu)
|
||||||
klc.set_pre_fx()
|
klc.set_pre_fx()
|
||||||
else:
|
#else:
|
||||||
last_klc.add_klu(klu)
|
#last_klc.add_klu(klu)
|
||||||
else:
|
else:
|
||||||
ddir = Chan_KLINE_DIR.UP
|
ddir = Chan_KLINE_DIR.UP
|
||||||
if klu.open > klu.close:
|
if klu.open > klu.close:
|
||||||
|
|||||||
+1
-1
@@ -323,7 +323,7 @@ def add_indicators(df):
|
|||||||
|
|
||||||
def calculate_macd(df):
|
def calculate_macd(df):
|
||||||
"""计算MACD指标"""
|
"""计算MACD指标"""
|
||||||
exp1 = df['close'].ewm(span=12, adjust=False).mean()
|
exp1 = df['close'].ewm(span=10, adjust=False).mean()
|
||||||
exp2 = df['close'].ewm(span=26, adjust=False).mean()
|
exp2 = df['close'].ewm(span=26, adjust=False).mean()
|
||||||
macd = exp1 - exp2
|
macd = exp1 - exp2
|
||||||
signal = macd.ewm(span=9, adjust=False).mean()
|
signal = macd.ewm(span=9, adjust=False).mean()
|
||||||
|
|||||||
@@ -3241,20 +3241,16 @@
|
|||||||
console.error('主周期KLC分型时间或价格转换错误:', fx.time, fx.price);
|
console.error('主周期KLC分型时间或价格转换错误:', fx.time, fx.price);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 主周期 KLC
|
||||||
// 确定颜色和位置
|
// 确定颜色和位置
|
||||||
const color = fx.is_bottom ? '#28a745' : '#dc3545'; // 底分型绿色,顶分型红色
|
const color = fx.is_bottom ? '#28a745' : '#dc3545'; // 底分型绿色,顶分型红色
|
||||||
|
|
||||||
// 根据强度等级调整颜色强度
|
// 根据强度等级调整颜色强度
|
||||||
let strengthColor = color;
|
let strengthColor = color;
|
||||||
if (fx.is_strong_fx) {
|
|
||||||
// 强分型使用更亮的颜色
|
|
||||||
strengthColor = fx.is_bottom ? '#00ff00' : '#ff0000';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建显示文本,包含分型类型和强度信息
|
// 构建显示文本,包含分型类型和强度信息
|
||||||
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
||||||
if (fx.fx_strength < 50) { // 降低阈值,让更多分型显示
|
if (fx.fx_strength < 1.4) { // 降低阈值,让更多分型显示
|
||||||
displayText = fx.fx_strength >= 0.8 ? '•' : '' // 0.8以上显示点,0.8以下不显示文本
|
displayText = fx.fx_strength >= 0.8 ? '•' : '' // 0.8以上显示点,0.8以下不显示文本
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3265,7 +3261,7 @@
|
|||||||
color: strengthColor,
|
color: strengthColor,
|
||||||
shape: 'triangle',
|
shape: 'triangle',
|
||||||
text: displayText,
|
text: displayText,
|
||||||
size: fx.is_strong_fx ? 1 : 0.6 // 调整尺寸,强分型稍大,普通分型更小
|
size: 2 // 调整尺寸,强分型稍大,普通分型更小
|
||||||
};
|
};
|
||||||
|
|
||||||
allMainFxMarkers.push(markerConfig);
|
allMainFxMarkers.push(markerConfig);
|
||||||
@@ -3306,7 +3302,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// KLU分型使用不同的颜色区分
|
// 主周期 KLU
|
||||||
const color = fx.is_bottom ? '#17a2b8' : '#fd7e14'; // 底分型用青色,顶分型用橙色
|
const color = fx.is_bottom ? '#17a2b8' : '#fd7e14'; // 底分型用青色,顶分型用橙色
|
||||||
|
|
||||||
// 根据强度等级调整颜色强度
|
// 根据强度等级调整颜色强度
|
||||||
@@ -3399,12 +3395,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 小周期分型使用不同的颜色和样式,与主周期区分
|
// 小周期 KLC
|
||||||
let strengthColor = fx.is_bottom ? '#FF6B6B' : '#4ECDC4'; // 底分型用珊瑚红,顶分型用薄荷绿
|
let strengthColor = fx.is_bottom ? '#11116B' : '#222222'; // 底分型用珊瑚红,顶分型用薄荷绿
|
||||||
if (fx.is_strong_fx) {
|
|
||||||
// 强分型使用更亮的颜色
|
|
||||||
strengthColor = fx.is_bottom ? '#FF0000' : '#00CED1';
|
|
||||||
}
|
|
||||||
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
||||||
// 构建小周期分型显示文本
|
// 构建小周期分型显示文本
|
||||||
if (fx.fx_strength < 1.5){ // 调整小周期阈值
|
if (fx.fx_strength < 1.5){ // 调整小周期阈值
|
||||||
@@ -3459,12 +3451,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 小周期KLU分型使用不同的颜色
|
// 小周期 KLU
|
||||||
let strengthColor = fx.is_bottom ? '#9A8C98' : '#F2CC8F'; // 底分型用灰紫色,顶分型用浅黄色
|
let strengthColor = fx.is_bottom ? '#9A8C98' : '#F2CC8F'; // 底分型用灰紫色,顶分型用浅黄色
|
||||||
if (fx.is_strong_fx) {
|
|
||||||
// 强分型使用更亮的颜色
|
|
||||||
strengthColor = fx.is_bottom ? '#6C5B7B' : '#F9844A';
|
|
||||||
}
|
|
||||||
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
||||||
// 构建小周期分型显示文本
|
// 构建小周期分型显示文本
|
||||||
if (fx.fx_strength < 1.4){ // 调整小周期阈值
|
if (fx.fx_strength < 1.4){ // 调整小周期阈值
|
||||||
|
|||||||
Reference in New Issue
Block a user