I have the code below, which is supposed to find flat Lows:
private void OnBarUpdate()
{
...
if (PrintFlat)
Print("Flat Low = " + FlatLow + " | " + (Math.Abs(Lows[0][0] - Lows[0][1]) <= FlatPriceRange * TickSize) + " | Bar = " + CurrentBar + "\r\n-");
if (!FlatLow && Math.Abs(Lows[0][0] - Lows[0][1]) <= FlatPriceRange * TickSize)
{
FlatLowPrice.Add(Lows[0][1]);
if (!FlatLowBar)
{
flatLowPriceBar = CurrentBar - 1;
FlatLowBar = true;
Draw.ArrowUp(this, "Flat L Start Bar = " + flatLowPriceBar, true, CurrentBar - flatLowPriceBar, FlatLowPrice[w] - TickSize, Brushes.DodgerBlue, true);
}
FlatLow = true;
w++;
}
if (PrintFlat)
Print ("Flat Low Bar = " + FlatLowBar + " | " + (MAX(Lows[0], CurrentBar - flatLowPriceBar)[0] - MIN(Lows[0], CurrentBar - flatLowPriceBar)[0] > FlatPriceRange * TickSize) +
" | Flat Bar =" + flatLowPriceBar + " | F1 - F2 = " + (MAX(Lows[0], CurrentBar - flatLowPriceBar)[0] - MIN(Lows[0], CurrentBar - flatLowPriceBar)[0]).ToString("F4") + " | Bar = " + CurrentBar + "\r\n-");
else if (FlatLowBar && MAX(Lows[0], CurrentBar - flatLowPriceBar)[0] - MIN(Lows[0], CurrentBar - flatLowPriceBar)[0] > FlatPriceRange * TickSize)
{
flatLowPriceEnd = CurrentBar - 1;
FlatLowBar = false;
FlatLow = false;
Draw.ArrowUp(this, "Flat L End Bar = " + flatLowPriceEnd, true, CurrentBar - flatLowPriceEnd, Lows[0][1] - TickSize, Brushes.Gray, true);
}
if (PrintFlat)
Print ("Flat Bar End = " + flatLowPriceEnd + " | Bar = " + CurrentBar + "\r\n-");
Flat Low = False | True | Bar = 21
-
Flat Low Bar = True | False | Flat Bar =20 | F1 - F2 = 0.0000 | Bar = 21
-
Flat Bar End = 0 | Bar = 21
-
Flat Low = True | True | Bar = 22
-
Flat Low Bar = True | False | Flat Bar =20 | F1 - F2 = 0.0100 | Bar = 22
-
Flat Bar End = 0 | Bar = 22
-
Flat Low = True | False | Bar = 23
-
Flat Low Bar = True | True | Flat Bar =20 | F1 - F2 = 0.0800 | Bar = 23
-
Flat Bar End = 0 | Bar = 23
-
Flat Low = True | False | Bar = 24
-
Flat Low Bar = True | True | Flat Bar =20 | F1 - F2 = 0.1900 | Bar = 24
-
Flat Bar End = 0 | Bar = 24
As you can see, on bar 21 it finds a flat Low price, prints the Flat Bar as 20, sets the " FlatLowBar = true; ", it it still Flat on bar 22, but on bar 23 it never sets the end of Flat (flatLowPriceEnd = 23), while FlatLowBar and FlatLow are still True on bar 24, which in turn never resets the logic for the next occurrence.
How is the " else if {} " statement never executed, when both conditions are true?!?
Compare this with the flat High code, basically a mirror code of the Flat Low, but which works as it should:
if (!FlatHigh && Math.Abs(Highs[0][0] - Highs[0][1]) <= FlatPriceRange * TickSize)
{
FlatHighPrice.Add(Highs[0][1]);
if (!FlatHighBar)
{
flatHighPriceBar = CurrentBar - 1;
FlatHighbar = true;
Draw.ArrowDown(this, "Flat H Start Bar = " + flatHighPriceBar, true, CurrentBar - flatHighPriceBar, FlatHighPrice[v] + TickSize, Brushes.Cyan, true);
}
FlatHigh = true;
v++;
}
else if (FlatHighbar && (MAX(Highs[0], CurrentBar - flatHighPriceBar)[0] - MIN(Highs[0], CurrentBar - flatHighPriceBar)[0]) > FlatPriceRange * TickSize)
{
flatHighPriceEnd = CurrentBar - 1;
FlatHighbar = false;
FlatHigh = false;
Draw.ArrowDown(this, "Flat H End Bar = " + flatHighPriceEnd, true, CurrentBar - flatHighPriceEnd, Highs[0][1] + TickSize, Brushes.Yellow, true);
}
Please see attachment with only the Flat High and Flat Low parts of the indicator enabled and observe Flat High arrows, vs only the start arrow of the first Flat Low.
Is this a major bug, or what?

Comment