Category Trend  Published on 05/02/2019

Hull Forcast

Description

This indicattor uses multiple hull moving average weighting to forcast trends. 


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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AutoRescale = false, AccessRights = AccessRights.FullAccess)]
    public class HullForcast : Indicator
    {
        [Parameter("Hull Coverage Period", DefaultValue = 35)]
        public int HullCoveragePeriod { get; set; }

        [Parameter("Hull Coverage Period Devisor", DefaultValue = 1.7)]
        public double HullPeriodDivisor { get; set; }


        [Parameter()]
        public DataSeries Price { get; set; }

        [Parameter("Play Notification", DefaultValue = true)]
        public bool PlayNotifiy { get; set; }

        [Parameter("Notification Sound File", DefaultValue = "")]
        public string Notify { get; set; }


        [Output("Up", PlotType = PlotType.Points, Color = Colors.White, Thickness = 4)]
        public IndicatorDataSeries UpSeries { get; set; }

        [Output("Down", PlotType = PlotType.Points, Color = Colors.Red, Thickness = 4)]
        public IndicatorDataSeries DownSeries { get; set; }

        private DateTime _openTime;

        private HullMovingAverage _movingAverage1;
        private HullMovingAverage _movingAverage2;
        private HullMovingAverage _movingAverage3;
        private IndicatorDataSeries _dataSeries;
        private IndicatorDataSeries _trend;


        protected override void Initialize()
        {
            _dataSeries = CreateDataSeries();
            _trend = CreateDataSeries();

            var period1 = (int)Math.Floor(HullCoveragePeriod / HullPeriodDivisor);
            var period2 = (int)Math.Floor(Math.Sqrt(HullCoveragePeriod));

            _movingAverage1 = Indicators.GetIndicator<HullMovingAverage>(Price, period1);
            _movingAverage2 = Indicators.GetIndicator<HullMovingAverage>(Price, HullCoveragePeriod);
            _movingAverage3 = Indicators.GetIndicator<HullMovingAverage>(_dataSeries, period2);

        }

        private void PlayNotification()
        {
            if (PlayNotifiy)
            {
                if (!File.Exists(Notify))
                {
                    var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                    Notifications.PlaySound(Path.Combine(windowsFolder, "Media", "tada.wav"));
                }
                else
                {
                    Notifications.PlaySound(Notify);
                }
            }
        }

        public override void Calculate(int index)
        {
            if (index < 1)
                return;

            _dataSeries[index] = 2.0 * _movingAverage1.Result[index] - _movingAverage2.Result[index];
            _trend[index] = _trend[index - 1];

            if (_movingAverage3.Result[index] > _movingAverage3.Result[index - 1])
                _trend[index] = 1;
            else if (_movingAverage3.Result[index] < _movingAverage3.Result[index - 1])
                _trend[index] = -1;

            if (_trend[index] > 0)
            {
                UpSeries[index] = _movingAverage3.Result[index];

                if (_trend[index - 1] < 0.0)
                {
                    UpSeries[index - 1] = _movingAverage3.Result[index - 1];

                    if (IsLastBar)
                    {
                        if (MarketSeries.OpenTime[index] != _openTime)
                        {
                            _openTime = MarketSeries.OpenTime[index];

                            PlayNotification();
                        }
                    }
                }
                DownSeries[index] = double.NaN;
            }
            else if (_trend[index] < 0)
            {
                DownSeries[index] = _movingAverage3.Result[index];

                if (_trend[index - 1] > 0.0)
                {
                    DownSeries[index - 1] = _movingAverage3.Result[index - 1];

                    if (IsLastBar)
                    {
                        if (MarketSeries.OpenTime[index] != _openTime)
                        {
                            _openTime = MarketSeries.OpenTime[index];
                            PlayNotification();

                        }
                    }
                }

                UpSeries[index] = double.NaN;
            }

        }

    }
}


shlbnd.ms's avatar
shlbnd.ms

Joined on 10.06.2016

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: HullForcast.algo
  • Rating: 5
  • Installs: 4667
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
DO
dorianse25 · 3 years ago

Why does it ask for FULL ACCESS?

matt92's avatar
matt92 · 5 years ago

Perhaps you could try incorporating this pop up alert window into the current notification. It also has telegram option in settings so it can be used as a great tool for receiving alerts on mobile. If you could possinly make this happen, I would be just ecstatic lol. https://ctrader.com/algos/indicators/show/1692

matt92's avatar
matt92 · 5 years ago

Hey sorry I was wrong, I was able to get the notification to play a sound once I added a sound file to it. So that was a success! The sound notification is only helpful for when at the desk though.. and If you have multiple charts it can be timely to go look at which chart sounded the notification. I am wondering, is there any way to add a pop up alert to this indicator, (same alert - upon dot color change) maybe one that can also send to mobile, maybe via telegram or something.. Thanks a lot for this great indicator.

matt92's avatar
matt92 · 5 years ago

eh bro, havent been able to recieve any notifications upon new dot color change, Are you able to get it to work?

matt92's avatar
matt92 · 5 years ago

Hi, i turned the Play Notification setting to Yes, but I can't seem to get any alerts upon new dot color change.. Any idea as to why that might be? Thanks a lot.

matt92's avatar
matt92 · 5 years ago

*sigh* It seems I'm much worse than you when it comes to responding here lol. Apologies man, I greatly appreciate the reply and the effort for updating a version with notifications! You're the GOAT

shlbnd.ms's avatar
shlbnd.ms · 5 years ago

Matt - Uploaded a version with notifications. 

shlbnd.ms's avatar
shlbnd.ms · 5 years ago

so .... to make sure .... if white .. then truns red ... "Ping".. if red then white "Ping"?    Do you want to calculate this on the start of the time period only aka start of bar 0 or would you like to know and have this "Ping"  as the price action occurs 

shlbnd.ms's avatar
shlbnd.ms · 5 years ago

lol... Just saw this. Yea I can addthat for ya

matt92's avatar
matt92 · 5 years ago

Please? lol ^^

matt92's avatar
matt92 · 5 years ago

Hi there, Great tool! Do you have any way to alert when a new dot has changed color? Thank you.

KE
kenwong423 · 6 years ago

HI .

I want to change this indicator to  cAlgo automatic trading. Can you help me? 

@kenwong423@gmail.com

 

VI
vikramtt · 7 years ago

Hi,

Thank you for the reply, as i said am just learning very basic, am trying to assume what the logic doing in the context even if dont understand some of it.

2. Just line with color change for bullish bearish

Thank you once again for your time.

shlbnd.ms's avatar
shlbnd.ms · 7 years ago

1. I'll see what I can do for you. How familiar are you with the HULL average and how weighted averages work. 

2.  Would you like to toggle between dots and lines or just a line?  Same color line for bullish bearish? Or did you have somthing else in mind? 

VI
vikramtt · 7 years ago

Hi,

was looking for this, I am learning to code, can please help me with following

1. To change the color if the price closes below the period, is below the correct way to do that, am not sure how it will impact later part of code its little advance for me.

if (MarketSeries.Close.Last(1) > _movingAverage3.Result[index - 1])
                _trend[index] = 1;
            else if (MarketSeries.Close.Last(1) < _movingAverage3.Result[index - 1])
                _trend[index] = -1;

2. secondly instead of dotted line can we have line