Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IDrawObject

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    IDrawObject

    I have created an indicator that draws Support Resistance Lines. Everything works fine, no issues.

    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?

    PHP Code:
            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
                                ));
                        }
                    }
                }
            } 
    
    Or what might be a better way to solve this issue.

    #2
    TAJTrades,

    There unfortunately is no "sort". You would simply need to keep track as to where exactly you have draw objects placed already. If there is one already in that location, you would then have to move one of the objects to a different location. Alternatively, if an object already exists at that location you could modify that object to contain the text of both objects and then it would just become a longer string being written.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh. Thought that might be the situation. The backup plan is to use a SortedList and check the Key for possible duplication and if so add to the string.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      599 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      344 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      558 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      557 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X