cTrader HMA Signals free

by ClickAlgo in category Trend at 20/08/2015
Description

This cTrader HMA indicator is an extension to the Hull Moving Average where it shows optional signals for trend:-

  • Optional Arrows on chart where trend changes
  • Optional Text on chart displaying trend direction
  • Optional display of HULL line, only display trend description.
  • Set how far away the arrow is spaced from the HMA with different time-frames.
  • Two public properties for usage with cBots

 

Usage with cBots

If you reference this indicator from your cBot you can use the IsBullish and IsBearish properties to determine an additional signal to help you buy or sell.

This is best for daily trends, but you can change the time-frame in your cBot code.

declare private variable's

private MarketSeries HmaDaySeries;
private HMASignals hmaSignal;

 

In the OnStart method construct your timeframe

HmaDaySeries = MarketData.GetSeries(TimeFrame.Daily);

 

Also in your OnStart method create your hmaSignal object.

hmaSignal = Indicators.GetIndicator(HmaDaySeries, 21, false, false, 3, false, 24);

 

Now use this as follows in your robots.

// forces loading hma object with values
double i = hmaSignal.hma.LastValue;

// If HMA daily trend is active then only trade where the signals are buy or sell
if (hmaSignal.IsBullish)
{
    // Only BUY
}

if (hmaSignal.IsBearish)
{
    // Only SELL
}

Paul Hayes
Sales & Marketing
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com

Twitter | Facebook | YouTube | Pinterest | LinkedIn

PS: Why not join our instant chat group on Telegram.

 


 

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 System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class HMASignals : Indicator
    {
        [Output("HMA", Color = Colors.Orange)]
        public IndicatorDataSeries hma { get; set; }

        [Parameter(DefaultValue = 21)]
        public int Period { get; set; }

        [Parameter("Display Line", DefaultValue = true)]
        public bool DisplayHullLine { get; set; }

        [Parameter("Display Trend Signal", DefaultValue = true)]
        public bool DisplayTrendSignal { get; set; }

        [Parameter("Display Position, 1-8", DefaultValue = 5, MinValue = 1, MaxValue = 8)]
        public int DisplayPostion { get; set; }

        [Parameter("Display Arrow Signal", DefaultValue = true)]
        public bool DisplayArrowSignal { get; set; }

        [Parameter("Arrow Spacing from Line", DefaultValue = 50)]
        public int ArrowSpacing { get; set; }

        private IndicatorDataSeries diff;
        private WeightedMovingAverage wma1;
        private WeightedMovingAverage wma2;
        private WeightedMovingAverage wma3;

        private string trend = string.Empty;
        private Colors trendColor = Colors.Red;
        private StaticPosition position;

        private bool bullishArrowDrawn = false;
        private bool bearishArrowDrawn = false;

        public bool IsBullish = false;
        public bool IsBearish = false;

        double var1 = 0;
        double var2 = 0;

        protected override void Initialize()
        {
            var index = MarketSeries.Close.Count - 1;

            diff = CreateDataSeries();
            wma1 = Indicators.WeightedMovingAverage(MarketSeries.Close, (int)Period / 2);
            wma2 = Indicators.WeightedMovingAverage(MarketSeries.Close, Period);
            wma3 = Indicators.WeightedMovingAverage(diff, (int)Math.Sqrt(Period));

            var1 = 2 * wma1.Result[index];
            var2 = wma2.Result[index];

            diff[index] = var1 - var2;
        }

        public override void Calculate(int index)
        {
            var1 = 2 * wma1.Result[index];
            var2 = wma2.Result[index];

            diff[index] = var1 - var2;

            if (DisplayHullLine)
                hma[index] = wma3.Result[index];

            // BEARISH
            if (wma3.Result.IsFalling())
            {
                IsBearish = true;
                IsBullish = false;
                trend = "BEARISH (hma)";
                trendColor = Colors.Red;
            }

            // BULLISH
            if (wma3.Result.IsRising())
            {
                IsBearish = false;
                IsBullish = true;
                trend = "BULLISH (hma)";
                trendColor = Colors.Green;
            }

            switch (DisplayPostion)
            {
                case 1:
                    position = StaticPosition.TopLeft;
                    break;
                case 2:
                    position = StaticPosition.TopCenter;
                    break;
                case 3:
                    position = StaticPosition.TopRight;
                    break;
                case 4:
                    position = StaticPosition.Right;
                    break;
                case 5:
                    position = StaticPosition.BottomRight;
                    break;
                case 6:
                    position = StaticPosition.BottomCenter;
                    break;
                case 7:
                    position = StaticPosition.BottomLeft;
                    break;
                case 8:
                    position = StaticPosition.Left;
                    break;
                default:
                    position = StaticPosition.TopLeft;
                    break;
            }

            if (DisplayTrendSignal)
                ChartObjects.DrawText("trendText", trend, position, trendColor);

            if (DisplayArrowSignal)
            {
                if (IsBullish && !bullishArrowDrawn)
                {
                    ChartObjects.DrawText(String.Format("Arrow{0}", index), "▲", index, wma3.Result.LastValue - Symbol.PipSize * ArrowSpacing, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Green);
                    bullishArrowDrawn = true;
                    bearishArrowDrawn = false;
                }

                if (IsBearish && !bearishArrowDrawn)
                {
                    ChartObjects.DrawText(String.Format("Arrow{0}", index), "▼", index, wma3.Result.LastValue + Symbol.PipSize * ArrowSpacing, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Red);
                    bearishArrowDrawn = true;
                    bullishArrowDrawn = false;
                }
            }
        }
    }
}
Comments

hiba7rain - August 20, 2015 @ 10:59

Paul

your work should be appreciated by all CTDN users -:) , you are providing a valuable inputs and comments, i have just download it and i will test it and give you my feedback  

ClickAlgo - August 20, 2015 @ 11:09

Thanks, I am just in a quiet period at work, so keeping myself busy. 

hiba7rain - August 20, 2015 @ 11:15

:)

hiba7rain - August 21, 2015 @ 10:07

Hey Paul 

just a question, have you included email alert on your first version because am not sure i thought that i saw the option available  :)

ClickAlgo - August 21, 2015 @ 10:18

Hi, I did, but took it out, it was an idea that when the trend changes on a larger time-frame; for example daily, an email is sent to you so you can look at additional signals to help decide on what to do.

If you want it then just look in the API reference:-

http://ctdn.com/api/reference/internals/inotifications/sendemail-5edf

hiba7rain - August 21, 2015 @ 10:27

hi 

i think the frequency of emails out will be an issue i have not try it yet but i just assume that will be the case 

ClickAlgo - August 21, 2015 @ 10:32

you can code it so only one email is sent when the trend first changes direction like when the arrow is drawn or else yes it will fire off emails continually while the IsBullish or IsBearish values are true.

ellcz - August 23, 2015 @ 04:18

Did EXACTLY what you said, got two errors. 

 

Error CS0103: The name `hmaSignal' does not exist in the current context. And next error is..

 

Error CS0411: The type arguments for method cAlgo.API.Internals.IIndicatorsAccessor.GetIndicator<TIndicator>(params object[]) cannot be inferred from the usage. Try specifying the type arguments explicitly.

 

Any help? please?

ClickAlgo - August 23, 2015 @ 05:44

Hi Ellcz,

Thank you for spotting an error, I added an extra user defined parameter and did not update the documentation correctly, 

hmaSignal = Indicators.GetIndicator(HmaDaySeries, 21, false, false, 3, false, 50);

As you see above the last parameter was missing for the arrow spacing.

This still does not solve the first error you are getting; the first error sounds like you don't have a reference to the indicator from your cBot, did you add this reference?

Can you post a code example here on how you are calling the GetIndicator method please

ClickAlgo - August 23, 2015 @ 05:52

Hello again Ellcz,

You did everything correct, it was my fault, a private variable declaration was missing, add this and it should work:-

private HMASignals hmaSignal;

 

ellcz - August 24, 2015 @ 01:38

Well, I'm still learning C# so... It's ok. I knew there is missing something, but i could not find it. However, when I update your code like this, compiler still saying that error "Error CS0411: The type arguments for method cAlgo.API.Internals.IIndicatorsAccessor.GetIndicator<TIndicator>(params object[]) cannot be inferred from the usage. Try specifying the type arguments explicitly."

What is this? Shouldn't we do it like in this example "sma = Indicators.GetIndicator<SampleSMA>(Source, SmaPeriod);" instead of "hmaSignal = Indicators.GetIndicator(HmaDaySeries, 21, falsefalse, 3, false, 50);

 

Or these brackets <> doesn't work for custom indis?

ellcz - August 24, 2015 @ 01:48

I'm totally out of ideas now.. :/ I wanted to try this indicator for my own cbot, so i have only this code. Did i forget something? Ummm, your HMA Signal is added as reference. (Via Manage References)

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HMASmartBotFirstEdition : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        private MarketSeries HmaDaySeries;
        private HMASignals hmaSignal;

        protected override void OnStart()
        {
            // Put your initialization logic here
            HmaDaySeries = MarketData.GetSeries(TimeFrame.Daily);
            hmaSignal = Indicators.GetIndicator(HmaDaySeries, 21, falsefalse, 3, false, 50);
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

ClickAlgo - August 24, 2015 @ 07:09

I don't know why, but when i copy/paste from visual studio it stripped some of the text, I had to paste into notepad and then paste into here, it is correct now:-

hmaSignal = Indicators.GetIndicator<HMASignals>(HmaDaySeries, 21, false, false, 3, false, 24);

hiba7rain - August 24, 2015 @ 08:02

Hey Paul,

yes i noticed that it was missing <HMASignals> and Private HMAsignals,  I have add it and I got no error, i thought you must missed to include it :)

I See that you have included 24 on (HmaDaySeries, 21, false, false, 3, false, 24);

ClickAlgo - August 24, 2015 @ 08:46

Yes, that's the spacing for the arrow from hma line, use any value from your cBot, not tried it will null.

ellcz - August 25, 2015 @ 00:23

Oh Im stupid.. I almost fixed it on my own.. But when i updated this code "<HMASignals>" calgo fixed it automatically to "<HMASignal>" so there was new error which makes me cunfused.. 

 

However, i made it thanks to you Paul. And it is profitable on its own with some good settings. I will probably update this and see what i can do. :) 

For now i added just TP and SL.

 

So thanks again! 

 

Mr Lime - October 23, 2015 @ 17:27

@Paul_Hayes

Thanks very much for this, my scalping algo was just just causing havoc on big moves, this is exactly what I wanted to do with it!

Wanted a higher TF HMA for larger direction for opening trades, and you did it! :)

Mr Lime - October 24, 2015 @ 18:47

is this correct for referencing and changing HTF HMA?

        [Parameter("HMA HTF Period", DefaultValue = 1, MinValue = 1, MaxValue = 200, Step = 1)]
        public double Parameter { get; set; }

I need to change HMA on the set timeframe.

Mr Lime - November 05, 2015 @ 17:54

I figured it out :)

hiba7rain - May 19, 2016 @ 17:49

hey Paul

nice to see the new updates you know most i like is hma :)

just a question how to use it on smartgrid cbot to reduce the drawdown 

thanks

ClickAlgo - May 23, 2016 @ 07:04

quite simply add indicator to cbot and use properties, IsBullish and IsBearish to decide if you should open long or short positions.

Serpico - July 12, 2016 @ 06:54

Thanks for this Indicator, can someone make a cbot of this or explain were to insert the imputs the creator of this mentioned but not very clear were they should be, i have tried with Smart grid but no succes 

Thanks in advance

erikvb - February 09, 2019 @ 21:38

Hello , i get some error when i try the robot ?

someone have the robot running ?

i installed the indicator , and work fine.

 

Severity Code Description Project File Line Suppression State

Error CS0234 The type or namespace name 'HMASingal' does not exist in the namespace 'cAlgo' (are you missing an assembly reference?) HMASignals d:\Users\Erik\Documents\cAlgo\Sources\Robots\HMASignals\HMASignals\HMASignals.cs 3 Active

Severity Code Description Project File Line Suppression State

Error CS0052 Inconsistent accessibility: field type 'HMASignals' is less accessible than field 'HMASmartBotFirstEdition.hmaSignals' HMASignals d:\Users\Erik\Documents\cAlgo\Sources\Robots\HMASignals\HMASignals\HMASignals.cs 11 Active

Severity Code Description Project File Line Suppression State

Error CS0118 'HMASignals' is a type but is used like a variable HMASignals d:\Users\Erik\Documents\cAlgo\Sources\Robots\HMASignals\HMASignals\HMASignals.cs 20 Active

Severity Code Description Project File Line Suppression State

Error CS0246 The type or namespace name 'HMASignal' could not be found (are you missing a using directive or an assembly reference?) HMASignals d:\Users\Erik\Documents\cAlgo\Sources\Robots\HMASignals\HMASignals\HMASignals.cs 20 Active

 

 

using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.HMASingal;
namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HMASmartBotFirstEdition : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        public HMASignals hmaSignals;

        private MarketSeries HmaDaySeries;
        private HMASignals _hmaSignal;

        protected override void OnStart()
        {
            // Put your initialization logic here
            HmaDaySeries = MarketData.GetSeries(TimeFrame.Daily);
            HMASignals = Indicators.GetIndicator<HMASignal>(HmaDaySeries, 21, false, false, 3, false, 50);
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }

    internal class HMASignals
    {
    }
}

janiolos - September 20, 2019 @ 07:32

Hey Guys,

I have developed the Telegram interface for this indicator, now we can send a telegra m message when the arrow is written.

Who wants more information, call me in private.

 

Att

janiolos - September 20, 2019 @ 07:33

I have a question!

Do this indicator repaint?

4