Gann Wave help

Created at 09 Jan 2023, 18:54
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
TA

Taitrader

Joined 19.12.2022

Gann Wave help
09 Jan 2023, 18:54


Hi,

I'm trying to code Gann Wave indicator however It does not work, here is the code:

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


namespace cAlgo
{

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class GannWave : Indicator
    {
        enum Direction { up, down }
        private Direction direction = Direction.up;


        public override void Calculate(int index)
        {
            int i = 0;
            int motherCount = 1;
            int countBars = Bars.Count - 1;

            int motherIdx = index - countBars + i - motherCount;
            var motherHigh = Bars.HighPrices[motherIdx];
            var motherLow = Bars.LowPrices[motherIdx];
            
            int childIdx = index - countBars + i;
            var high = Bars.HighPrices[childIdx];
            var low = Bars.LowPrices[childIdx];
            

            int pointIdx = index - countBars - 1;
            double pointPrice = Bars.OpenPrices[pointIdx];

            while (i < countBars)
            {
                if (direction == Direction.up)
                {

                    //outside bar break the point
                    if (high > motherHigh && low < pointPrice) 
                    {
                        DrawWave(pointIdx, pointPrice, childIdx, high);
                        pointIdx = childIdx;
                        pointPrice = low;
                        motherCount = 1;
                        i++;
                    }

                    //inside bar
                    else if (low > motherLow && high < motherHigh)
                    {
                        motherCount++;
                        i++;
                    }

                    //reverse
                    else if (high < motherHigh && low < motherLow)
                    {
                        DrawWave(pointIdx, pointPrice, motherIdx, motherHigh);
                        pointIdx = motherIdx;
                        pointPrice = motherHigh;
                        direction = Direction.down;
                        motherCount = 1;
                        i++;

                    }
                    else i++;
                }


                if (direction == Direction.down)
                {
                    
                    //outside bar break the point
                    if (high > pointPrice && low < motherLow)
                    {
                        DrawWave(pointIdx, pointPrice, childIdx, low);
                        pointIdx = childIdx;
                        pointPrice = high;
                        motherCount = 1;
                        i++;
                    }

                    //inside bar
                    else if (low > motherLow && high < motherHigh)
                    {
                        motherCount++;
                        i++;
                    }

                    //reverse
                    else if (low > motherLow && high > motherHigh)
                    {
                        DrawWave(pointIdx, pointPrice, motherIdx, motherHigh);
                        pointIdx = motherIdx;
                        pointPrice = motherHigh;                        
                        direction = Direction.up;
                        motherCount = 1;
                        i++;
                    }
                    else i++;
                }
            }
        }

        // Draws a line
        void DrawWave(int motherIndex, double motherPrice, int index, double price)
        {
           ChartObjects.DrawLine("GannWave", motherIndex, motherPrice, index, price, Colors.White);
           
        }
    }
}


@Taitrader
Replies

firemyst
25 Jan 2023, 06:11

How doesn't it work? What's the problem?


@firemyst