Web 加上资金面/情绪叠图,并收紧默认图面。

默认主/次/次次改为 45m/15m/5m、开始时间一周;SD/CD 按 hist 摆位置和箭头;去掉笔线段背驰与第四类勾选。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jackyu66git
2026-09-12 02:25:44 +08:00
co-authored by Cursor
parent b301ad22c9
commit c22cd48f36
24 changed files with 1200 additions and 306 deletions
+32 -13
View File
@@ -229,29 +229,29 @@ function updateTradingViewData(options) {
}
// 更新MACD数据
if (tvWidget.series.macdLineSeries && currentData.macd && currentData.kline_data && Array.isArray(currentData.kline_data)) {
// 提取MACD数据
const macdKlineSrc = useSubSubPeriod ? (currentData.sub_sub_kline_data || []) : (useElementPeriod ? (currentData.element_kline_data || []) : (currentData.kline_data || []));
const macdSrc = useSubSubPeriod ? (currentData.sub_sub_macd || currentData.macd) : (useElementPeriod ? (currentData.element_macd || currentData.macd) : currentData.macd);
if (tvWidget.series.macdLineSeries && macdSrc && macdKlineSrc && Array.isArray(macdKlineSrc)) {
const macdData = [];
const signalData = [];
const histogramData = [];
for (let i = 0; i < currentData.kline_data.length; i++) {
const kline = currentData.kline_data[i];
for (let i = 0; i < macdKlineSrc.length; i++) {
const kline = macdKlineSrc[i];
const timestamp = Math.floor(new Date(kline.date).getTime() / 1000);
if (currentData.macd && currentData.macd.macd && currentData.macd.macd[i] !== undefined) {
if (macdSrc && macdSrc.macd && macdSrc.macd[i] !== undefined) {
macdData.push({
time: timestamp,
value: currentData.macd.macd[i]
value: macdSrc.macd[i]
});
signalData.push({
time: timestamp,
value: currentData.macd.signal[i]
value: macdSrc.signal[i]
});
// 设置直方图颜色
const histValue = currentData.macd.histogram[i];
const histValue = macdSrc.histogram[i];
histogramData.push({
time: timestamp,
value: histValue,
@@ -309,6 +309,9 @@ function updateTradingViewData(options) {
}
);
}
if (typeof refreshUnittfOverlayFromData === 'function') {
refreshUnittfOverlayFromData(currentData);
}
} catch (e) {
console.warn('更新ChanMACD标注失败:', e);
}
@@ -331,7 +334,8 @@ function updateTradingViewData(options) {
tvWidget.volumeChart,
tvWidget.atrChart,
tvWidget.macdChart,
tvWidget.chanMacdChart
tvWidget.chanMacdChart,
tvWidget.sentimentChart
].filter(Boolean);
const vr = clampedVisibleRange || savedVisibleRange;
@@ -409,8 +413,11 @@ function bindSyncEvents(mainChartContainer, volumeChartContainer, atrChartContai
volume: false,
atr: false,
macd: false,
chanmacd: false
chanmacd: false,
sentiment: false
};
const sentimentChart = tvWidget && tvWidget.sentimentChart;
const sentimentChartContainer = tvWidget && tvWidget.sentimentChartContainer;
// 同步图表的时间范围
function syncCharts(sourceChart, sourceContainer) {
@@ -438,6 +445,9 @@ function bindSyncEvents(mainChartContainer, volumeChartContainer, atrChartContai
if (showMacd && chanMacdChart && sourceChart !== chanMacdChart && chanMacdChart.timeScale) {
try { chanMacdChart.timeScale().setVisibleLogicalRange(logicalRange); } catch (e) {}
}
if (sentimentChart && sourceChart !== sentimentChart && sentimentChart.timeScale) {
try { sentimentChart.timeScale().setVisibleLogicalRange(logicalRange); } catch (e) {}
}
if (tvWidget && tvWidget.state) {
tvWidget.state.logicalRange = logicalRange;
@@ -458,7 +468,8 @@ function bindSyncEvents(mainChartContainer, volumeChartContainer, atrChartContai
chart === volumeChart ? 'volume' :
chart === atrChart ? 'atr' :
chart === macdChart ? 'macd' :
chart === chanMacdChart ? 'chanmacd' : 'unknown';
chart === chanMacdChart ? 'chanmacd' :
chart === sentimentChart ? 'sentiment' : 'unknown';
const timeRangeHandler = () => {
if (!syncInProgress) {
@@ -515,6 +526,9 @@ function bindSyncEvents(mainChartContainer, volumeChartContainer, atrChartContai
if (showMacd && chanMacdChartContainer && chanMacdChart) {
addChartSyncEvents(chanMacdChartContainer, chanMacdChart);
}
if (sentimentChartContainer && sentimentChart) {
addChartSyncEvents(sentimentChartContainer, sentimentChart);
}
// 窗口大小变化时重绘图表 — 使用可清理的方式注册
const resizeHandler = () => {
@@ -533,6 +547,9 @@ function bindSyncEvents(mainChartContainer, volumeChartContainer, atrChartContai
if (showMacd && chanMacdChart && chanMacdChartContainer) {
chanMacdChart.applyOptions({ width: chanMacdChartContainer.clientWidth, height: chanMacdChartContainer.clientHeight });
}
if (sentimentChart && sentimentChartContainer) {
sentimentChart.applyOptions({ width: sentimentChartContainer.clientWidth, height: sentimentChartContainer.clientHeight });
}
setTimeout(() => { if (mainChart) syncCharts(mainChart, mainChartContainer); }, 200);
};
window.addEventListener('resize', resizeHandler);
@@ -549,9 +566,11 @@ function setupTooltip(mainChart, buyMarkers = [], sellMarkers = [], mainChartCon
// 初始化 U 显示状态(主/次周期分开控制)
const isShowUMain = $('#toggleUOnMain').is(':checked');
const isShowUElement = $('#toggleUOnElement').is(':checked');
const isShowUSubSub = $('#toggleUOnSubSub').is(':checked');
window.showUOnMain = isShowUMain;
window.showUOnElement = isShowUElement;
if (!isShowUMain && !isShowUElement) {
window.showUOnSubSub = isShowUSubSub;
if (!isShowUMain && !isShowUElement && !isShowUSubSub) {
// 隐藏时清空子图上的 U 标记
if (tvWidget.series && tvWidget.series.chanMacdLineSeries) {
try { tvWidget.series.chanMacdLineSeries.setMarkers([]); } catch (e) {}