using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

using MS;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MarketMeannessIndex : Indicator
    {
        [Parameter("Time Period", DefaultValue = 20, MinValue = 2)]
        public int TimePeriod { get; set; }
 
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Output("MMI", LineColor = "Orange")]
        public IndicatorDataSeries Result { get; set; }

        // Instance of the MMI class to handle all MMI calculations.
        private MMI _mmiCalculator; 
        private int _lastIndex = -1;

        protected override void Initialize()
        {
            // Initialize the MMI calculator with the specified TimePeriod.
            _mmiCalculator = new MMI(TimePeriod); // Use new class name MMI
        }

        public override void Calculate(int index)
        {
            Result[index] = _mmiCalculator.Update(Source[index], index > _lastIndex);
            _lastIndex = index;
        }
    }
}