Keltner Channel MA Guild free

by paul.williams125 in category Trend at 14/02/2020
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. 

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

3. Adjust the Position / Width setting to apply the slope angle of the moving average to the Keltner channel. The value represents the maximum deviation.

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
 

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.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 = "MA Settings", DefaultValue = 34)]
        public int period { get; set; }

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

        [Parameter("Type", Group = "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("Position / Width", Group = "Band Settings", DefaultValue = 6.0)]
        public double B { get; set; }

        [Parameter("Slope Smooth Period", Group = "Band Settings", DefaultValue = 20)]
        public int A { 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;
        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 > A)
            {
//---------                                                                                   Primary smooth the MA           
                masmooth[index] = _ma.Result.Sum(smoothperiod) / smoothperiod;
//---------                                                                                   This calculates the Slope or Angle of the moving average.. This indicator uses the Slope Angle to adjust the Keltner.
//---------                                                                                  A -  adjusts the size of the chunk collected for the averaging process later.
//---------                                                                                   the larger the chunks, the smoother the line, This is secondary smoothing, 
//---------                                                                                   at a cost, when the trend changes, it lags.
                maslope = (masmooth[index] - masmooth[index - A]) / pipsize;
//---------                                                                                   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;
//---------                                                                                   average so that the maximum will never exceed 100 or 100%
                slopeaverage = ((maslope / slopemax) + C) * 100;
//---------                                                                                   B - adjusts the band sensitivity or band position/ width. correction is limited to values between 0 and A
//---------                                                                                   values of 0 to A, A - being typically 4. What you normally adjust, called deviaton on Keltner channel settings.
                correction = (slopeaverage * (B / 100));

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

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


        }
    }
}

Comments

paul.williams125 - February 15, 2020 @ 13:49

Revision 2

1. Minor improvements to the code.

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

Mastah1238 - February 17, 2020 @ 18:49

Hi

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

5