/**
 * Indicator Definition Object for SMA.
 */
const SMA_INDICATOR = {
    name: 'SMA',
    label: 'Simple Moving Average',
    usesBaseData: false, // This simple indicator uses the chart's currently displayed data
    params: [
        { name: 'period', type: 'number', defaultValue: 20, min: 2 },
    ],
    calculateFull: calculateFullSMA,
};

function calculateFullSMA(data, params) {
    const period = params.period;
    if (!data || data.length < period) return [];
    let smaData = [];
    let sum = 0;
    for (let i = 0; i < period; i++) {
        sum += data[i].close;
    }
    smaData.push({ time: data[period - 1].time, value: sum / period });
    for (let i = period; i < data.length; i++) {
        sum = sum - data[i - period].close + data[i].close;
        smaData.push({ time: data[i].time, value: sum / period });
    }
    return smaData;
}
