Category Trend  Published on 29/07/2024

Donchian Smoothed Ma

Description

This trading indicator, called DonchianSmoothingMa, combines the concepts of the Donchian channel and moving averages to smooth out the extreme price levels over a given period. Here's a simplified description of how it works:

Main Parameters:

  • PeriodDonchian: The period used to calculate the Donchian channel.
  • SmoothPeriod: The period used to smooth the Donchian channel values.
  • MaTypeSmooth: The type of moving average used for smoothing (such as simple, exponential, etc.).

Calculating the Donchian Channel:

  • High: The highest closing price during the Donchian period.
  • Low: The lowest closing price during the Donchian period.
  • Middle: The average between the high and low prices.

Smoothing the Values:

  • The high, low, and middle values are smoothed using a moving average over the specified SmoothPeriod.

Displayed Results:

  • ResultUp: The smoothed high value.
  • ResultMidd: The smoothed middle value.
  • ResultDown: The smoothed low value.

How It Works

Initialization:

  • Create data series to store the raw high, low, and middle values.
  • Initialize moving averages to smooth these data series.

Calculation on Each Update:

  • Calculate the high, low, and middle prices for the specified Donchian period.
  • Smooth these values using the moving averages.
  • Update the smoothed results (ResultUp, ResultMidd, ResultDown) with the corresponding smoothed values.

Usage

This indicator is useful for identifying market trends and support and resistance levels. By smoothing the values, it helps reduce noise and provides a clearer representation of critical price levels.

Necessary for the Donchian Smooth Ma All In One Scored :  https://ctrader.com/algos/indicators/show/4411/

Enjoy for Free =) 


Previous account here : https://ctrader.com/users/profile/70920
Contact telegram :  https://t.me/nimi012 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class DonchianSmoothingMa : Indicator
    {
        [Parameter(DefaultValue = 20, Group = "Donchian")]
        public int PeriodDonchian { get; set; }

        [Parameter(DefaultValue = 20, Group = "Smooth Donchian")]
        public int SmoothPeriod { get; set; }

        [Parameter(DefaultValue = MovingAverageType.TimeSeries, Group = "Smooth Donchian")]
        public MovingAverageType MaTypeSmooth { get; set; }

        [Output("ResultUp")]
        public IndicatorDataSeries ResultUp { get; set; }
        [Output("ResultMidd")]
        public IndicatorDataSeries ResultMidd { get; set; }
        [Output("ResultDown")]
        public IndicatorDataSeries ResultDown { get; set; }

        private IndicatorDataSeries reshigh, reslow, resmidd;
        private MovingAverage mahigh, malow, mamidd;

        protected override void Initialize()
        {
            reshigh = CreateDataSeries();
            resmidd = CreateDataSeries();
            reslow = CreateDataSeries();
            mahigh = Indicators.MovingAverage(reshigh, SmoothPeriod, MaTypeSmooth);
            mamidd = Indicators.MovingAverage(resmidd, SmoothPeriod, MaTypeSmooth);
            malow = Indicators.MovingAverage(reslow, SmoothPeriod, MaTypeSmooth);
        }

        public override void Calculate(int index)
        {

            reshigh[index] = Bars.ClosePrices.Maximum(PeriodDonchian);
            reslow[index] = Bars.ClosePrices.Minimum(PeriodDonchian);
            resmidd[index] = (reshigh[index] - reslow[index]) / 2 + reslow[index];

            ResultUp[index] = mahigh.Result.Last(0);
            ResultMidd[index] = mamidd.Result.Last(0);
            ResultDown[index] = malow.Result.Last(0);
        }
    }
}

YE
YesOrNot2

Joined on 17.05.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Donchian Smoothing Ma.algo
  • Rating: 5
  • Installs: 168
  • Modified: 29/07/2024 23:32
Comments
Log in to add a comment.
No comments found.