I find a swing high
I check to see if it is the first swing high at that price
If it is, I look back to see if there is an equal high that isn't a swing high. If I find one, I draw a line from the equal high to the swing high. Then start a new line at that price that is a different color
if it's not the first swing high at that level, I draw a line from the last swing high to the current one, then start a new line at that price that is a different color
In the top image you can see that there are 2 lines that are in the Drawing Object list that didn't draw on the chart. But when I click on a line to bring up the Drawing Object list, then close the box, the lines show up. That's the bottom image
My code is below
What am I doing wrong?
protected override void OnBarUpdate()
{
if (CurrentBar < 2) return;
if(CurrentBar == 3)
startTime = DateTime.Now.Ticks;
if ((High[1] >= High[0]) && (High[1] >= High[2])) // FOUND SWING HIGH
{
AddSwingHigh();
}
if (swingHighs.Count > 0) // GO THRU LIST AND DRAW ANY OPEN SWING HIGH LINES
for (x = swingHighs.Count - 1; x >= 0 ; x--)
{
DrawSwingHighs(
swingHighs[x].swingHLValue,
swingHighs[x].swingHLStartTime,
Time[0],
swingHighs[x].eqhlCount);
if(High[0] > swingHighs[x].swingHLValue) // CHECK FOR END OF SWING HIGH
{
swingHighs.RemoveAt(x); // REMOVE SWING HIGH FROM LIST
}
}
if (Count - 2 == CurrentBar)
{
DrawTextBox1();
Print("IFVGComboTest " + (DateTime.Now.Ticks - startTime)/10000); // PRINT INDICATOR LOAD TIME
}
}
//==================================================================================================
//==================================================================================================
//==================================================================================================
private void AddSwingHigh()
{
if (swingHighs.Count(a => a.swingHLValue == High[1]) == 0) // FOUND NEW SWING HIGH
{
CheckBackForEqualHigh(); // CHECK BACK TO SEE IF PRIOR EQUAL HIGHS
swingHL v = new swingHL();
v.eqhlCount = eqhlCount + 1;
v.swingHLStartTime = Time[1];
v.swingHLEndTime = Time[0];
v.swingHLValue = High[1];
swingHighs.Add(v); // ADD NEW SWING HIGH TO LIST
swingHighs.Sort((y, x) => x.swingHLStartTime.CompareTo(y.swingHLStartTime));
}
else // FOUND ADDITIONAL SWING HIGH
{
int x = swingHighs.FindIndex(a => a.swingHLValue == High[1]);
DrawSwingHighs(swingHighs[x].swingHLValue, // DRAW SWING HIGH FROM PRIOR SWING HIGH TO CURRENT SWING HIGH
swingHighs[x].swingHLStartTime,
Time[1],
swingHighs[x].eqhlCount);
swingHighs[x].swingHLStartTime = Time[1];
swingHighs[x].swingHLEndTime = Time[1];
swingHighs[x].eqhlCount = swingHighs[x].eqhlCount + 1;
}
}
//==================================================================================================
private void CheckBackForEqualHigh()
{
eqhlCount = 0;
for ( int i = 2 ; i <= CurrentBar ; i++)
{
if(High[i] > High[1]) // STOP CHECKING BACK
{
break;
}
else if(High[i] == High[1]) // FOUND PRIOR EQUAL HIGH
{
DrawSwingHighs( // DRAW SWING HIGH LINE FROM PRIOR EQUAL HIGH TO CURRENT SWING HIGH
High[i],
Time[i],
Time[1],
1);
eqhlCount = 1;
}
}
}
//==================================================================================================
private void DrawSwingHighs(double price, DateTime start, DateTime end, int strength)
{
Draw.Line(this, "swingHigh-" + start, false,
start,
price,
end,
price,
strength == 1 ? Brushes.Green : strength == 2 ? Brushes.Lime : Brushes.Cyan,
strength == 1 ? DashStyleHelper.Dash : DashStyleHelper.Solid,
strength == 1 ? 1 : swingHLLineThickness,
true);
}
​
Comment