Now I am trying to label the lines on the right margin using DrawText and thought I would use the IDrawObject instead of creating my on Dictionary. The problem I have encountered is that there are times when two or more lines are set on the same price point therefore the DrawText (Labels) are drawn on top of each other. Not good.
How do I sort the drawnLine in the following code? Can someone please point me in the right direction. What methods / code / website / chapter in a book should I be looking at?
protected void TestIDrawObject()
{
Print("\r\n************* TestIDrawObject() ********************");
Print("On Bar: " + Time[0] );
foreach (IDrawObject draw in DrawObjects)
{
if (draw is ILine)
{
ILine drawnLine = (ILine) draw;
DateTime CurrentBarDateTime = new DateTime(Time[0].Year,Time[0].Month,Time[0].Day,Time[0].Hour,Time[0].Minute, 0);
DateTime drawEndTime = new DateTime(drawnLine.EndTime.Year, drawnLine.EndTime.Month, drawnLine.EndTime.Day, drawnLine.EndTime.Hour, drawnLine.EndTime.Minute, drawnLine.EndTime.Second);
int drawEndTimeCompareValue = CurrentBarDateTime.CompareTo(drawEndTime);
if(drawEndTimeCompareValue < 0 )
{
int LastCharacter = drawnLine.Tag.IndexOf("|");
string LabelText = drawnLine.Tag.Substring(0, LastCharacter).Trim();
/*
Problem: May have more then one Line with the same drawnLine.EndY.
This cause Labels to print on top of each other.
Possible Sort the drawnLine on drawnLine.EndY. If current
Solution drawnLine.EndY == previous drawnLine.EndY then
place the DrawText below drawnLine.EndY else
place above drawnLine.EndY
*/
string DrawTextTag = "LineLabel " + drawnLine.Tag;
DrawText(DrawTextTag, LabelText, 0, drawnLine.EndY + (1*TickSize), Color.Black);
Print(string.Format(
"{0} \t {1} \t {2} \t {3} \t {4} \t {5} \t {6} \t {7} \t {8} ",
drawEndTimeCompareValue,
LastCharacter,
LabelText,
drawnLine.DrawType,
drawnLine.Tag,
drawnLine.StartTime,
drawnLine.EndY,
drawnLine.EndTime,
drawnLine.Pen.Color
));
}
}
}
}

Comment