Category Trend  Published on 09/11/2022

KF_Mtf_SslChannels_v2

Description

Gives you the ability to add up to 4 SSL channels of any timeframe onto the current chart

Makes life easier - Enjoy!!!

 


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

namespace cAlgo
{
    [Cloud("S1_T", "S1_B")]
    [Cloud("S2_T", "S2_B")]
    [Cloud("S3_T", "S3_B")]
    [Cloud("S4_T", "S4_B")]
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class KF_Mtf_SslChannels_v2 : Indicator
    {
        [Parameter("S1_Enabled", DefaultValue = true, Group = "SSL_1")]
        public bool S1_Enabled { get; set; }

        [Parameter("S1_Period", DefaultValue = 10, Group = "SSL_1")]
        public int S1_Period { get; set; }

        [Parameter("S1_MaType", DefaultValue = MovingAverageType.Simple, Group = "SSL_1")]
        public MovingAverageType S1_MaType { get; set; }

        [Parameter("S1_TimeFrame", DefaultValue = "Minute5", Group = "SSL_1")]
        public TimeFrame S1_TimeFrame { get; set; }



        [Parameter("S2_Enabled", DefaultValue = true, Group = "SSL_2")]
        public bool S2_Enabled { get; set; }

        [Parameter("S2_Period", DefaultValue = 26, Group = "SSL_2")]
        public int S2_Period { get; set; }

        [Parameter("S2_MaType", DefaultValue = MovingAverageType.WilderSmoothing, Group = "SSL_2")]
        public MovingAverageType S2_MaType { get; set; }

        [Parameter("S2_TimeFrame", DefaultValue = "Hour4", Group = "SSL_2")]
        public TimeFrame S2_TimeFrame { get; set; }




        [Parameter("S3_Enabled", DefaultValue = true, Group = "SSL_3")]
        public bool S3_Enabled { get; set; }

        [Parameter("S3_Period", DefaultValue = 7, Group = "SSL_3")]
        public int S3_Period { get; set; }

        [Parameter("S3_MaType", DefaultValue = MovingAverageType.WilderSmoothing, Group = "SSL_3")]
        public MovingAverageType S3_MaType { get; set; }

        [Parameter("S3_TimeFrame", DefaultValue = "Daily", Group = "SSL_3")]
        public TimeFrame S3_TimeFrame { get; set; }



        [Parameter("S4_Enabled", DefaultValue = true, Group = "SSL_4")]
        public bool S4_Enabled { get; set; }

        [Parameter("S4_Period", DefaultValue = 3, Group = "SSL_4")]
        public int S4_Period { get; set; }

        [Parameter("S4_MaType", DefaultValue = MovingAverageType.WilderSmoothing, Group = "SSL_4")]
        public MovingAverageType S4_MaType { get; set; }

        [Parameter("S4_TimeFrame", DefaultValue = "Day3", Group = "SSL_4")]
        public TimeFrame S4_TimeFrame { get; set; }



        [Output("S1_T", LineColor = "Red")]
        public IndicatorDataSeries S1_T { get; set; }

        [Output("S1_B", LineColor = "Lime")]
        public IndicatorDataSeries S1_B { get; set; }



        [Output("S2_T", LineColor = "Yellow")]
        public IndicatorDataSeries S2_T { get; set; }

        [Output("S2_B", LineColor = "Blue")]
        public IndicatorDataSeries S2_B { get; set; }



        [Output("S3_T", LineColor = "Magenta")]
        public IndicatorDataSeries S3_T { get; set; }

        [Output("S3_B", LineColor = "Aqua")]
        public IndicatorDataSeries S3_B { get; set; }



        [Output("S4_T", LineColor = "Cyan")]
        public IndicatorDataSeries S4_T { get; set; }

        [Output("S4_B", LineColor = "Teal")]
        public IndicatorDataSeries S4_B { get; set; }


        private MovingAverage _s1_H, _s1_L, _s2_H, _s2_L, _s3_H, _s3_L, _s4_H, _s4_L;

        private IndicatorDataSeries _s1_hlv, _s2_hlv, _s3_hlv, _s4_hlv;

        private Bars _s1, _s2, _s3, _s4;


        protected override void Initialize()
        {
            if (S1_Enabled)
            {
                _s1 = MarketData.GetBars(S1_TimeFrame);

                while (_s1.OpenTimes[0] > Bars.OpenTimes[0])
                    _s1.LoadMoreHistory();

                _s1_H = Indicators.MovingAverage(_s1.HighPrices, S1_Period, S1_MaType);
                _s1_L = Indicators.MovingAverage(_s1.LowPrices, S1_Period, S1_MaType);
                _s1_hlv = CreateDataSeries();
            }

            if (S2_Enabled)
            {
                _s2 = MarketData.GetBars(S2_TimeFrame);

                while (_s2.OpenTimes[0] > Bars.OpenTimes[0])
                    _s2.LoadMoreHistory();

                _s2_H = Indicators.MovingAverage(_s2.HighPrices, S2_Period, S2_MaType);
                _s2_L = Indicators.MovingAverage(_s2.LowPrices, S2_Period, S2_MaType);
                _s2_hlv = CreateDataSeries();
            }

            if (S3_Enabled)
            {
                _s3 = MarketData.GetBars(S3_TimeFrame);

                while (_s3.OpenTimes[0] > Bars.OpenTimes[0])
                    _s3.LoadMoreHistory();

                _s3_H = Indicators.MovingAverage(_s3.HighPrices, S3_Period, S3_MaType);
                _s3_L = Indicators.MovingAverage(_s3.LowPrices, S3_Period, S3_MaType);
                _s3_hlv = CreateDataSeries();
            }

            if (S4_Enabled)
            {
                _s4 = MarketData.GetBars(S4_TimeFrame);

                while (_s4.OpenTimes[0] > Bars.OpenTimes[0])
                    _s4.LoadMoreHistory();

                _s4_H = Indicators.MovingAverage(_s4.HighPrices, S4_Period, S4_MaType);
                _s4_L = Indicators.MovingAverage(_s4.LowPrices, S4_Period, S4_MaType);
                _s4_hlv = CreateDataSeries();
            }
        }

        public override void Calculate(int index)
        {
            if (S1_Enabled)
            {
                var index1 = _s1.TimeFrame == Chart.TimeFrame ? index : _s1.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                if (index1 < 0)
                {
                    return;
                }


                _s1_H.Calculate(index1);
                _s1_L.Calculate(index1);

                _s1_hlv[index] = _s1.ClosePrices[index1] > _s1_H.Result[index1] ? 1 : _s1.ClosePrices[index1] < _s1_L.Result[index1] ? -1 : _s1_hlv[index - 1];

                S1_T[index] = _s1_hlv[index] < 0 ? _s1_H.Result[index1] : _s1_L.Result[index1];
                S1_B[index] = _s1_hlv[index] < 0 ? _s1_L.Result[index1] : _s1_H.Result[index1];


                var tmp1 = _s1.TimeFrame == Chart.TimeFrame ? index - 1 : _s1.OpenTimes.GetIndexByTime(Bars.OpenTimes[index - 1]);

                int lastIdx1 = Bars.OpenTimes.GetIndexByTime(_s1.OpenTimes[index1]);
                int lastIdx2 = Bars.OpenTimes.GetIndexByTime(_s1.OpenTimes[tmp1]);
                if (lastIdx1 == lastIdx2 && _s1.TimeFrame != Chart.TimeFrame)
                {
                    S1_T[index - 1] = double.NaN;
                    S1_B[index - 1] = double.NaN;
                }
            }


            if (S2_Enabled)
            {
                var index2 = _s2.TimeFrame == Chart.TimeFrame ? index : _s2.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                if (index2 < 0)
                {
                    return;
                }


                _s2_H.Calculate(index2);
                _s2_L.Calculate(index2);

                _s2_hlv[index] = _s2.ClosePrices[index2] > _s2_H.Result[index2] ? 1 : _s2.ClosePrices[index2] < _s2_L.Result[index2] ? -1 : _s2_hlv[index - 1];

                S2_T[index] = _s2_hlv[index] < 0 ? _s2_H.Result[index2] : _s2_L.Result[index2];
                S2_B[index] = _s2_hlv[index] < 0 ? _s2_L.Result[index2] : _s2_H.Result[index2];


                var tmp2 = _s2.TimeFrame == Chart.TimeFrame ? index - 1 : _s2.OpenTimes.GetIndexByTime(Bars.OpenTimes[index - 1]);

                int lastIdx1 = Bars.OpenTimes.GetIndexByTime(_s2.OpenTimes[index2]);
                int lastIdx2 = Bars.OpenTimes.GetIndexByTime(_s2.OpenTimes[tmp2]);
                if (lastIdx1 == lastIdx2 && _s2.TimeFrame != Chart.TimeFrame)
                {
                    S2_T[index - 1] = double.NaN;
                    S2_B[index - 1] = double.NaN;
                }
            }


            if (S3_Enabled)
            {
                var index3 = _s3.TimeFrame == Chart.TimeFrame ? index : _s3.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                if (index3 < 0)
                {
                    return;
                }


                _s3_H.Calculate(index3);
                _s3_L.Calculate(index3);

                _s3_hlv[index] = _s3.ClosePrices[index3] > _s3_H.Result[index3] ? 1 : _s3.ClosePrices[index3] < _s3_L.Result[index3] ? -1 : _s3_hlv[index - 1];

                S3_T[index] = _s3_hlv[index] < 0 ? _s3_H.Result[index3] : _s3_L.Result[index3];
                S3_B[index] = _s3_hlv[index] < 0 ? _s3_L.Result[index3] : _s3_H.Result[index3];


                var tmp3 = _s3.TimeFrame == Chart.TimeFrame ? index - 1 : _s3.OpenTimes.GetIndexByTime(Bars.OpenTimes[index - 1]);

                int lastIdx1 = Bars.OpenTimes.GetIndexByTime(_s3.OpenTimes[index3]);
                int lastIdx2 = Bars.OpenTimes.GetIndexByTime(_s3.OpenTimes[tmp3]);
                if (lastIdx1 == lastIdx2 && _s3.TimeFrame != Chart.TimeFrame)
                {
                    S3_T[index - 1] = double.NaN;
                    S3_B[index - 1] = double.NaN;
                }
            }


            if (S4_Enabled)
            {
                var index4 = _s4.TimeFrame == Chart.TimeFrame ? index : _s4.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                if (index4 < 0)
                {
                    return;
                }


                _s4_H.Calculate(index4);
                _s4_L.Calculate(index4);

                _s4_hlv[index] = _s4.ClosePrices[index4] > _s4_H.Result[index4] ? 1 : _s4.ClosePrices[index4] < _s4_L.Result[index4] ? -1 : _s4_hlv[index - 1];

                S4_T[index] = _s4_hlv[index] < 0 ? _s4_H.Result[index4] : _s4_L.Result[index4];
                S4_B[index] = _s4_hlv[index] < 0 ? _s4_L.Result[index4] : _s4_H.Result[index4];


                var tmp4 = _s4.TimeFrame == Chart.TimeFrame ? index - 1 : _s4.OpenTimes.GetIndexByTime(Bars.OpenTimes[index - 1]);

                int lastIdx1 = Bars.OpenTimes.GetIndexByTime(_s4.OpenTimes[index4]);
                int lastIdx2 = Bars.OpenTimes.GetIndexByTime(_s4.OpenTimes[tmp4]);
                if (lastIdx1 == lastIdx2 && _s4.TimeFrame != Chart.TimeFrame)
                {
                    S4_T[index - 1] = double.NaN;
                    S4_B[index - 1] = double.NaN;
                }
            }

        }
    }
}


GM
gmkenneyy

Joined on 20.03.2020 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: KF_Mtf_SslChannels_v2.algo
  • Rating: 0
  • Installs: 867
  • Modified: 09/11/2022 00:03
Comments
Log in to add a comment.
asc444555@gmail.com's avatar
asc444555@gmail.com · 2 years ago

CÖTSE HUSSELEY APF DERA LANCELOT VETCHE NACH BIE EREZIS ASPTSCH NEUTHRALE