Custom Fractal feeding bot no value

icollocollo since: 26 Nov 2021;

  13 May 2022, 16:19
Custom Fractal feeding bot no value

This is my fractals indicator gets 4hr values

I am trying to get .last (1) and last (0) using the for loop below

Values needed is UpFractal 1 and 2

                            DownFractal 1 and 2

i have tried it prints last values but then repeats them. need to get last values at a particular time.

for (int i = i_fractal.UpFractal.Count; i > i_fractal.UpFractal.Count - 5; i--)
            {

                for (int j = i_fractal.DownFractal.Count; j > i_fractal.DownFractal.Count - 5; j--)
                {
                    if (i_fractal.DownFractal.Last(0) < i_fractal.DownFractal.Last(1) && FSeries.ClosePrices.Last(0) > i_fractal.DownFractal.Last(1) && FSeries.LowPrices.Last(0) < i_fractal.DownFractal.Last(1))
                    {
                        if (i_fractal.UpFractal.Last(0) < i_fractal.UpFractal.Last(1))
                        {
                            if (OneBearish)
                            {

                                Hdown = true;

                                break;
                            }
                        }

                    }

                }
            }

The indicator code is below

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None, TimeZone = TimeZones.EAfricaStandardTime)]
    public class Spring : Indicator
    {


        [Output("Up Fractal", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries UpFractal { get; set; }

        [Output("Down Fractal", Color = Colors.Blue, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries DownFractal { get; set; }


        private Bars HSeries;
        protected override void Initialize()
        {
            HSeries = MarketData.GetBars(TimeFrame.Hour4);
        }



        public override void Calculate(int index)
        {
            if (index == 1)
                return;

            DrawUpFractal(index);
            DrawDownFractal(index);



        }

        private void DrawUpFractal(int index)
        {

            int middleIndex = index - 2;
            double middleValue = HSeries.ClosePrices[middleIndex];

            bool up = false;

            for (int i = 1; i < HSeries.ClosePrices.Count - 1; i++)
            {
                if (HSeries.ClosePrices[middleIndex] > HSeries.ClosePrices[middleIndex - 1] && HSeries.ClosePrices[middleIndex] > HSeries.ClosePrices[middleIndex + 1])
                {
                    up = true;
                    break;
                }
            }
            if (up)
                UpFractal[middleIndex] = middleValue;
        }

        private void DrawDownFractal(int index)
        {

            int middleIndex = index - 2;
            double middleValue = HSeries.ClosePrices[middleIndex];
            bool down = false;

            for (int i = 1; i < HSeries.ClosePrices.Count - 1; i++)
            {
                if (HSeries.ClosePrices[middleIndex] < HSeries.ClosePrices[middleIndex - 1] && HSeries.ClosePrices[middleIndex] < HSeries.ClosePrices[middleIndex + 1])
                {
                    down = true;
                    break;
                }
            }
            if (down)
                DownFractal[middleIndex] = middleValue;

        }



    }
}
amusleh's avatar

amusleh since: 01 Mar 2021;

  13 May 2022, 10:21

Hi,

We can only help you if you post a code sample that can reproduce this issue.

Please post the code for your cBot and the custom indicator you are using.

Community Developer | Spotware | Telegram: @algodeveloper

icollocollo since: 26 Nov 2021;

  13 May 2022, 16:16
RE:

amusleh said:

Hi,

We can only help you if you post a code sample that can reproduce this issue.

Please post the code for your cBot and the custom indicator you are using.

Updated Please check, really need these values. 

amusleh's avatar

amusleh since: 01 Mar 2021;

  16 May 2022, 09:36

Hi,

The index is the current chart bars index, not the index of time frame that you loaded.

You have to change the index to the loaded time frame bars index first then use it, try this:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None, TimeZone = TimeZones.EAfricaStandardTime)]
    public class Spring : Indicator
    {
        [Output("Up Fractal", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries UpFractal { get; set; }

        [Output("Down Fractal", Color = Colors.Blue, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries DownFractal { get; set; }

        private Bars HSeries;

        protected override void Initialize()
        {
            HSeries = MarketData.GetBars(TimeFrame.Hour4);
        }

        public override void Calculate(int index)
        {
            if (index == 1)
                return;

            DrawUpFractal(index);
            DrawDownFractal(index);
        }

        private void DrawUpFractal(int index)
        {
            var hSeriesIndex = HSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

            int middleIndex = hSeriesIndex - 2;
            double middleValue = HSeries.ClosePrices[middleIndex];

            bool up = false;

            for (int i = 1; i < HSeries.ClosePrices.Count - 1; i++)
            {
                if (HSeries.ClosePrices[middleIndex] > HSeries.ClosePrices[middleIndex - 1] && HSeries.ClosePrices[middleIndex] > HSeries.ClosePrices[middleIndex + 1])
                {
                    up = true;
                    break;
                }
            }

            if (up)
                UpFractal[index] = middleValue;
        }

        private void DrawDownFractal(int index)
        {
            var hSeriesIndex = HSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

            int middleIndex = hSeriesIndex - 2;
            double middleValue = HSeries.ClosePrices[middleIndex];
            bool down = false;

            for (int i = 1; i < HSeries.ClosePrices.Count - 1; i++)
            {
                if (HSeries.ClosePrices[middleIndex] < HSeries.ClosePrices[middleIndex - 1] && HSeries.ClosePrices[middleIndex] < HSeries.ClosePrices[middleIndex + 1])
                {
                    down = true;
                    break;
                }
            }
            if (down)
                DownFractal[index] = middleValue;
        }
    }
}
Community Developer | Spotware | Telegram: @algodeveloper