根据新的条件进行交易,添加交易规则

This commit is contained in:
Porter
2025-09-15 10:29:53 +08:00
parent 3c360ea35b
commit 0b9f63409c
8 changed files with 149 additions and 71 deletions
+100 -46
View File
@@ -3054,62 +3054,114 @@
}
);
// 从 ChanMACD 的 klu_list 提取 continue_div / separate_div 标记,供主K线图显示
// 同时从主/次周期的 klu_list 提取 SD/CD 标记,分别使用不同样式
try {
const kluList = Array.isArray(cm.klu_list) ? cm.klu_list : [];
const kluDivMarkers = [];
kluList.forEach((item) => {
if (!item || !item.time) return;
const ts = Math.floor(new Date(item.time).getTime() / 1000);
if (isNaN(ts)) return;
// separate_div 为 true:上方蓝色箭头
if (item.separate_div === true) {
kluDivMarkers.push({
time: ts,
position: 'aboveBar',
color: '#03a9f4',
shape: 'arrowUp',
text: 'SD',
size: 0.6
});
}
// continue_div 为 true:下方橙色箭头
if (item.continue_div === true) {
kluDivMarkers.push({
time: ts,
position: 'belowBar',
color: '#ff9800',
shape: 'arrowDown',
text: 'CD',
size: 0.6
});
}
// near0_return > 0:在主图显示具体数值
if (item.near0_return && Number(item.near0_return) > 0) {
kluDivMarkers.push({
time: ts,
position: 'belowBar',
color: '#8bc34a',
shape: 'circle',
text: `N${Number(item.near0_return)}`,
size: 0.6
});
}
});
window.kluDivMarkers = kluDivMarkers;
const mainCm = currentData.chan_macd || {};
const elementCm = currentData.element_chan_macd || {};
const mainMarkers = [];
const elementMarkers = [];
// 主周期 U 标记(蓝/橙,与原样式一致)
if ((typeof window.showUOnMain === 'undefined' ? true : window.showUOnMain) && Array.isArray(mainCm.klu_list)) {
mainCm.klu_list.forEach((item) => {
if (!item || !item.time) return;
const ts = Math.floor(new Date(item.time).getTime() / 1000);
if (isNaN(ts)) return;
if (item.separate_div === true) {
mainMarkers.push({ time: ts, position: 'aboveBar', color: '#03a9f4', shape: 'arrowUp', text: 'SD', size: 0.6 });
}
if (item.continue_div === true) {
mainMarkers.push({ time: ts, position: 'belowBar', color: '#ff9800', shape: 'arrowDown', text: 'CD', size: 0.6 });
}
if (item.near0_return && Number(item.near0_return) > 0) {
mainMarkers.push({ time: ts, position: 'belowBar', color: '#8bc34a', shape: 'circle', text: `N${Number(item.near0_return)}`, size: 0.6 });
}
});
}
// 次周期 U 标记(使用不同配色以区分)
if ((typeof window.showUOnElement === 'undefined' ? true : window.showUOnElement) && Array.isArray(elementCm.klu_list)) {
elementCm.klu_list.forEach((item) => {
if (!item || !item.time) return;
const ts = Math.floor(new Date(item.time).getTime() / 1000);
if (isNaN(ts)) return;
if (item.separate_div === true) {
elementMarkers.push({ time: ts, position: 'aboveBar', color: '#9c27b0', shape: 'arrowUp', text: 'SD', size: 0.6 });
}
if (item.continue_div === true) {
elementMarkers.push({ time: ts, position: 'belowBar', color: '#4caf50', shape: 'arrowDown', text: 'CD', size: 0.6 });
}
if (item.near0_return && Number(item.near0_return) > 0) {
elementMarkers.push({ time: ts, position: 'belowBar', color: '#009688', shape: 'circle', text: `N${Number(item.near0_return)}`, size: 0.6 });
}
});
}
// 保存到全局,供主图合并标记使用
window.kluDivMarkersMain = mainMarkers;
window.kluDivMarkersElement = elementMarkers;
} catch (e) {
console.warn('处理 KLU 背驰标记出错:', e);
window.kluDivMarkers = [];
window.kluDivMarkersMain = [];
window.kluDivMarkersElement = [];
}
} else {
console.log('⚠️ 没有ChanMACD分析数据');
// 无数据时清空本次的 KLU 背驰标记
window.kluDivMarkers = [];
window.kluDivMarkersMain = [];
window.kluDivMarkersElement = [];
}
} else {
console.log('⚠️ ChanMACD图表创建条件不满足');
}
// 独立于当前显示周期:计算主/次周期 SD/CD 标记(用于主图合并显示)
try {
const mainCmAll = currentData.chan_macd || {};
const elementCmAll = currentData.element_chan_macd || {};
const mainMarkersAll = [];
const elementMarkersAll = [];
if ((typeof window.showUOnMain === 'undefined' ? true : window.showUOnMain) && Array.isArray(mainCmAll.klu_list)) {
mainCmAll.klu_list.forEach((item) => {
if (!item || !item.time) return;
const ts = Math.floor(new Date(item.time).getTime() / 1000);
if (isNaN(ts)) return;
if (item.separate_div === true) {
mainMarkersAll.push({ time: ts, position: 'aboveBar', color: '#03a9f4', shape: 'arrowUp', text: 'SD', size: 0.6 });
}
if (item.continue_div === true) {
mainMarkersAll.push({ time: ts, position: 'belowBar', color: '#ff9800', shape: 'arrowDown', text: 'CD', size: 0.6 });
}
if (item.near0_return && Number(item.near0_return) > 0) {
mainMarkersAll.push({ time: ts, position: 'belowBar', color: '#8bc34a', shape: 'circle', text: `N${Number(item.near0_return)}`, size: 0.6 });
}
});
}
if ((typeof window.showUOnElement === 'undefined' ? true : window.showUOnElement) && Array.isArray(elementCmAll.klu_list)) {
elementCmAll.klu_list.forEach((item) => {
if (!item || !item.time) return;
const ts = Math.floor(new Date(item.time).getTime() / 1000);
if (isNaN(ts)) return;
if (item.separate_div === true) {
elementMarkersAll.push({ time: ts, position: 'aboveBar', color: '#9c27b0', shape: 'arrowUp', text: 'SD', size: 0.6 });
}
if (item.continue_div === true) {
elementMarkersAll.push({ time: ts, position: 'belowBar', color: '#4caf50', shape: 'arrowDown', text: 'CD', size: 0.6 });
}
if (item.near0_return && Number(item.near0_return) > 0) {
elementMarkersAll.push({ time: ts, position: 'belowBar', color: '#009688', shape: 'circle', text: `N${Number(item.near0_return)}`, size: 0.6 });
}
});
}
window.kluDivMarkersMain = mainMarkersAll;
window.kluDivMarkersElement = elementMarkersAll;
} catch (e) {
console.warn('独立计算 KLU 背驰标记出错:', e);
window.kluDivMarkersMain = [];
window.kluDivMarkersElement = [];
}
// 实现三图联动滚动
// 同步图表的时间范围
@@ -5380,7 +5432,8 @@
const combinedMarkers = [
...(window.mainFxMarkers || []),
...allElementFxMarkers,
...(window.kluDivMarkers || [])
...(window.kluDivMarkersMain || []),
...(window.kluDivMarkersElement || [])
];
if (combinedMarkers.length > 0) {
console.log('合并设置', combinedMarkers.length, '个标记(主周期分型:', (window.mainFxMarkers || []).length, '个,小周期分型:', allElementFxMarkers.length, '个,UnitTF:', (window.unittfMarkers || []).length, '个)');
@@ -5403,7 +5456,8 @@
// 只设置主周期分型 + UnitTF 标记
const onlyMainAndU = [
...(window.mainFxMarkers || []),
...(window.kluDivMarkers || [])
...(window.kluDivMarkersMain || []),
...(window.kluDivMarkersElement || [])
];
if (onlyMainAndU.length > 0) {
console.log('仅设置', onlyMainAndU.length, '个主周期/UnitTF标记(主周期分型:', (window.mainFxMarkers || []).length, 'UnitTF:', (window.unittfMarkers || []).length, '');