Andrew's Pitchfork from Zigzag indicator free

by iForex2015 in category Trend at 22/02/2022
Description

This indicator is an integration of two other indicators, viz Zigzag developed by Jiri and Andrew's Pitchfork indicators.

Andrew's Pitchfork

 


using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AutoRescale = true, AccessRights = AccessRights.None)]
    public class AndrewsPitchforkZigZag : Indicator
    {

        #region Properties
        [Parameter()]
        public DataSeries High { get; set; }

        [Parameter()]
        public DataSeries Low { get; set; }

        [Parameter("Period", DefaultValue = 16, MinValue = 1)]
        public int Period { get; set; }

        [Output("ZigZagSeries", Color = Colors.Green, Thickness = 1, PlotType = PlotType.Line)]
        public IndicatorDataSeries ZigZagSeries { get; set; }

        [Parameter("Show Andrews Pitch Fork", DefaultValue = true)]
        public bool ShowAndrewsPitchFork { get; set; }

        #endregion

        #region Variables
        private double currentZigZagHigh = 0;
        private double currentZigZagLow = 0;
        private int lastSwingIndex = -1;
        private double lastSwingPrice = 0.0;
        private int trendDir = 0;
        private int CurrentBar = 0;
        #endregion

        protected override void Initialize()
        {

        }

        public override void Calculate(int index)
        {
            CurrentBar = High.Count;

            if (CurrentBar < 2)
                return;

            if (lastSwingPrice == 0.0)
                lastSwingPrice = Low[index] + (High[index] - Low[index]) / 2;

            bool isSwingHigh = High[index] == Functions.Maximum(High, Period);
            bool isSwingLow = Low[index] == Functions.Minimum(Low, Period);
            double saveValue = 0.0;
            bool addHigh = false;
            bool addLow = false;
            bool updateHigh = false;
            bool updateLow = false;

            if (trendDir == 1 && isSwingHigh && High[index] >= lastSwingPrice)
            {
                saveValue = High[index];
                updateHigh = true;
            }
            else if (trendDir == -1 && isSwingLow && Low[index] <= lastSwingPrice)
            {
                saveValue = Low[index];
                updateLow = true;
            }
            else if (trendDir <= 0 && isSwingHigh)
            {
                saveValue = High[index];
                addHigh = true;
                trendDir = 1;
            }
            else if (trendDir >= 0 && isSwingLow)
            {
                saveValue = Low[index];
                addLow = true;
                trendDir = -1;
            }

            if (addHigh || addLow || updateHigh || updateLow)
            {
                if (updateHigh && lastSwingIndex >= 0)
                {
                    ZigZagSeries[lastSwingIndex] = double.NaN;
                }
                else if (updateLow && lastSwingIndex >= 0)
                {
                    ZigZagSeries[lastSwingIndex] = double.NaN;
                }

                if (addHigh || updateHigh)
                {
                    currentZigZagHigh = saveValue;
                    ZigZagSeries[index] = currentZigZagHigh;
                }
                else if (addLow || updateLow)
                {
                    currentZigZagLow = saveValue;
                    ZigZagSeries[index] = currentZigZagLow;
                }

                lastSwingIndex = CurrentBar - 1;
                lastSwingPrice = saveValue;
            }

            if (ShowAndrewsPitchFork)
                DrawAndrewsPitchFork(index);

        }

        public void DrawAndrewsPitchFork(int index)
        {
            int barIndex1 = 0;
            int barIndex2 = 0;
            int barIndex3 = 0;
            int barIndex4 = 0;

            for (int i = index; i >= 0; i--)
            {
                if (ZigZagSeries[i] > 0)
                {
                    if (barIndex4 == 0)
                    {
                        barIndex4 = i;
                    }
                    else if (barIndex3 == 0)
                    {
                        barIndex3 = i;
                    }
                    else if (barIndex2 == 0)
                    {
                        barIndex2 = i;
                    }
                    else if (barIndex1 == 0)
                    {
                        barIndex1 = i;
                        break;
                    }
                }
            }

            var y1 = ZigZagSeries[barIndex1];
            var y2 = ZigZagSeries[barIndex2];
            var y3 = ZigZagSeries[barIndex3];

            var andrewsPitchfork = Chart.DrawAndrewsPitchfork("AndrewsPitchFork", barIndex1, y1, barIndex2, y2, barIndex3, y3, Color.Red);
            andrewsPitchfork.IsInteractive = true;
        }
    }
}

 

 

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader

using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AutoRescale = true, AccessRights = AccessRights.None)]
    public class AndrewsPitchforkZigZag : Indicator
    {

        #region Properties
        [Parameter()]
        public DataSeries High { get; set; }

        [Parameter()]
        public DataSeries Low { get; set; }

        [Parameter("Period", DefaultValue = 16, MinValue = 1)]
        public int Period { get; set; }

        [Output("ZigZagSeries", Color = Colors.Green, Thickness = 1, PlotType = PlotType.Line)]
        public IndicatorDataSeries ZigZagSeries { get; set; }

        [Parameter("Show Andrews Pitch Fork", DefaultValue = true)]
        public bool ShowAndrewsPitchFork { get; set; }

        #endregion

        #region Variables
        private double currentZigZagHigh = 0;
        private double currentZigZagLow = 0;
        private int lastSwingIndex = -1;
        private double lastSwingPrice = 0.0;
        private int trendDir = 0;
        private int CurrentBar = 0;
        #endregion

        protected override void Initialize()
        {

        }

        public override void Calculate(int index)
        {
            CurrentBar = High.Count;

            if (CurrentBar < 2)
                return;

            if (lastSwingPrice == 0.0)
                lastSwingPrice = Low[index] + (High[index] - Low[index]) / 2;

            bool isSwingHigh = High[index] == Functions.Maximum(High, Period);
            bool isSwingLow = Low[index] == Functions.Minimum(Low, Period);
            double saveValue = 0.0;
            bool addHigh = false;
            bool addLow = false;
            bool updateHigh = false;
            bool updateLow = false;

            if (trendDir == 1 && isSwingHigh && High[index] >= lastSwingPrice)
            {
                saveValue = High[index];
                updateHigh = true;
            }
            else if (trendDir == -1 && isSwingLow && Low[index] <= lastSwingPrice)
            {
                saveValue = Low[index];
                updateLow = true;
            }
            else if (trendDir <= 0 && isSwingHigh)
            {
                saveValue = High[index];
                addHigh = true;
                trendDir = 1;
            }
            else if (trendDir >= 0 && isSwingLow)
            {
                saveValue = Low[index];
                addLow = true;
                trendDir = -1;
            }

            if (addHigh || addLow || updateHigh || updateLow)
            {
                if (updateHigh && lastSwingIndex >= 0)
                {
                    ZigZagSeries[lastSwingIndex] = double.NaN;
                }
                else if (updateLow && lastSwingIndex >= 0)
                {
                    ZigZagSeries[lastSwingIndex] = double.NaN;
                }

                if (addHigh || updateHigh)
                {
                    currentZigZagHigh = saveValue;
                    ZigZagSeries[index] = currentZigZagHigh;
                }
                else if (addLow || updateLow)
                {
                    currentZigZagLow = saveValue;
                    ZigZagSeries[index] = currentZigZagLow;
                }

                lastSwingIndex = CurrentBar - 1;
                lastSwingPrice = saveValue;
            }

            if (ShowAndrewsPitchFork)
                DrawAndrewsPitchFork(index);

        }

        public void DrawAndrewsPitchFork(int index)
        {
            int barIndex1 = 0;
            int barIndex2 = 0;
            int barIndex3 = 0;
            int barIndex4 = 0;

            for (int i = index; i >= 0; i--)
            {
                if (ZigZagSeries[i] > 0)
                {
                    if (barIndex4 == 0)
                    {
                        barIndex4 = i;
                    }
                    else if (barIndex3 == 0)
                    {
                        barIndex3 = i;
                    }
                    else if (barIndex2 == 0)
                    {
                        barIndex2 = i;
                    }
                    else if (barIndex1 == 0)
                    {
                        barIndex1 = i;
                        break;
                    }
                }
            }

            var y1 = ZigZagSeries[barIndex1];
            var y2 = ZigZagSeries[barIndex2];
            var y3 = ZigZagSeries[barIndex3];

            var andrewsPitchfork = Chart.DrawAndrewsPitchfork("AndrewsPitchFork", barIndex1, y1, barIndex2, y2, barIndex3, y3, Color.Red);
            andrewsPitchfork.IsInteractive = true;
        }
    }
}
Comments

jackjohnsonpo - March 04, 2022 @ 08:36

 Thank you for bringing new knowledge to everyone, it is very helpful paper io 2

monicaphillpa1122 - March 09, 2022 @ 11:10

This Andrew's Pitchfork from Zigzag indicator, which is so reflective and desirable for all the new individuals but there are also very beneficial and fantastic guest post backlinks, from them so easily all over the US.

ameliafishal37 - March 12, 2022 @ 13:02

Thank you for sharing this kind of post it is very beneficial for students who are learned algos and indicators in the program which platform is very good for their growth and many different opportunities they can make. As you all know resume editor service is much needed nowadays for students which are wanting to get a job but lacking due to the low-quality resumes which are not effective in the future.

almaza24map - March 24, 2022 @ 08:25

Nice information, I love this. Provides special education attorney services in San Leandro

nelsonmurdockk - April 06, 2022 @ 08:16

Thank you for providing this type of material; it is really valuable for students who have learned algorithms and indicators in the programme, and it is a platform that is very good for their progress and many other chances. However, they also provide really useful and amazing Management assignment help to students all around the UK.

incremental1990finnish - April 07, 2022 @ 15:53

This is really informative!

thomasmarsden970 - July 22, 2022 @ 15:14

A technical indicator that uses three parallel trendlines to identify possible levels of support and resistance but Usually the international students look no further and opt for help with dissertation for complete assistance at any stage of dissertation.
 

junealexis001 - September 12, 2022 @ 12:13

Awesome  site i love it keep posting more!   storage sheds grand junction

snz103513 - October 01, 2022 @ 08:09

Avec le marché submergé de dépossessions et de transactions à court terme, il y a tellement de détails complexes légaux que vous voulez vraiment être au courant pour acheter ou vendre une maison. Les bureaux connaissent les réglementations et ville de genève les systèmes légaux du marché de votre quartier.

snz103513 - October 01, 2022 @ 08:10

This intends that on the off chance that we're not living in the right area, regardless of whether we're getting a ton of sun, it actually may not be sufficient. Those in southern environments charge better, with best outcomes got close to the equator. Any of start iv therapy business us occupying focuses north might have to think about an enhancement.

miarose7878 - October 21, 2022 @ 14:38

Hello there, I am a college student from the United Kingdom. I have sat to write write my college assignment but having some difficulties writing it down, so I need authentic assignment writing help from a senior student. Kindly help!

snz103513 - November 29, 2022 @ 17:30

Michelle Adams is somebody who has investigated many types of canines, including the Beagle. Since rearing brings specific senses and ways of behaving into play with various kinds of canines understanding the historical backdrop of Beagles for sale your better outfit you to work with your new pet. There is a lot of Beagle data the field will assist you with understanding where your Beagle came from and why he acts the manner in which he does.

0