HMA Hull Moving Average Multi Time Frame free

by BullittTraders in category Trend at 22/12/2019
Description

The Hull Moving Average (HMA) is one more alternative of an ideal MA that enables smoothing price movements with the help of weighted averages. The indicator was created by Alan Hull.

HMA(n) = WMA(2*WMA(n/2) – WMA(n)),sqrt(n))

Thanks to Paul and Click Algo which develop it for me. I want to give you also this nice Indicator.

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐using cAlgo.API;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HMAMTF : Indicator
    {
        [Parameter("TimeFrame")]
        public TimeFrame CustomTimeFrame { get; set; }

        [Parameter("Price")]
        public HMA.PriceType Price { get; set; }

        [Parameter("Period", DefaultValue = 14, MinValue = 1)]
        public int Period { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Weighted)]
        public MovingAverageType MaType { get; set; }


        [Output("UpTrend", PlotType = PlotType.DiscontinuousLine, LineColor = "#00FFFF", Thickness = 3)]
        public IndicatorDataSeries UpTrend { get; set; }

        [Output("DownTrend", PlotType = PlotType.DiscontinuousLine, LineColor = "#DC143C", Thickness = 3)]
        public IndicatorDataSeries DownTrend { get; set; }

        public IndicatorDataSeries Result { get; private set; }

        private MarketSeries _marketSeries;
        private HMA _hma;

        protected override void Initialize()
        {
            Result = CreateDataSeries();

            _marketSeries = MarketData.GetSeries(CustomTimeFrame);
            _hma = Indicators.GetIndicator<HMA>(_marketSeries, Price, Period, MaType);
        }

        public override void Calculate(int index)
        {
            var barIndex = _marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            if (barIndex < 0)
                return;

            var result = _hma.Result[barIndex];
            var trend = _hma.Trend[barIndex];

            for (var i = index; i >= MarketSeries.OpenTime.GetIndexByTime(_marketSeries.OpenTime[barIndex]); i--)
            {
                Result[i] = result;

                if (trend > 0)
                {
                    UpTrend[i] = result;
                    UpTrend[i - 1] = Result[i - 1];
                    DownTrend[i] = double.NaN;
                }
                else if (trend < 0)
                {
                    DownTrend[i] = result;
                    DownTrend[i - 1] = Result[i - 1];
                    UpTrend[i] = double.NaN;
                }
            }
        }
    }
}
Comments
5