Gann Wave help
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);
}
}
}
firemyst
25 Jan 2023, 06:11
How doesn't it work? What's the problem?
@firemyst