단순이동평균선 이름 표시방식 변경

This commit is contained in:
Macbook
2026-06-13 01:36:03 +09:00
parent 207374a08e
commit beeebed8f4
13 changed files with 106 additions and 51 deletions
+15 -18
View File
@@ -4,7 +4,7 @@
* - MA3 → period3 (예: 20일)
* - MA20 → 레거시: 숫자>11 이면 기간 20일 그대로
*/
import { SMA_DEFAULT_PERIODS, SMA_MA_COUNT } from './smaConfig';
import { SMA_DEFAULT_PERIODS, SMA_MA_COUNT, formatSmaPeriodDisplayLabel } from './smaConfig';
export const MA_DSL_SLOT_MAX = SMA_MA_COUNT;
@@ -45,7 +45,14 @@ export function resolveMaDslFieldPeriod(
return null;
}
/** UI·해석용 라벨 — MA5(60일) */
/** EMA 설정 기간 → EMA5일 */
export function formatEmaPeriodDisplayLabel(period: number | string | boolean | undefined): string {
const raw = typeof period === 'number' ? period : Number(period);
const p = Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 1;
return `EMA${p}`;
}
/** UI·해석용 라벨 — MA20일 */
export function formatMaDslFieldLabel(
field: string | undefined,
smaParams?: Record<string, number | string | boolean>,
@@ -53,18 +60,8 @@ export function formatMaDslFieldLabel(
if (!field) return '';
const period = resolveMaDslFieldPeriod(field, smaParams);
if (period == null) return field;
const ma = /^MA(\d+)$/.exec(field);
if (ma && !field.startsWith('MACD')) {
const n = parseInt(ma[1], 10);
if (n >= 1 && n <= MA_DSL_SLOT_MAX) return `MA${n}(${period}일)`;
return `MA(${period}일)`;
}
const ema = /^EMA(\d+)$/.exec(field);
if (ema) {
const n = parseInt(ema[1], 10);
if (n >= 1 && n <= MA_DSL_SLOT_MAX) return `EMA${n}(${period}일)`;
return `EMA(${period}일)`;
}
if (field.startsWith('EMA')) return formatEmaPeriodDisplayLabel(period);
if (field.startsWith('MA') && !field.startsWith('MACD')) return formatSmaPeriodDisplayLabel(period);
return field;
}
@@ -74,7 +71,7 @@ export function buildMaFieldOptions(
return Array.from({ length: SMA_MA_COUNT }, (_, i) => {
const slot = i + 1;
const p = maLines[i] ?? SMA_DEFAULT_PERIODS[i];
return { value: `MA${slot}`, label: `MA${slot}(${p}일)` };
return { value: `MA${slot}`, label: formatSmaPeriodDisplayLabel(p) };
});
}
@@ -86,7 +83,7 @@ export function buildEmaFieldOptions(
return Array.from({ length: n }, (_, i) => {
const slot = i + 1;
const p = maLines[i] ?? SMA_DEFAULT_PERIODS[i];
return { value: `EMA${slot}`, label: `EMA${slot}(${p}일)` };
return { value: `EMA${slot}`, label: formatEmaPeriodDisplayLabel(p) };
});
}
@@ -102,14 +99,14 @@ export function appendLegacyMaFieldOption(
if (ma && !field.startsWith('MACD')) {
const n = parseInt(ma[1], 10);
if (n > MA_DSL_SLOT_MAX) {
return [...opts, { value: field, label: `MA(${period}일)` }];
return [...opts, { value: field, label: formatSmaPeriodDisplayLabel(period) }];
}
}
const ema = /^EMA(\d+)$/.exec(field);
if (ema) {
const n = parseInt(ema[1], 10);
if (n > MA_DSL_SLOT_MAX) {
return [...opts, { value: field, label: `EMA(${period}일)` }];
return [...opts, { value: field, label: formatEmaPeriodDisplayLabel(period) }];
}
}
return opts;