示例#1
0
        //for code based construction
        public MHLMA(BarHistory source, Int32 periodHigh, Int32 periodMA, WhichMA choice)
            : base()
        {
            Parameters[0].Value = source;
            Parameters[1].Value = periodHigh;
            Parameters[2].Value = periodMA;
            Parameters[3].Value = choice;

            Populate();
        }
示例#2
0
        //populate
        public override void Populate()
        {
            BarHistory bars       = Parameters[0].AsBarHistory;
            Int32      highPeriod = Parameters[1].AsInt;
            Int32      movPeriod  = Parameters[2].AsInt;
            WhichMA    option     = (WhichMA)Enum.Parse(typeof(WhichMA), Parameters[3].AsString);

            DateTimes = bars.DateTimes;

            var period = Math.Max(highPeriod, movPeriod);

            if (period <= 0 || bars.Count == 0)
            {
                return;
            }

            var tempMHL = new TimeSeries(DateTimes);
            var HH      = new Highest(bars.High, highPeriod);
            var LL      = new Lowest(bars.Low, highPeriod);

            tempMHL = (HH + LL) / 2;

            for (int bar = period; bar < bars.Count; bar++)
            {
                Values[bar] = tempMHL[bar];

                if (option == WhichMA.EMA) //EMA
                {
                    Values[bar] = new EMA(tempMHL, movPeriod)[bar];
                }
                else
                {
                    Values[bar] = new SMA(tempMHL, movPeriod)[bar];
                }
            }
        }