添加默认均线

This commit is contained in:
jackyu66git
2025-07-02 01:14:14 +08:00
parent 717332196c
commit dc5b130862
+58
View File
@@ -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);