From dc5b1308624b76aeb4000fc1605daafa68beec75 Mon Sep 17 00:00:00 2001 From: jackyu66git Date: Wed, 2 Jul 2025 01:14:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=9D=87?= =?UTF-8?q?=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/templates/index.html | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/web/templates/index.html b/web/templates/index.html index 9ebb94b..1d6b367 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -1279,6 +1279,61 @@ } }; + // 添加默认EMA线 + function addDefaultEMALines() { + if (!tvWidget.mainChart || !currentData || !currentData.kline_data) { + console.log('图表或数据未准备好,跳过默认EMA添加'); + return; + } + + console.log('开始检查和添加默认EMA线'); + + // 默认EMA配置 + const defaultEMAConfigs = [ + { period: 5, color: '#FF0000', name: 'EMA5' }, // 红色 + { period: 10, color: '#0000FF', name: 'EMA10' }, // 蓝色 + { period: 26, color: '#00FF00', name: 'EMA26' }, // 绿色 + { period: 52, color: '#800080', name: 'EMA52' } // 紫色 + ]; + + // 延迟添加EMA,确保图表完全准备好 + setTimeout(() => { + defaultEMAConfigs.forEach(config => { + // 检查是否已经存在相同周期的EMA + const existingEMA = movingAverages.find(ma => + ma.type === 'EMA' && + ma.period === config.period && + ma.source === 'close' + ); + + if (existingEMA) { + console.log(`${config.name}已存在,跳过添加`); + return; + } + + try { + const emaConfig = { + type: 'EMA', + period: config.period, + source: 'close', + color: config.color, + smoothing: 'none', + smoothingPeriod: 3, + lineWidth: 1, + style: 'solid' + }; + + addMovingAverageToChart(emaConfig); + console.log(`已添加默认${config.name},颜色:${config.color}`); + } catch (error) { + console.error(`添加${config.name}时出错:`, error); + } + }); + + console.log('默认EMA线检查和添加完成'); + }, 100); + } + // 初始化均线系统事件处理程序 function initMovingAverageEvents() { // 均线按钮点击事件 @@ -3897,6 +3952,9 @@ // 添加买卖点提示 setupTooltip(mainChart, [], [], mainChartContainer, volumeChartContainer, macdChartContainer, atrChartContainer, volumeChart, macdChart, atrChart, showMacd); + // 添加默认EMA线 + addDefaultEMALines(); + console.log('图表初始化完成'); } catch (e) { console.error('图表初始化错误:', e);