Category Trend  Published on 15/05/2020

Donchian Channels

Description
Caption

Donchian Channels with cloud


// -------------------------------------------------------------------------------
//
//    This is a Template used as a guideline to build your own Robot. 
//    Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API.
//
// -------------------------------------------------------------------------------

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

namespace cAlgo.Indicators
{
    [Cloud("Upper Line", "Lower Line")]
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class DonchianChannels : Indicator
    {
        [Parameter(DefaultValue = 20)]
        public int Periods { get; set; }

        [Parameter(DefaultValue = 1)]
        public int Extremes { get; set; }

        [Parameter(DefaultValue = -1, MinValue = -1)]
        public int Margins { get; set; }

        [Output("Upper Line", Color = Colors.DodgerBlue, PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries UpperSeries { get; set; }

        [Output("Lower Line", Color = Colors.DodgerBlue, PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries LowerSeries { get; set; }

        [Output("Middle Line", Color = Colors.DarkBlue, PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries MiddSeries { get; set; }


        protected override void Initialize()
        {
            // Initialize and create nested indicators

        }

        private double Highest(DataSeries arr, int range, int fromIndex)
        {
            double res;
            int i;
            res = arr[fromIndex];
            for (i = fromIndex; i > fromIndex - range && i >= 0; i--)
            {
                if (res < arr[i])
                    res = arr[i];
            }
            return (res);
        }

        private double Lowest(DataSeries arr, int range, int fromIndex)
        {
            double res;
            int i;
            res = arr[fromIndex];
            for (i = fromIndex; i > fromIndex - range && i >= 0; i--)
            {
                if (res > arr[i])
                    res = arr[i];
            }
            return (res);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...

            double smin = 0, smax = 0, SsMax = 0, SsMin = 0;

            for (int i = index - Periods + 1; i <= index; i++)
            {
                if (Extremes == 1)
                {
                    SsMax = Highest(MarketSeries.High, Periods, i);
                    SsMin = Lowest(MarketSeries.Low, Periods, i);
                }
                else if (Extremes == 3)
                {
                    SsMax = (Highest(MarketSeries.Open, Periods, i) + Highest(MarketSeries.High, Periods, i)) / 2;
                    SsMin = (Lowest(MarketSeries.Open, Periods, i) + Lowest(MarketSeries.Low, Periods, i)) / 2;
                }
                else
                {
                    SsMax = Highest(MarketSeries.Open, Periods, i);
                    SsMin = Lowest(MarketSeries.Open, Periods, i);
                }
                smin = SsMin + (SsMax - SsMin) * Margins / 100;
                smax = SsMax - (SsMax - SsMin) * Margins / 100;
                UpperSeries[i] = smax;
                LowerSeries[i] = smin;
                MiddSeries[i] = (UpperSeries[i] + LowerSeries[i]) / 2.0;

            }

        }

    }
}


HE
heruta07

Joined on 04.05.2020

  • Distribution: Paid
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Donchian Channel (ForexBit).algo
  • Rating: 5
  • Installs: 787
Comments
Log in to add a comment.
No comments found.