添加klu分型的强度计算

This commit is contained in:
Porter
2025-06-02 14:34:28 +08:00
parent aea88b1e3e
commit 510a03aea8
4 changed files with 333 additions and 95 deletions
+231 -91
View File
@@ -397,7 +397,11 @@
</div>
<div class="form-check form-check-inline">
<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 class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="showMainBollinger">
@@ -411,7 +415,7 @@
<label class="form-check-label" for="showElementBi"></label>
</div>
<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>
</div>
<div class="form-check form-check-inline">
@@ -428,7 +432,11 @@
</div>
<div class="form-check form-check-inline">
<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 class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="showElementBollinger">
@@ -1080,6 +1088,8 @@
console.log('- 显示成交量:', false);
console.log('- 显示分型类型:', $('#showKlcFxType').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('- 显示原始K线:', $('#showOriginalKline').is(':checked'));
console.log('- 显示主周期布林带:', $('#showMainBollinger').is(':checked'));
@@ -3187,19 +3197,25 @@
// 绘制分型类型标签
console.log('=== 开始检查分型显示条件 ===');
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.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.klu_fx_info长度:', currentData.klu_fx_info ? currentData.klu_fx_info.length : 'undefined');
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));
}
// 收集所有主周期分型标记
const allMainFxMarkers = [];
const mainFxMarkers = []; // 用于tooltip支持
// 处理主周期KLC分型
if ($('#showKlcFxType').is(':checked') && currentData.klc_fx_info && currentData.klc_fx_info.length > 0) {
console.log(`绘制K线分型类型标签,共${currentData.klc_fx_info.length}条`);
// 收集所有分型标记
const allFxMarkers = [];
// 存储分型标记,用于tooltip功能
const fxMarkers = [];
console.log(`绘制主周期K线合并分型标签,共${currentData.klc_fx_info.length}条`);
currentData.klc_fx_info.forEach(function(fx) {
try {
@@ -3207,18 +3223,8 @@
const timestamp = Math.floor(new Date(fx.time).getTime() / 1000);
const price = parseFloat(fx.price);
// 添加时间和价格调试信息
console.log('处理分型:', {
原始时间: fx.time,
转换时间戳: timestamp,
原始价格: fx.price,
转换价格: price,
时间有效: !isNaN(timestamp),
价格有效: !isNaN(price)
});
if (isNaN(timestamp) || isNaN(price)) {
console.error('分型类型时间或价格转换错误:', fx.time, fx.price);
console.error('主周期KLC分型时间或价格转换错误:', fx.time, fx.price);
return;
}
@@ -3233,38 +3239,28 @@
}
// 构建显示文本,包含分型类型和强度信息
// 添加调试信息
console.log('分型数据:', {
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) { // 降低阈值让更多分型显示
let displayText = `${fx.fx_strength.toFixed(1)}`;
if (fx.fx_strength < 1.5) { // 降低阈值让更多分型显示
displayText = fx.fx_strength >= 0.8 ? '•' : '' // 0.8以上显示点,0.8以下不显示文本
}
console.log('显示文本:', displayText);
// 添加标记配置调试
// 添加标记配置
const markerConfig = {
time: timestamp,
position: fx.is_bottom ? 'belowBar' : 'aboveBar',
color: strengthColor,
shape: 'circle',
shape: 'triangle',
text: displayText,
size: fx.is_strong_fx ? 1 : 0.6 // 调整尺寸,强分型稍大,普通分型更小
};
console.log('标记配置:', markerConfig);
// 添加到标记数组
allFxMarkers.push(markerConfig);
allMainFxMarkers.push(markerConfig);
// 创建分型标记对象,包含tooltip信息
const fxMarker = {
time: timestamp,
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_level}<br>
是否强分型: ${fx.is_strong_fx ? '是' : '否'}<br>
@@ -3273,87 +3269,62 @@
</div>`
};
// 添加到分型标记数组
fxMarkers.push(fxMarker);
mainFxMarkers.push(fxMarker);
} catch (e) {
console.error('绘制分型类型标签出错:', e);
console.error('绘制主周期KLC分型标签出错:', e);
}
});
// 一次性设置所有分型标记到主数据系列
if (allFxMarkers.length > 0) {
console.log('一次性设置', allFxMarkers.length, '个分型标记');
// 暂存主周期分型标记,等待与小周期合并
window.mainFxMarkers = allFxMarkers;
} else {
window.mainFxMarkers = [];
}
// 将分型标记添加到全局markers中以支持tooltip功能
if (window.fxMarkers) {
window.fxMarkers = [...window.fxMarkers, ...fxMarkers];
} else {
window.fxMarkers = fxMarkers;
}
} else {
console.log('绘制分型类型标签 - 已禁用或无数据');
// 清空分型标记
window.fxMarkers = [];
window.mainFxMarkers = [];
}
// 绘制小周期分型标记
if ($('#showElementKlcFxType').is(':checked') && currentData.element_klc_fx_info && currentData.element_klc_fx_info.length > 0) {
console.log(`绘制周期分型标,共${currentData.element_klc_fx_info.length}条`);
// 处理主周期KLU分型
if ($('#showKluFxType').is(':checked') && currentData.klu_fx_info && currentData.klu_fx_info.length > 0) {
console.log(`绘制周期K线未合并分型标,共${currentData.klu_fx_info.length}条`);
// 收集所有小周期分型标记
const allElementFxMarkers = [];
const elementFxMarkers = []; // 用于tooltip支持
currentData.element_klc_fx_info.forEach(function(fx) {
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('周期分型时间或价格转换错误:', fx.time, fx.price);
console.error('周期KLU分型时间或价格转换错误:', fx.time, fx.price);
return;
}
// 小周期分型使用不同的颜色和样式,与主周期区分
let strengthColor = fx.is_bottom ? '#FF6B6B' : '#4ECDC4'; // 底分型用珊瑚红,顶分型用薄荷绿
// KLU分型使用不同的颜色区分
const color = fx.is_bottom ? '#17a2b8' : '#fd7e14'; // 底分型用青色,顶分型用橙色
// 根据强度等级调整颜色强度
let strengthColor = color;
if (fx.is_strong_fx) {
// 强分型使用更亮的颜色
strengthColor = fx.is_bottom ? '#FF0000' : '#00CED1';
strengthColor = fx.is_bottom ? '#20c997' : '#fd7e14';
}
let displayText = `${fx.fx_strength_level} ${fx.fx_strength.toFixed(1)}`;
// 构建小周期分型显示文本
if (fx.fx_strength < 0.8){ // 调整小周期阈值
displayText = fx.fx_strength >= 0.6 ? '•' : '' // 0.6以上显示
// 构建显示文本,包含分型类型和强度信息
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: 'circle',
// shape: 'triangle', // 使用三角形区分KLU分型
text: displayText,
size: fx.is_strong_fx ? 0.8 : 0.6 // 小周期标记整体更小一些
size: fx.is_strong_fx ? 0.8 : 0.5 // KLU分型稍小一些
};
console.log('小周期分型标记配置:', markerConfig);
allElementFxMarkers.push(markerConfig);
allMainFxMarkers.push(markerConfig);
// 创建小周期分型标记对象,包含tooltip信息
const elementFxMarker = {
// 创建分型标记对象,包含tooltip信息
const fxMarker = {
time: timestamp,
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_level}<br>
是否强分型: ${fx.is_strong_fx ? '是' : '否'}<br>
@@ -3362,13 +3333,162 @@
</div>`
};
// 添加到小周期分型标记数组
elementFxMarkers.push(elementFxMarker);
mainFxMarkers.push(fxMarker);
} catch (e) {
console.error('绘制周期分型标出错:', e);
console.error('绘制周期KLU分型标出错:', e);
}
});
}
// 暂存主周期分型标记
window.mainFxMarkers = allMainFxMarkers;
// 将分型标记添加到全局markers中以支持tooltip功能
if (window.fxMarkers) {
window.fxMarkers = [...window.fxMarkers, ...mainFxMarkers];
} else {
window.fxMarkers = mainFxMarkers;
}
// 检查是否有任何主周期分型数据
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);
if (!hasMainFxData) {
console.log('绘制主周期分型标记 - 已禁用或无数据');
// 清空主周期分型标记
window.mainFxMarkers = [];
window.fxMarkers = [];
}
// 绘制小周期分型标记
if (($('#showElementKlcFxType').is(':checked') && currentData.element_klc_fx_info && currentData.element_klc_fx_info.length > 0) ||
($('#showElementKluFxType').is(':checked') && currentData.element_klu_fx_info && currentData.element_klu_fx_info.length > 0)) {
// 收集所有小周期分型标记
const allElementFxMarkers = [];
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) {
try {
// 直接使用UTC时间戳(秒)
const timestamp = Math.floor(new Date(fx.time).getTime() / 1000);
const price = parseFloat(fx.price);
if (isNaN(timestamp) || isNaN(price)) {
console.error('小周期KLC分型时间或价格转换错误:', fx.time, fx.price);
return;
}
// 小周期分型使用不同的颜色和样式,与主周期区分
let strengthColor = fx.is_bottom ? '#FF6B6B' : '#4ECDC4'; // 底分型用珊瑚红,顶分型用薄荷绿
if (fx.is_strong_fx) {
// 强分型使用更亮的颜色
strengthColor = fx.is_bottom ? '#FF0000' : '#00CED1';
}
let displayText = `${fx.fx_strength.toFixed(1)}`;
// 构建小周期分型显示文本
if (fx.fx_strength < 1.5){ // 调整小周期阈值
displayText = fx.fx_strength >= 0.6 ? '•' : '' // 0.6以上显示点
}
// 小周期分型标记配置
const markerConfig = {
time: timestamp,
position: fx.is_bottom ? 'belowBar' : 'aboveBar',
color: strengthColor,
shape: 'triangle',
text: displayText,
size: fx.is_strong_fx ? 0.8 : 0.6 // 小周期标记整体更小一些
};
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('绘制小周期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功能
if (window.fxMarkers) {
@@ -3411,6 +3531,14 @@
} else {
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);
});
// 绑定KLU分型显示开关
$('#showKluFxType').change(function() {
refreshChartOnly();
});
// 绑定小周期KLU分型显示开关
$('#showElementKluFxType').change(function() {
refreshChart(currentData);
});
// 绑定买卖点显示开关
$('#showTradePoints').change(function() {
refreshChart(currentData);
@@ -5113,7 +5251,9 @@
'showVolume': false,
'showMacd': true,
'showKlcFxType': $('#showKlcFxType').is(':checked'),
'showKluFxType': $('#showKluFxType').is(':checked'),
'showElementKlcFxType': $('#showElementKlcFxType').is(':checked'),
'showElementKluFxType': $('#showElementKluFxType').is(':checked'),
'showTradePoints': $('#showTradePoints').is(':checked'),
'showMainBollinger': $('#showMainBollinger').is(':checked'),
'showElementBollinger': $('#showElementBollinger').is(':checked'),