Category Trend  Published on 06/03/2020

Keltner Channel MA Guild

Description

This Keltner Channel indicator  moves with the trend.

It can be used for getting in on the trend.

It uses an additional Moving average to guild the Keltner Channel,  .This indicator uses the SLOPE ANGLE of the Moving Average to adjust the Keltner.

USEAGE NOTES

1. It is important for the moving average to be as Large and  smooth as possible and should be the first adjustment. 

    Adjust the Guild Moving Average Settings.

2. The Keltner adjustment needs to be a size, that the Moving Average can follow. Adjust this Next

3. Adjust the Correction Factor setting to apply the slope angle of the moving average to the Keltner channel. The value represents the maximum deviation.

    This Correction Factor, is the sensitivity of the correction.

4. Addition settings - Height Offset and Extend to future, are just addition features and do not  have any special function.

 

   If the smoothing is not good enough, the lines will swing.

   You will only see measurable results on a trending market.

by Paul Williams paul.williams125.yahoo.co.uk

my source code is included with notes.

--------------

In the Photo the purple lines are standard Keltner Channel

The Keltner MA indicator,  is the White lines and green centre.  The Currency is the EURUSD
 


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class KeltnerMAAdjust : Indicator
    {
        private IndicatorDataSeries dataseries;
        private IndicatorDataSeries masmooth;
        private MovingAverage _ma;
        private KeltnerChannels _keltner;

        [Parameter("Period", Group = "Guild MA Settings", DefaultValue = 55)]
        public int period { get; set; }

        [Parameter("MA Smooth Period", Group = "Guild MA Settings", DefaultValue = 20)]
        public int smoothperiod { get; set; }

        [Parameter("Type", Group = "Guild MA Settings", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType matype { get; set; }

        [Parameter("Guild MA Line On", Group = "Setup Settings", DefaultValue = false)]
        public bool malineon { get; set; }

        [Parameter("Correction Factor", Group = "Band Settings", DefaultValue = 0.6)]
        public double B { get; set; }

        [Parameter("Height Offset", Group = "Band Settings", DefaultValue = 0.0)]
        public double C { get; set; }

        [Parameter("Extend to Future", Group = "Band Settings", DefaultValue = 0)]
        public int D { get; set; }

        [Parameter("Period", Group = "Keltner Settings", DefaultValue = 60)]
        public int keltnerperiod { get; set; }

        [Parameter("ATR Period", Group = "Keltner Settings", DefaultValue = 120)]
        public int atrperiod { get; set; }

        [Parameter("Deviation", Group = "Keltner Settings", DefaultValue = 2)]
        public double deviation { get; set; }

        [Parameter("Type", Group = "Keltner Settings", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType keltnermatype { get; set; }

        [Parameter("ATR Type", Group = "Keltner Settings", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType atrmatype { get; set; }


        [Output("Upper", LineColor = "White", Thickness = 1, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries upper { get; set; }

        [Output("Lower", LineColor = "White", Thickness = 1, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries lower { get; set; }

        [Output("middle", LineColor = "Green", Thickness = 1, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries middle { get; set; }

        [Output("Guild MA Line", LineColor = "Purple", Thickness = 1, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries guildmaline { get; set; }

        double slopemax, slopeaverage, correction, maslope, maslopeback1;
        double pipsize;

        protected override void Initialize()
        {
            dataseries = CreateDataSeries();
            masmooth = CreateDataSeries();
            _ma = Indicators.MovingAverage(dataseries, period, matype);
            _keltner = Indicators.KeltnerChannels(keltnerperiod, keltnermatype, atrperiod, atrmatype, deviation);
            pipsize = Symbol.PipSize;

        }

        public override void Calculate(int index)
        {
//---------                                                                                  This improves smoothness by 5%. Rather than using Bars.ClosePrices.
            dataseries[index] = (Bars.OpenPrices[index] + Bars.ClosePrices[index]) / 2;

            if (index > 2)
            {
//---------                                                                                   Primary smooth the MA           
                masmooth[index] = _ma.Result.Sum(smoothperiod) / smoothperiod;

//---------                                                                                   Tried using this little trick (maslopeback1 = maslope)  but this doesnt seem to be reliable ?. So recalculated it here, instead.
                maslopeback1 = (masmooth[index - 1] - masmooth[index - 2]) / pipsize;

//---------                                                                                   This calculates the Slope or Angle of the moving average.. This indicator uses the Slope Angle to adjust the Keltner.
                maslope = (masmooth[index] - masmooth[index - 1]) / pipsize;
//---------                                                                                   This code makes the slope angle - more stable.
//---------                                                                                   I have found that some currencies have large "gap ups" or "gaps down", in the prices. This messes up the slopemax.
//---------                                                                                   I have added limiter code.  This stops any value, that is too large adding to slopemax.
                if (maslope > 2 * slopemax)
                    maslope = maslopeback1;

//---------                                                                                   This code, finds the largest, maximum size that the slope can be.. for a benchmark for the averaging in the next step.
//---------                                                                                   Its so, the indicator can be used on all currencies and timeframes.
                if (maslope > slopemax)
                    slopemax = maslope;

//---------                                                                                   This averages, so that the maximum will never exceed 100 or 100%
                slopeaverage = ((maslope / slopemax) + C) * 100;
//---------                                                                                   correction - variably adjusts the band distance. B - is the variable band distance sensitivity.
                correction = slopeaverage * (B / 100);


                upper[index + D] = _keltner.Top[index] + (_keltner.Top[index] * correction) / 100;
                lower[index + D] = _keltner.Bottom[index] - (_keltner.Bottom[index] * -correction) / 100;
                middle[index + D] = (upper[index] - lower[index]) / 2 + lower[index];

                if (malineon == true)
                    guildmaline[index] = masmooth[index];
            }


        }
    }
}


PA
paul.williams125

Joined on 03.12.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Keltner MA Adjust.algo
  • Rating: 5
  • Installs: 1494
Comments
Log in to add a comment.
PA
paul.williams125 · 4 years ago

Now on Revision 4

1. This code makes the slope angle - more stable.

I have found that recently, some currencies have had large "gap ups" or "gaps down", in the prices. This messes up the slopemax.

 I have added, limiter code.  This stops any Bar / Gap, that is too large, adding to slopemax.

PA
paul.williams125 · 4 years ago

Revision 3

1. Secondary smoothing deleted - not needed

2. Clearer interface.

3. More sensitivity with the correction Factor.

4. Easier to use.

5. Parameter guild notes updated.

MA
Mastah1238 · 4 years ago

Hi

Could you write some simple guide what are the parameters used for?

PA
paul.williams125 · 4 years ago

Revision 2

1. Minor improvements to the code.

2. Ive added a setup feature.  To setup the guild Moving Average.