Category Trend  Published on 05/09/2024

Swing Hi Lo

Description

Higher High, Higher Low, Lower High, Lower Low..

Finally update it.. =)

Telegram group : https://t.me/cTraderStrategyTesterProject

GitHub : https://github.com/YesOrNotCtrader/Ctrader-Stragegy-Tester-Project

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 SwingHilov11 : Indicator
    {
        [Parameter(DefaultValue = 8)]
        public int PeriodFractale { get; set; }

        [Output("Higher High ", PlotType = PlotType.Points, LineColor = "Lime", Thickness = 2)]
        public IndicatorDataSeries HH { get; set; }
        [Output("Higher Low", PlotType = PlotType.Points, LineColor = "Orange", Thickness = 2)]
        public IndicatorDataSeries HL { get; set; }
        [Output("Lower High", PlotType = PlotType.Points, LineColor = "DeepSkyBlue", Thickness = 2)]
        public IndicatorDataSeries LH { get; set; }
        [Output("Lower Low", PlotType = PlotType.Points, LineColor = "Red", Thickness = 2)]
        public IndicatorDataSeries LL { get; set; }


        private Fractals fra5;
        private int upint, downint;
        private int newindex;
        private IndicatorDataSeries up, down, up2, down2;

        protected override void Initialize()
        {
            fra5 = Indicators.Fractals(PeriodFractale);
            up = CreateDataSeries();
            down = CreateDataSeries();
            up2 = CreateDataSeries();
            down2 = CreateDataSeries();

        }

        public override void Calculate(int index)
        {

            if (index > newindex)
            {
                up[index] = fra5.UpFractal.Last(0);
                down[index] = fra5.DownFractal.Last(0);

                up[index] = double.IsNaN(up[index]) ? up[index - 1] : up[index];
                down[index] = double.IsNaN(down[index]) ? down[index - 1] : down[index];

                var customindex = index - (int)(PeriodFractale / 2);


                up2[customindex] = up2[index];
                down2[customindex] = down2[index];

                if (up[index] > up[index - 1])
                {
                    HH[customindex] = up[index];
                    HL[customindex] = double.NaN;
                }
                if (up[index] < up[index - 1])
                {
                    HL[customindex] = up[index];
                    HH[customindex] = double.NaN;
                }
                if (down[index] < down[index - 1])
                {
                    LL[customindex] = down[index];
                    LH[customindex] = double.NaN;
                }
                if (down[index] > down[index - 1])
                {
                    LH[customindex] = down[index];
                    LL[customindex] = double.NaN;
                }

                HL[customindex] = double.IsNaN(HL[customindex]) && double.IsNaN(HH[customindex]) ? HL[customindex - 1] : HL[customindex];
                HH[customindex] = double.IsNaN(HH[customindex]) && double.IsNaN(HL[customindex]) ? HH[customindex - 1] : HH[customindex];
                LL[customindex] = double.IsNaN(LL[customindex]) && double.IsNaN(LH[customindex]) ? LL[customindex - 1] : LL[customindex];
                LH[customindex] = double.IsNaN(LH[customindex]) && double.IsNaN(LL[customindex]) ? LH[customindex - 1] : LH[customindex];

                for (int i = 1; i < index - customindex; i++)
                {
                    HL[customindex + i] = HL[customindex];
                    HH[customindex + i] = HH[customindex];
                    LL[customindex + i] = LL[customindex];
                    LH[customindex + i] = LH[customindex];
                }

                newindex = index;
                CreateLabel(customindex);

            }
        }
        private void CreateLabel(int customindex)
        {


            if ((!double.IsNaN(HH[customindex]) && double.IsNaN(HH[customindex - 1])) || (!double.IsNaN(HH[customindex]) && !double.IsNaN(HH[customindex - 1]) && HH[customindex - 1] != HH[customindex]))
            {
                var textHH = Chart.DrawText("HH" + customindex, "HH", customindex, HH[customindex], Color.Lime);
                textHH.VerticalAlignment = VerticalAlignment.Top;
                textHH.HorizontalAlignment = HorizontalAlignment.Center;
            }
            else if ((!double.IsNaN(HL[customindex]) && double.IsNaN(HL[customindex - 1])) || (!double.IsNaN(HL[customindex]) && !double.IsNaN(HL[customindex - 1]) && HL[customindex - 1] != HL[customindex]))
            {
                var textHL = Chart.DrawText("HL" + customindex, "HL", customindex, HL[customindex], Color.Orange);
                textHL.VerticalAlignment = VerticalAlignment.Top;
                textHL.HorizontalAlignment = HorizontalAlignment.Center;
            }
            else if ((!double.IsNaN(LL[customindex]) && double.IsNaN(LL[customindex - 1])) || (!double.IsNaN(LL[customindex]) && !double.IsNaN(LL[customindex - 1]) && LL[customindex - 1] != LL[customindex]))
            {
                var textLL = Chart.DrawText("LL" + customindex, "LL", customindex, LL[customindex], Color.Red);
                textLL.VerticalAlignment = VerticalAlignment.Bottom;
                textLL.HorizontalAlignment = HorizontalAlignment.Center;
            }
            else if ((!double.IsNaN(LH[customindex]) && double.IsNaN(LH[customindex - 1])) || (!double.IsNaN(LH[customindex]) && !double.IsNaN(LH[customindex - 1]) && LH[customindex - 1] != LH[customindex]))
            {
                var textLH = Chart.DrawText("LH" + customindex, "LH", customindex, LH[customindex], Color.DeepSkyBlue);
                textLH.VerticalAlignment = VerticalAlignment.Bottom;
                textLH.HorizontalAlignment = HorizontalAlignment.Center;
            }



            //ChartObjects[name].FontSize = 8;
        }
    }
}



YE
YesOrNot2

Joined on 17.05.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Swing Hilo v1.1.algo
  • Rating: 5
  • Installs: 310
  • Modified: 05/09/2024 21:16
Comments
Log in to add a comment.
JI
jim.tollan · 3 weeks ago

oh and forgot to say, of course a great submission as ever!!

JI
jim.tollan · 3 weeks ago

here's what i think the correction should be (starting line 60):

    if (up[index] > up[index - 1])
    {
        HH[customindex] = up[index];
        LH[customindex] = double.NaN;
    }
    if (up[index] < up[index - 1])
    {
        LH[customindex] = up[index];
        HH[customindex] = double.NaN;
    }
    if (down[index] < down[index - 1])
    {
        LL[customindex] = down[index];
        HL[customindex] = double.NaN;
    }
    if (down[index] > down[index - 1])
    {
        HL[customindex] = down[index];
        LL[customindex] = double.NaN;
    }
JI
jim.tollan · 3 weeks ago

Hi there.. there is still a small issue. the HL and LH labels are the wrong way round. i.e. the LH is indicating the HL data point and the HL is indicating the LH data point ;)

YE
YesOrNot2 · 3 weeks ago

Good Version is update..

YE
YesOrNot2 · 3 weeks ago

Pour ceux qui on remarqué que ça bugué en live 

=)

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 SwingHilov11 : Indicator
    {
        [Parameter(DefaultValue = 8)]
        public int PeriodFractale { get; set; }

        [Output("Higher High ", PlotType = PlotType.Points, LineColor = "Lime", Thickness = 2)]
        public IndicatorDataSeries HH { get; set; }
        [Output("Higher Low", PlotType = PlotType.Points, LineColor = "Orange", Thickness = 2)]
        public IndicatorDataSeries HL { get; set; }
        [Output("Lower High", PlotType = PlotType.Points, LineColor = "DeepSkyBlue", Thickness = 2)]
        public IndicatorDataSeries LH { get; set; }
        [Output("Lower Low", PlotType = PlotType.Points, LineColor = "Red", Thickness = 2)]
        public IndicatorDataSeries LL { get; set; }


        private Fractals fra5;
        private int upint, downint;
        private int newindex;
        private IndicatorDataSeries up, down, up2, down2;

        protected override void Initialize()
        {
            fra5 = Indicators.Fractals(PeriodFractale);
            up = CreateDataSeries();
            down = CreateDataSeries();
            up2 = CreateDataSeries();
            down2 = CreateDataSeries();

        }

        public override void Calculate(int index)
        {

            if (index > newindex)
            {
                up[index] = fra5.UpFractal.Last(0);
                down[index] = fra5.DownFractal.Last(0);

                up[index] = double.IsNaN(up[index]) ? up[index - 1] : up[index];
                down[index] = double.IsNaN(down[index]) ? down[index - 1] : down[index];

                var customindex = index - (int)(PeriodFractale / 2);


                up2[customindex] = up2[index];
                down2[customindex] = down2[index];

                if (up[index] > up[index - 1])
                {
                    HH[customindex] = up[index];
                    HL[customindex] = double.NaN;
                }
                if (up[index] < up[index - 1])
                {
                    HL[customindex] = up[index];
                    HH[customindex] = double.NaN;
                }
                if (down[index] < down[index - 1])
                {
                    LL[customindex] = down[index];
                    LH[customindex] = double.NaN;
                }
                if (down[index] > down[index - 1])
                {
                    LH[customindex] = down[index];
                    LL[customindex] = double.NaN;
                }

                HL[customindex] = double.IsNaN(HL[customindex]) && double.IsNaN(HH[customindex]) ? HL[customindex - 1] : HL[customindex];
                HH[customindex] = double.IsNaN(HH[customindex]) && double.IsNaN(HL[customindex]) ? HH[customindex - 1] : HH[customindex];
                LL[customindex] = double.IsNaN(LL[customindex]) && double.IsNaN(LH[customindex]) ? LL[customindex - 1] : LL[customindex];
                LH[customindex] = double.IsNaN(LH[customindex]) && double.IsNaN(LL[customindex]) ? LH[customindex - 1] : LH[customindex];

                newindex = index;
                CreateLabel(customindex);

            }
        }
        private void CreateLabel(int customindex)
        {


            if ((!double.IsNaN(HH[customindex]) && double.IsNaN(HH[customindex - 1])) || (!double.IsNaN(HH[customindex]) && !double.IsNaN(HH[customindex - 1]) && HH[customindex - 1] != HH[customindex]))
            {
                var textHH = Chart.DrawText("HH" + customindex, "HH", customindex, HH[customindex], Color.Lime);
                textHH.VerticalAlignment = VerticalAlignment.Top;
                textHH.HorizontalAlignment = HorizontalAlignment.Center;
            }
            else if ((!double.IsNaN(HL[customindex]) && double.IsNaN(HL[customindex - 1])) || (!double.IsNaN(HL[customindex]) && !double.IsNaN(HL[customindex - 1]) && HL[customindex - 1] != HL[customindex]))
            {
                var textHL = Chart.DrawText("HL" + customindex, "HL", customindex, HL[customindex], Color.Orange);
                textHL.VerticalAlignment = VerticalAlignment.Top;
                textHL.HorizontalAlignment = HorizontalAlignment.Center;
            }
            else if ((!double.IsNaN(LL[customindex]) && double.IsNaN(LL[customindex - 1])) || (!double.IsNaN(LL[customindex]) && !double.IsNaN(LL[customindex - 1]) && LL[customindex - 1] != LL[customindex]))
            {
                var textLL = Chart.DrawText("LL" + customindex, "LL", customindex, LL[customindex], Color.Red);
                textLL.VerticalAlignment = VerticalAlignment.Bottom;
                textLL.HorizontalAlignment = HorizontalAlignment.Center;
            }
            else if ((!double.IsNaN(LH[customindex]) && double.IsNaN(LH[customindex - 1])) || (!double.IsNaN(LH[customindex]) && !double.IsNaN(LH[customindex - 1]) && LH[customindex - 1] != LH[customindex]))
            {
                var textLH = Chart.DrawText("LH" + customindex, "LH", customindex, LH[customindex], Color.DeepSkyBlue);
                textLH.VerticalAlignment = VerticalAlignment.Bottom;
                textLH.HorizontalAlignment = HorizontalAlignment.Center;
            }



            //ChartObjects[name].FontSize = 8;
        }
    }
}