DrawPriceMove V4 free

Description

 

V4 is in blue - same as V3 (green) but:

Flips trend direction if the bar is either an inner or outer bar to previous.
Then checks the trend direction using the relationship of the current and previous high prices.

Once again, let us know if there are any bugs.

Find us at: fxtradersystems.com/development/

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 System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DrawPriceMoveV4 : Indicator
    {
        [Output("ZigZag", Thickness = 2, PlotType = PlotType.Line, LineColor = "Lime")]
        public IndicatorDataSeries Value { get; set; }


        enum Direction
        {
            up,
            down
        }

        private Direction direction = Direction.down;
        private double extremumPrice = 0.0;
        private int extremumIndex = 0;

        private void moveExtremum(int index, double price)
        {
            Value[extremumIndex] = Double.NaN;
            setExtremum(index, price);
        }

        private void setExtremum(int index, double price)
        {
            extremumIndex = index;
            extremumPrice = price;
            Value[extremumIndex] = extremumPrice;
        }

        private bool isInside(int index)
        {
            return (Bars.LowPrices[index] >= Bars.LowPrices[index - 1]) && (Bars.HighPrices[index] <= Bars.HighPrices[index - 1]);
        }

        private bool isOutside(int index)
        {
            return (Bars.LowPrices[index] <= Bars.LowPrices[index - 1]) && (Bars.HighPrices[index] >= Bars.HighPrices[index - 1]);
        }

        public override void Calculate(int index)
        {
            double low = Bars.LowPrices[index];
            double high = Bars.HighPrices[index];

            if (extremumPrice == 0.0)
                extremumPrice = high;

            if (Bars.OpenTimes.Count < 2)
                return;

            if (direction == Direction.down)
            {
                if (isInside(index) || isOutside(index))
                {
                    setExtremum(index, high);
                    direction = Direction.up;
                }
                else if (Bars.HighPrices[index] <= Bars.HighPrices[index - 1])
                    moveExtremum(index, low);
                else
                {
                    setExtremum(index, high);
                    direction = Direction.up;
                }
            }
            else
            {
                if (isInside(index) || isOutside(index))
                {
                    setExtremum(index, low);
                    direction = Direction.down;
                }
                else if (Bars.HighPrices[index] >= Bars.HighPrices[index - 1])
                    moveExtremum(index, high);
                else
                {
                    setExtremum(index, low);
                    direction = Direction.down;
                }
            }
        }
    }
}
Comments