添加klu分型的强度计算
This commit is contained in:
+2
-2
@@ -718,7 +718,7 @@ class ChanLun():
|
|||||||
if last_top.index + 4 < klc.index and len(bi_list) > 1:
|
if last_top.index + 4 < klc.index and len(bi_list) > 1:
|
||||||
pre_last_bi = bi_list[-2]
|
pre_last_bi = bi_list[-2]
|
||||||
last_bi = bi_list[-1]
|
last_bi = bi_list[-1]
|
||||||
if pre_last_bi.is_sure and not last_bi.is_sure and pre_last_bi.dir == Chan_BI_DIR.UP and False:
|
if pre_last_bi.is_sure and not last_bi.is_sure and pre_last_bi.dir == Chan_BI_DIR.UP:
|
||||||
pre_last_bi.update_bi(klc)
|
pre_last_bi.update_bi(klc)
|
||||||
bi_list.remove(last_bi)
|
bi_list.remove(last_bi)
|
||||||
pre_last_bi.set_next(None)
|
pre_last_bi.set_next(None)
|
||||||
@@ -838,7 +838,7 @@ class ChanLun():
|
|||||||
if last_bottom.index + 4 < klc.index and len(bi_list) > 1:
|
if last_bottom.index + 4 < klc.index and len(bi_list) > 1:
|
||||||
pre_last_bi = bi_list[-2]
|
pre_last_bi = bi_list[-2]
|
||||||
last_bi = bi_list[-1]
|
last_bi = bi_list[-1]
|
||||||
if pre_last_bi.is_sure and not last_bi.is_sure and pre_last_bi.dir == Chan_BI_DIR.DOWN and False:
|
if pre_last_bi.is_sure and not last_bi.is_sure and pre_last_bi.dir == Chan_BI_DIR.DOWN:
|
||||||
pre_last_bi.update_bi(klc)
|
pre_last_bi.update_bi(klc)
|
||||||
bi_list.remove(last_bi)
|
bi_list.remove(last_bi)
|
||||||
pre_last_bi.set_next(None)
|
pre_last_bi.set_next(None)
|
||||||
|
|||||||
Binary file not shown.
+100
-2
@@ -353,6 +353,22 @@ def analyze_chan(df):
|
|||||||
for bi in bi_list:
|
for bi in bi_list:
|
||||||
bi.cal_macd_div()
|
bi.cal_macd_div()
|
||||||
#print(bi.start_time, bi.macd_hist, bi.macd_div)
|
#print(bi.start_time, bi.macd_hist, bi.macd_div)
|
||||||
|
|
||||||
|
# 获取原始K线数据用于KLU分型分析
|
||||||
|
klu_list = []
|
||||||
|
try:
|
||||||
|
# 尝试获取KLU数据
|
||||||
|
if hasattr(chan, 'get_klu_list'):
|
||||||
|
klu_list = chan.get_klu_list(df)
|
||||||
|
elif hasattr(chan, 'klu_list'):
|
||||||
|
klu_list = chan.klu_list
|
||||||
|
else:
|
||||||
|
# 如果没有专门的KLU方法,尝试从KLC获取原始K线数据
|
||||||
|
print("未找到KLU数据获取方法,尝试其他方式")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"获取KLU数据时出错: {e}")
|
||||||
|
klu_list = []
|
||||||
|
|
||||||
# 提取K线分型信息
|
# 提取K线分型信息
|
||||||
klc_fx_info = []
|
klc_fx_info = []
|
||||||
for klc in klc_list:
|
for klc in klc_list:
|
||||||
@@ -403,13 +419,74 @@ def analyze_chan(df):
|
|||||||
'is_strong_fx': False
|
'is_strong_fx': False
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# 提取KLU分型信息
|
||||||
|
klu_fx_info = []
|
||||||
|
for klu in klu_list:
|
||||||
|
if hasattr(klu, 'fx_type') and klu.fx_type != Chan_FX_TYPE.UNKNOWN:
|
||||||
|
try:
|
||||||
|
# 计算分型强度
|
||||||
|
fx_strength = 0
|
||||||
|
fx_strength_level = ""
|
||||||
|
is_strong_fx = False
|
||||||
|
|
||||||
|
# 尝试调用分型强度计算方法
|
||||||
|
if hasattr(klu, 'calculate_realtime_fx_strength'):
|
||||||
|
fx_strength = klu.calculate_realtime_fx_strength()
|
||||||
|
elif hasattr(klu, 'fx_strength'):
|
||||||
|
fx_strength = klu.fx_strength
|
||||||
|
|
||||||
|
# 尝试获取分型强度等级 - 基于强度值生成等级
|
||||||
|
if fx_strength >= 2:
|
||||||
|
fx_strength_level = "强"
|
||||||
|
is_strong_fx = True
|
||||||
|
elif fx_strength >= 1:
|
||||||
|
fx_strength_level = "中"
|
||||||
|
is_strong_fx = False
|
||||||
|
elif fx_strength >= 0:
|
||||||
|
fx_strength_level = "弱"
|
||||||
|
is_strong_fx = False
|
||||||
|
else:
|
||||||
|
fx_strength_level = "极弱"
|
||||||
|
is_strong_fx = False
|
||||||
|
|
||||||
|
# 确保分型确认状态
|
||||||
|
is_confirmed = getattr(klu, 'fx_confirmed', True)
|
||||||
|
|
||||||
|
klu_fx_info.append({
|
||||||
|
'time': klu.time,
|
||||||
|
'price': klu.low if klu.fx_type == Chan_FX_TYPE.BOTTOM else klu.high,
|
||||||
|
'fx_type': str(klu.fx_type).replace("Chan_FX_TYPE.", ""),
|
||||||
|
'is_bottom': klu.fx_type == Chan_FX_TYPE.BOTTOM,
|
||||||
|
'fx_strength': fx_strength, # 分型强度分数
|
||||||
|
'fx_strength_level': fx_strength_level, # 分型强度等级
|
||||||
|
'is_strong_fx': is_strong_fx, # 是否为强分型
|
||||||
|
'fx_confirmed': is_confirmed # 分型是否确认
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
print(f"处理KLU分型信息时出错: {e}")
|
||||||
|
# 如果出错,仍然添加基本信息,但分型强度为0
|
||||||
|
klu_fx_info.append({
|
||||||
|
'time': klu.time,
|
||||||
|
'price': klu.low if klu.fx_type == Chan_FX_TYPE.BOTTOM else klu.high,
|
||||||
|
'fx_type': str(klu.fx_type).replace("Chan_FX_TYPE.", ""),
|
||||||
|
'is_bottom': klu.fx_type == Chan_FX_TYPE.BOTTOM,
|
||||||
|
'fx_strength': 0,
|
||||||
|
'fx_strength_level': "",
|
||||||
|
'is_strong_fx': False,
|
||||||
|
'fx_confirmed': False
|
||||||
|
})
|
||||||
|
|
||||||
|
print(f"提取到 {len(klc_fx_info)} 个KLC分型和 {len(klu_fx_info)} 个KLU分型")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'klc_list': klc_list,
|
'klc_list': klc_list,
|
||||||
|
'klu_list': klu_list, # 添加KLU列表
|
||||||
'bi_list': bi_list,
|
'bi_list': bi_list,
|
||||||
'seg_list': seg_list,
|
'seg_list': seg_list,
|
||||||
'zs_list': zs_list,
|
'zs_list': zs_list,
|
||||||
'trade_points': buy_sell_points,
|
'trade_points': buy_sell_points,
|
||||||
'klc_fx_info': klc_fx_info # 添加分型信息
|
'klc_fx_info': klc_fx_info, # KLC分型信息
|
||||||
|
'klu_fx_info': klu_fx_info # 添加KLU分型信息
|
||||||
}
|
}
|
||||||
|
|
||||||
def identify_trade_points(bi_list, seg_list, zs_list):
|
def identify_trade_points(bi_list, seg_list, zs_list):
|
||||||
@@ -687,7 +764,17 @@ def analyze():
|
|||||||
'fx_strength': float(point['fx_strength']), # 分型强度分数
|
'fx_strength': float(point['fx_strength']), # 分型强度分数
|
||||||
'fx_strength_level': str(point['fx_strength_level']), # 分型强度等级
|
'fx_strength_level': str(point['fx_strength_level']), # 分型强度等级
|
||||||
'is_strong_fx': bool(point['is_strong_fx']) # 是否为强分型
|
'is_strong_fx': bool(point['is_strong_fx']) # 是否为强分型
|
||||||
} for point in analysis_result['klc_fx_info']]
|
} for point in analysis_result['klc_fx_info']],
|
||||||
|
'klu_fx_info': [{
|
||||||
|
'time': format_time_safely(point['time'], client_tz),
|
||||||
|
'price': float(point['price']),
|
||||||
|
'fx_type': point['fx_type'],
|
||||||
|
'is_bottom': bool(point['is_bottom']),
|
||||||
|
'fx_strength': float(point['fx_strength']), # 分型强度分数
|
||||||
|
'fx_strength_level': str(point['fx_strength_level']), # 分型强度等级
|
||||||
|
'is_strong_fx': bool(point['is_strong_fx']), # 是否为强分型
|
||||||
|
'fx_confirmed': bool(point['fx_confirmed']) # 分型是否确认
|
||||||
|
} for point in analysis_result['klu_fx_info']]
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
print(f"只请求元素数据,跳过主周期数据处理 (elements_only={elements_only})")
|
print(f"只请求元素数据,跳过主周期数据处理 (elements_only={elements_only})")
|
||||||
@@ -780,6 +867,17 @@ def analyze():
|
|||||||
'is_strong_fx': bool(point['is_strong_fx']) # 是否为强分型
|
'is_strong_fx': bool(point['is_strong_fx']) # 是否为强分型
|
||||||
} for point in element_analysis['klc_fx_info']]
|
} for point in element_analysis['klc_fx_info']]
|
||||||
|
|
||||||
|
result['element_klu_fx_info'] = [{
|
||||||
|
'time': format_time_safely(point['time'], client_tz),
|
||||||
|
'price': float(point['price']),
|
||||||
|
'fx_type': point['fx_type'],
|
||||||
|
'is_bottom': bool(point['is_bottom']),
|
||||||
|
'fx_strength': float(point['fx_strength']), # 分型强度分数
|
||||||
|
'fx_strength_level': str(point['fx_strength_level']), # 分型强度等级
|
||||||
|
'is_strong_fx': bool(point['is_strong_fx']), # 是否为强分型
|
||||||
|
'fx_confirmed': bool(point['fx_confirmed']) # 分型是否确认
|
||||||
|
} for point in element_analysis['klu_fx_info']]
|
||||||
|
|
||||||
print(f"小周期分析完成: {element_timeframe}, 笔数量: {len(result['element_bi_list'])}, {'仅元素数据' if elements_only else '包含主周期数据'}")
|
print(f"小周期分析完成: {element_timeframe}, 笔数量: {len(result['element_bi_list'])}, {'仅元素数据' if elements_only else '包含主周期数据'}")
|
||||||
else:
|
else:
|
||||||
print(f"无法获取小周期数据: {element_timeframe}")
|
print(f"无法获取小周期数据: {element_timeframe}")
|
||||||
|
|||||||
+206
-66
@@ -397,7 +397,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
<input class="form-check-input" type="checkbox" id="showKlcFxType" checked>
|
<input class="form-check-input" type="checkbox" id="showKlcFxType" checked>
|
||||||
<label class="form-check-label" for="showKlcFxType">分型</label>
|
<label class="form-check-label" for="showKlcFxType">KLC分型</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check form-check-inline">
|
||||||
|
<input class="form-check-input" type="checkbox" id="showKluFxType">
|
||||||
|
<label class="form-check-label" for="showKluFxType">KLU分型</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
<input class="form-check-input" type="checkbox" id="showMainBollinger">
|
<input class="form-check-input" type="checkbox" id="showMainBollinger">
|
||||||
@@ -411,7 +415,7 @@
|
|||||||
<label class="form-check-label" for="showElementBi">笔</label>
|
<label class="form-check-label" for="showElementBi">笔</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
<input class="form-check-input" type="checkbox" id="showElementSeg" checked>
|
<input class="form-check-input" type="checkbox" id="showElementSeg">
|
||||||
<label class="form-check-label" for="showElementSeg">线段</label>
|
<label class="form-check-label" for="showElementSeg">线段</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
@@ -428,7 +432,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
<input class="form-check-input" type="checkbox" id="showElementKlcFxType">
|
<input class="form-check-input" type="checkbox" id="showElementKlcFxType">
|
||||||
<label class="form-check-label" for="showElementKlcFxType">分型</label>
|
<label class="form-check-label" for="showElementKlcFxType">KLC分型</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check form-check-inline">
|
||||||
|
<input class="form-check-input" type="checkbox" id="showElementKluFxType">
|
||||||
|
<label class="form-check-label" for="showElementKluFxType">KLU分型</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
<input class="form-check-input" type="checkbox" id="showElementBollinger">
|
<input class="form-check-input" type="checkbox" id="showElementBollinger">
|
||||||
@@ -1080,6 +1088,8 @@
|
|||||||
console.log('- 显示成交量:', false);
|
console.log('- 显示成交量:', false);
|
||||||
console.log('- 显示分型类型:', $('#showKlcFxType').is(':checked'));
|
console.log('- 显示分型类型:', $('#showKlcFxType').is(':checked'));
|
||||||
console.log('- 显示小周期分型:', $('#showElementKlcFxType').is(':checked'));
|
console.log('- 显示小周期分型:', $('#showElementKlcFxType').is(':checked'));
|
||||||
|
console.log('- 显示KLU分型:', $('#showKluFxType').is(':checked'));
|
||||||
|
console.log('- 显示小周期KLU分型:', $('#showElementKluFxType').is(':checked'));
|
||||||
console.log('- 显示买卖点:', $('#showTradePoints').is(':checked'));
|
console.log('- 显示买卖点:', $('#showTradePoints').is(':checked'));
|
||||||
console.log('- 显示原始K线:', $('#showOriginalKline').is(':checked'));
|
console.log('- 显示原始K线:', $('#showOriginalKline').is(':checked'));
|
||||||
console.log('- 显示主周期布林带:', $('#showMainBollinger').is(':checked'));
|
console.log('- 显示主周期布林带:', $('#showMainBollinger').is(':checked'));
|
||||||
@@ -3187,19 +3197,25 @@
|
|||||||
// 绘制分型类型标签
|
// 绘制分型类型标签
|
||||||
console.log('=== 开始检查分型显示条件 ===');
|
console.log('=== 开始检查分型显示条件 ===');
|
||||||
console.log('showKlcFxType勾选状态:', $('#showKlcFxType').is(':checked'));
|
console.log('showKlcFxType勾选状态:', $('#showKlcFxType').is(':checked'));
|
||||||
|
console.log('showKluFxType勾选状态:', $('#showKluFxType').is(':checked'));
|
||||||
console.log('currentData.klc_fx_info存在:', !!currentData.klc_fx_info);
|
console.log('currentData.klc_fx_info存在:', !!currentData.klc_fx_info);
|
||||||
|
console.log('currentData.klu_fx_info存在:', !!currentData.klu_fx_info);
|
||||||
console.log('currentData.klc_fx_info长度:', currentData.klc_fx_info ? currentData.klc_fx_info.length : 'undefined');
|
console.log('currentData.klc_fx_info长度:', currentData.klc_fx_info ? currentData.klc_fx_info.length : 'undefined');
|
||||||
|
console.log('currentData.klu_fx_info长度:', currentData.klu_fx_info ? currentData.klu_fx_info.length : 'undefined');
|
||||||
if (currentData.klc_fx_info && currentData.klc_fx_info.length > 0) {
|
if (currentData.klc_fx_info && currentData.klc_fx_info.length > 0) {
|
||||||
console.log('前3个分型数据样本:', currentData.klc_fx_info.slice(0, 3));
|
console.log('前3个klc分型数据样本:', currentData.klc_fx_info.slice(0, 3));
|
||||||
|
}
|
||||||
|
if (currentData.klu_fx_info && currentData.klu_fx_info.length > 0) {
|
||||||
|
console.log('前3个klu分型数据样本:', currentData.klu_fx_info.slice(0, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($('#showKlcFxType').is(':checked') && currentData.klc_fx_info && currentData.klc_fx_info.length > 0) {
|
// 收集所有主周期分型标记
|
||||||
console.log(`绘制K线分型类型标签,共${currentData.klc_fx_info.length}条`);
|
const allMainFxMarkers = [];
|
||||||
|
const mainFxMarkers = []; // 用于tooltip支持
|
||||||
|
|
||||||
// 收集所有分型标记
|
// 处理主周期KLC分型
|
||||||
const allFxMarkers = [];
|
if ($('#showKlcFxType').is(':checked') && currentData.klc_fx_info && currentData.klc_fx_info.length > 0) {
|
||||||
// 存储分型标记,用于tooltip功能
|
console.log(`绘制主周期K线合并分型标签,共${currentData.klc_fx_info.length}条`);
|
||||||
const fxMarkers = [];
|
|
||||||
|
|
||||||
currentData.klc_fx_info.forEach(function(fx) {
|
currentData.klc_fx_info.forEach(function(fx) {
|
||||||
try {
|
try {
|
||||||
@@ -3207,18 +3223,8 @@
|
|||||||
const timestamp = Math.floor(new Date(fx.time).getTime() / 1000);
|
const timestamp = Math.floor(new Date(fx.time).getTime() / 1000);
|
||||||
const price = parseFloat(fx.price);
|
const price = parseFloat(fx.price);
|
||||||
|
|
||||||
// 添加时间和价格调试信息
|
|
||||||
console.log('处理分型:', {
|
|
||||||
原始时间: fx.time,
|
|
||||||
转换时间戳: timestamp,
|
|
||||||
原始价格: fx.price,
|
|
||||||
转换价格: price,
|
|
||||||
时间有效: !isNaN(timestamp),
|
|
||||||
价格有效: !isNaN(price)
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isNaN(timestamp) || isNaN(price)) {
|
if (isNaN(timestamp) || isNaN(price)) {
|
||||||
console.error('分型类型时间或价格转换错误:', fx.time, fx.price);
|
console.error('主周期KLC分型时间或价格转换错误:', fx.time, fx.price);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3233,38 +3239,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 构建显示文本,包含分型类型和强度信息
|
// 构建显示文本,包含分型类型和强度信息
|
||||||
// 添加调试信息
|
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
||||||
console.log('分型数据:', {
|
if (fx.fx_strength < 1.5) { // 降低阈值,让更多分型显示
|
||||||
fx_type: fx.fx_type,
|
|
||||||
fx_strength: fx.fx_strength,
|
|
||||||
fx_strength_level: fx.fx_strength_level,
|
|
||||||
is_strong_fx: fx.is_strong_fx
|
|
||||||
});
|
|
||||||
let displayText = `${fx.fx_strength_level} ${fx.fx_strength.toFixed(1)}`;
|
|
||||||
if (fx.fx_strength < 1.0) { // 降低阈值,让更多分型显示
|
|
||||||
displayText = fx.fx_strength >= 0.8 ? '•' : '' // 0.8以上显示点,0.8以下不显示文本
|
displayText = fx.fx_strength >= 0.8 ? '•' : '' // 0.8以上显示点,0.8以下不显示文本
|
||||||
}
|
}
|
||||||
console.log('显示文本:', displayText);
|
|
||||||
|
|
||||||
// 添加标记配置调试
|
// 添加标记配置
|
||||||
const markerConfig = {
|
const markerConfig = {
|
||||||
time: timestamp,
|
time: timestamp,
|
||||||
position: fx.is_bottom ? 'belowBar' : 'aboveBar',
|
position: fx.is_bottom ? 'belowBar' : 'aboveBar',
|
||||||
color: strengthColor,
|
color: strengthColor,
|
||||||
shape: 'circle',
|
shape: 'triangle',
|
||||||
text: displayText,
|
text: displayText,
|
||||||
size: fx.is_strong_fx ? 1 : 0.6 // 调整尺寸,强分型稍大,普通分型更小
|
size: fx.is_strong_fx ? 1 : 0.6 // 调整尺寸,强分型稍大,普通分型更小
|
||||||
};
|
};
|
||||||
console.log('标记配置:', markerConfig);
|
|
||||||
|
|
||||||
// 添加到标记数组
|
allMainFxMarkers.push(markerConfig);
|
||||||
allFxMarkers.push(markerConfig);
|
|
||||||
|
|
||||||
// 创建分型标记对象,包含tooltip信息
|
// 创建分型标记对象,包含tooltip信息
|
||||||
const fxMarker = {
|
const fxMarker = {
|
||||||
time: timestamp,
|
time: timestamp,
|
||||||
tooltip: `<div style="color: ${strengthColor}; font-weight: bold;">
|
tooltip: `<div style="color: ${strengthColor}; font-weight: bold;">
|
||||||
${fx.is_bottom ? '底分型' : '顶分型'}: ${fx.fx_type}<br>
|
主周期${fx.is_bottom ? '底分型' : '顶分型'}(合): ${fx.fx_type}<br>
|
||||||
强度分数: ${fx.fx_strength}分<br>
|
强度分数: ${fx.fx_strength}分<br>
|
||||||
强度等级: ${fx.fx_strength_level}<br>
|
强度等级: ${fx.fx_strength_level}<br>
|
||||||
是否强分型: ${fx.is_strong_fx ? '是' : '否'}<br>
|
是否强分型: ${fx.is_strong_fx ? '是' : '否'}<br>
|
||||||
@@ -3273,46 +3269,111 @@
|
|||||||
</div>`
|
</div>`
|
||||||
};
|
};
|
||||||
|
|
||||||
// 添加到分型标记数组
|
mainFxMarkers.push(fxMarker);
|
||||||
fxMarkers.push(fxMarker);
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('绘制分型类型标签出错:', e);
|
console.error('绘制主周期KLC分型标签出错:', e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 一次性设置所有分型标记到主数据系列
|
|
||||||
if (allFxMarkers.length > 0) {
|
|
||||||
console.log('一次性设置', allFxMarkers.length, '个分型标记');
|
|
||||||
|
|
||||||
// 暂存主周期分型标记,等待与小周期合并
|
|
||||||
window.mainFxMarkers = allFxMarkers;
|
|
||||||
} else {
|
|
||||||
window.mainFxMarkers = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理主周期KLU分型
|
||||||
|
if ($('#showKluFxType').is(':checked') && currentData.klu_fx_info && currentData.klu_fx_info.length > 0) {
|
||||||
|
console.log(`绘制主周期K线未合并分型标签,共${currentData.klu_fx_info.length}条`);
|
||||||
|
|
||||||
|
currentData.klu_fx_info.forEach(function(fx) {
|
||||||
|
try {
|
||||||
|
// 直接使用UTC时间戳(秒)
|
||||||
|
const timestamp = Math.floor(new Date(fx.time).getTime() / 1000);
|
||||||
|
const price = parseFloat(fx.price);
|
||||||
|
|
||||||
|
if (isNaN(timestamp) || isNaN(price)) {
|
||||||
|
console.error('主周期KLU分型时间或价格转换错误:', fx.time, fx.price);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// KLU分型使用不同的颜色区分
|
||||||
|
const color = fx.is_bottom ? '#17a2b8' : '#fd7e14'; // 底分型用青色,顶分型用橙色
|
||||||
|
|
||||||
|
// 根据强度等级调整颜色强度
|
||||||
|
let strengthColor = color;
|
||||||
|
if (fx.is_strong_fx) {
|
||||||
|
// 强分型使用更亮的颜色
|
||||||
|
strengthColor = fx.is_bottom ? '#20c997' : '#fd7e14';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建显示文本,包含分型类型和强度信息
|
||||||
|
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
||||||
|
if (fx.fx_strength < 1.4) { // 降低阈值,让更多分型显示
|
||||||
|
displayText = fx.fx_strength >= 0.8 ? '•' : '' // 0.8以上显示点,0.8以下不显示文本
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加标记配置
|
||||||
|
const markerConfig = {
|
||||||
|
time: timestamp,
|
||||||
|
position: fx.is_bottom ? 'belowBar' : 'aboveBar',
|
||||||
|
color: strengthColor,
|
||||||
|
// shape: 'triangle', // 使用三角形区分KLU分型
|
||||||
|
text: displayText,
|
||||||
|
size: fx.is_strong_fx ? 0.8 : 0.5 // KLU分型稍小一些
|
||||||
|
};
|
||||||
|
|
||||||
|
allMainFxMarkers.push(markerConfig);
|
||||||
|
|
||||||
|
// 创建分型标记对象,包含tooltip信息
|
||||||
|
const fxMarker = {
|
||||||
|
time: timestamp,
|
||||||
|
tooltip: `<div style="color: ${strengthColor}; font-weight: bold;">
|
||||||
|
主周期${fx.is_bottom ? '底分型' : '顶分型'}(原): ${fx.fx_type}<br>
|
||||||
|
强度分数: ${fx.fx_strength}分<br>
|
||||||
|
强度等级: ${fx.fx_strength_level}<br>
|
||||||
|
是否强分型: ${fx.is_strong_fx ? '是' : '否'}<br>
|
||||||
|
价格: ${price.toFixed(4)}<br>
|
||||||
|
时间: ${fx.time}
|
||||||
|
</div>`
|
||||||
|
};
|
||||||
|
|
||||||
|
mainFxMarkers.push(fxMarker);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('绘制主周期KLU分型标签出错:', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 暂存主周期分型标记
|
||||||
|
window.mainFxMarkers = allMainFxMarkers;
|
||||||
|
|
||||||
// 将分型标记添加到全局markers中以支持tooltip功能
|
// 将分型标记添加到全局markers中以支持tooltip功能
|
||||||
if (window.fxMarkers) {
|
if (window.fxMarkers) {
|
||||||
window.fxMarkers = [...window.fxMarkers, ...fxMarkers];
|
window.fxMarkers = [...window.fxMarkers, ...mainFxMarkers];
|
||||||
} else {
|
} else {
|
||||||
window.fxMarkers = fxMarkers;
|
window.fxMarkers = mainFxMarkers;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
// 检查是否有任何主周期分型数据
|
||||||
console.log('绘制分型类型标签 - 已禁用或无数据');
|
const hasMainFxData = ($('#showKlcFxType').is(':checked') && currentData.klc_fx_info && currentData.klc_fx_info.length > 0) ||
|
||||||
// 清空分型标记
|
($('#showKluFxType').is(':checked') && currentData.klu_fx_info && currentData.klu_fx_info.length > 0);
|
||||||
window.fxMarkers = [];
|
|
||||||
|
if (!hasMainFxData) {
|
||||||
|
console.log('绘制主周期分型标记 - 已禁用或无数据');
|
||||||
|
// 清空主周期分型标记
|
||||||
window.mainFxMarkers = [];
|
window.mainFxMarkers = [];
|
||||||
|
window.fxMarkers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制小周期分型标记
|
// 绘制小周期分型标记
|
||||||
if ($('#showElementKlcFxType').is(':checked') && currentData.element_klc_fx_info && currentData.element_klc_fx_info.length > 0) {
|
if (($('#showElementKlcFxType').is(':checked') && currentData.element_klc_fx_info && currentData.element_klc_fx_info.length > 0) ||
|
||||||
console.log(`绘制小周期分型标记,共${currentData.element_klc_fx_info.length}条`);
|
($('#showElementKluFxType').is(':checked') && currentData.element_klu_fx_info && currentData.element_klu_fx_info.length > 0)) {
|
||||||
|
|
||||||
// 收集所有小周期分型标记
|
// 收集所有小周期分型标记
|
||||||
const allElementFxMarkers = [];
|
const allElementFxMarkers = [];
|
||||||
const elementFxMarkers = []; // 用于tooltip支持
|
const elementFxMarkers = []; // 用于tooltip支持
|
||||||
|
|
||||||
|
// 处理小周期KLC分型
|
||||||
|
if ($('#showElementKlcFxType').is(':checked') && currentData.element_klc_fx_info && currentData.element_klc_fx_info.length > 0) {
|
||||||
|
console.log(`绘制小周期K线合并分型标记,共${currentData.element_klc_fx_info.length}条`);
|
||||||
|
|
||||||
currentData.element_klc_fx_info.forEach(function(fx) {
|
currentData.element_klc_fx_info.forEach(function(fx) {
|
||||||
try {
|
try {
|
||||||
// 直接使用UTC时间戳(秒)
|
// 直接使用UTC时间戳(秒)
|
||||||
@@ -3320,7 +3381,7 @@
|
|||||||
const price = parseFloat(fx.price);
|
const price = parseFloat(fx.price);
|
||||||
|
|
||||||
if (isNaN(timestamp) || isNaN(price)) {
|
if (isNaN(timestamp) || isNaN(price)) {
|
||||||
console.error('小周期分型时间或价格转换错误:', fx.time, fx.price);
|
console.error('小周期KLC分型时间或价格转换错误:', fx.time, fx.price);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3330,30 +3391,29 @@
|
|||||||
// 强分型使用更亮的颜色
|
// 强分型使用更亮的颜色
|
||||||
strengthColor = fx.is_bottom ? '#FF0000' : '#00CED1';
|
strengthColor = fx.is_bottom ? '#FF0000' : '#00CED1';
|
||||||
}
|
}
|
||||||
let displayText = `${fx.fx_strength_level} ${fx.fx_strength.toFixed(1)}`;
|
let displayText = `${fx.fx_strength.toFixed(1)}`;
|
||||||
// 构建小周期分型显示文本
|
// 构建小周期分型显示文本
|
||||||
if (fx.fx_strength < 0.8){ // 调整小周期阈值
|
if (fx.fx_strength < 1.5){ // 调整小周期阈值
|
||||||
displayText = fx.fx_strength >= 0.6 ? '•' : '' // 0.6以上显示点
|
displayText = fx.fx_strength >= 0.6 ? '•' : '' // 0.6以上显示点
|
||||||
}
|
}
|
||||||
|
|
||||||
// 小周期分型标记配置 - 根据分型类型使用正确的箭头形状
|
// 小周期分型标记配置
|
||||||
const markerConfig = {
|
const markerConfig = {
|
||||||
time: timestamp,
|
time: timestamp,
|
||||||
position: fx.is_bottom ? 'belowBar' : 'aboveBar',
|
position: fx.is_bottom ? 'belowBar' : 'aboveBar',
|
||||||
color: strengthColor,
|
color: strengthColor,
|
||||||
shape: 'circle',
|
shape: 'triangle',
|
||||||
text: displayText,
|
text: displayText,
|
||||||
size: fx.is_strong_fx ? 0.8 : 0.6 // 小周期标记整体更小一些
|
size: fx.is_strong_fx ? 0.8 : 0.6 // 小周期标记整体更小一些
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('小周期分型标记配置:', markerConfig);
|
|
||||||
allElementFxMarkers.push(markerConfig);
|
allElementFxMarkers.push(markerConfig);
|
||||||
|
|
||||||
// 创建小周期分型标记对象,包含tooltip信息
|
// 创建小周期分型标记对象,包含tooltip信息
|
||||||
const elementFxMarker = {
|
const elementFxMarker = {
|
||||||
time: timestamp,
|
time: timestamp,
|
||||||
tooltip: `<div style="color: ${strengthColor}; font-weight: bold;">
|
tooltip: `<div style="color: ${strengthColor}; font-weight: bold;">
|
||||||
小周期${fx.is_bottom ? '底分型' : '顶分型'}: ${fx.fx_type}<br>
|
小周期${fx.is_bottom ? '底分型' : '顶分型'}(合): ${fx.fx_type}<br>
|
||||||
强度分数: ${fx.fx_strength}分<br>
|
强度分数: ${fx.fx_strength}分<br>
|
||||||
强度等级: ${fx.fx_strength_level}<br>
|
强度等级: ${fx.fx_strength_level}<br>
|
||||||
是否强分型: ${fx.is_strong_fx ? '是' : '否'}<br>
|
是否强分型: ${fx.is_strong_fx ? '是' : '否'}<br>
|
||||||
@@ -3362,13 +3422,73 @@
|
|||||||
</div>`
|
</div>`
|
||||||
};
|
};
|
||||||
|
|
||||||
// 添加到小周期分型标记数组
|
|
||||||
elementFxMarkers.push(elementFxMarker);
|
elementFxMarkers.push(elementFxMarker);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('绘制小周期分型标记出错:', e);
|
console.error('绘制小周期KLC分型标记出错:', e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理小周期KLU分型
|
||||||
|
if ($('#showElementKluFxType').is(':checked') && currentData.element_klu_fx_info && currentData.element_klu_fx_info.length > 0) {
|
||||||
|
console.log(`绘制小周期K线未合并分型标记,共${currentData.element_klu_fx_info.length}条`);
|
||||||
|
|
||||||
|
currentData.element_klu_fx_info.forEach(function(fx) {
|
||||||
|
try {
|
||||||
|
// 直接使用UTC时间戳(秒)
|
||||||
|
const timestamp = Math.floor(new Date(fx.time).getTime() / 1000);
|
||||||
|
const price = parseFloat(fx.price);
|
||||||
|
|
||||||
|
if (isNaN(timestamp) || isNaN(price)) {
|
||||||
|
console.error('小周期KLU分型时间或价格转换错误:', fx.time, fx.price);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 小周期KLU分型使用不同的颜色
|
||||||
|
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)}`;
|
||||||
|
// 构建小周期分型显示文本
|
||||||
|
if (fx.fx_strength < 1.4){ // 调整小周期阈值
|
||||||
|
displayText = fx.fx_strength >= 0.6 ? '•' : '' // 0.6以上显示点
|
||||||
|
}
|
||||||
|
|
||||||
|
// 小周期KLU分型标记配置
|
||||||
|
const markerConfig = {
|
||||||
|
time: timestamp,
|
||||||
|
position: fx.is_bottom ? 'belowBar' : 'aboveBar',
|
||||||
|
color: strengthColor,
|
||||||
|
// shape: 'triangle', // 使用三角形区分KLU分型
|
||||||
|
text: displayText,
|
||||||
|
size: fx.is_strong_fx ? 0.7 : 0.5 // 小周期KLU标记更小一些
|
||||||
|
};
|
||||||
|
|
||||||
|
allElementFxMarkers.push(markerConfig);
|
||||||
|
|
||||||
|
// 创建小周期分型标记对象,包含tooltip信息
|
||||||
|
const elementFxMarker = {
|
||||||
|
time: timestamp,
|
||||||
|
tooltip: `<div style="color: ${strengthColor}; font-weight: bold;">
|
||||||
|
小周期${fx.is_bottom ? '底分型' : '顶分型'}(原): ${fx.fx_type}<br>
|
||||||
|
强度分数: ${fx.fx_strength}分<br>
|
||||||
|
强度等级: ${fx.fx_strength_level}<br>
|
||||||
|
是否强分型: ${fx.is_strong_fx ? '是' : '否'}<br>
|
||||||
|
价格: ${price.toFixed(4)}<br>
|
||||||
|
时间: ${fx.time}
|
||||||
|
</div>`
|
||||||
|
};
|
||||||
|
|
||||||
|
elementFxMarkers.push(elementFxMarker);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('绘制小周期KLU分型标记出错:', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 将小周期分型标记添加到全局markers中以支持tooltip功能
|
// 将小周期分型标记添加到全局markers中以支持tooltip功能
|
||||||
if (window.fxMarkers) {
|
if (window.fxMarkers) {
|
||||||
@@ -3411,6 +3531,14 @@
|
|||||||
} else {
|
} else {
|
||||||
console.log('未找到主数据系列,无法设置标记');
|
console.log('未找到主数据系列,无法设置标记');
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('没有分型标记需要显示,清空图表标记');
|
||||||
|
// 清空图表上的所有标记
|
||||||
|
if (showOriginalKline && tvWidget.series.candleSeries) {
|
||||||
|
tvWidget.series.candleSeries.setMarkers([]);
|
||||||
|
} else if (!showOriginalKline && tvWidget.series.lineSeries) {
|
||||||
|
tvWidget.series.lineSeries.setMarkers([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5084,6 +5212,16 @@
|
|||||||
refreshChart(currentData);
|
refreshChart(currentData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 绑定KLU分型显示开关
|
||||||
|
$('#showKluFxType').change(function() {
|
||||||
|
refreshChartOnly();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 绑定小周期KLU分型显示开关
|
||||||
|
$('#showElementKluFxType').change(function() {
|
||||||
|
refreshChart(currentData);
|
||||||
|
});
|
||||||
|
|
||||||
// 绑定买卖点显示开关
|
// 绑定买卖点显示开关
|
||||||
$('#showTradePoints').change(function() {
|
$('#showTradePoints').change(function() {
|
||||||
refreshChart(currentData);
|
refreshChart(currentData);
|
||||||
@@ -5113,7 +5251,9 @@
|
|||||||
'showVolume': false,
|
'showVolume': false,
|
||||||
'showMacd': true,
|
'showMacd': true,
|
||||||
'showKlcFxType': $('#showKlcFxType').is(':checked'),
|
'showKlcFxType': $('#showKlcFxType').is(':checked'),
|
||||||
|
'showKluFxType': $('#showKluFxType').is(':checked'),
|
||||||
'showElementKlcFxType': $('#showElementKlcFxType').is(':checked'),
|
'showElementKlcFxType': $('#showElementKlcFxType').is(':checked'),
|
||||||
|
'showElementKluFxType': $('#showElementKluFxType').is(':checked'),
|
||||||
'showTradePoints': $('#showTradePoints').is(':checked'),
|
'showTradePoints': $('#showTradePoints').is(':checked'),
|
||||||
'showMainBollinger': $('#showMainBollinger').is(':checked'),
|
'showMainBollinger': $('#showMainBollinger').is(':checked'),
|
||||||
'showElementBollinger': $('#showElementBollinger').is(':checked'),
|
'showElementBollinger': $('#showElementBollinger').is(':checked'),
|
||||||
|
|||||||
Reference in New Issue
Block a user