Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to read all Anchors of Short Line

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

    How to read all Anchors of Short Line

    hello,

    How to read all Anchors of Short Line (brush.cyan generated by a strategy) .

    If I draw a line manually , code works good. But when I add strategy that make short line , I have an issue.

    GetType show that is a Line , but impossible to get Anchors.




    Name: Line GetType().Name: Line draw.Tag: Line 3 (FOR manual drawing Line)
    draw: 4996 End: 5007 .Price 3558.37752711497

    Name: Line GetType().Name: Line draw.Tag: sline_09/11/2020 17:26:00 (FOR Strategy drawing short Line color cyan)
    Strategy 'M_Strategy': Error on calling 'OnBarUpdate' method on bar 5015: Object reference not set to an instance of an object.



    foreach (IDrawingTool draw in DrawObjects)
    {
    Print("Name: " + draw.Name + " GetType().Name: " + draw.GetType().Name + " draw.Tag: " + draw.Tag);

    DrawingTools.Line globalLine = draw as DrawingTools.Line;

    if (draw.GetType().Name == "Line")
    Print("draw: " + globalLine.StartAnchor.SlotIndex + " End: " + globalLine.EndAnchor.SlotIndex + " .Price " + globalLine.EndAnchor.Price);
    }

    #2
    Hello oceanis400, thanks for writing in.

    I moved this post to a new thread from the original location here.

    If you get object reference errors and you are not sure where they are coming from, use Visual Studio to attach to the NinjaTrader process. After it is attached, you can run the script and it will break at the line where the exception occurred. Here is the documentation on the subject:



    Try adding a null check to the line where the object is null in case you are accessing it at a time it is null. e.g.

    if(globalLine != null)
    { // access globalLine }

    All drawing tools on the chart, user drawn or indicator drawn, will be in this list. The anchors are available for any of the objects in the DrawObject list. The example here shows how to properly access the lines on a chart:



    Please let me know if I can assist any further.

    Comment


      #3
      Hello, ChrisL

      Impossible to get information of drawing Line made by strategy

      Is it possible to print all anchors directly in ForEach ... (without using : DrawingTools.Line globalLine = draw as DrawingTools.Line);


      foreach (IDrawingTool draw in DrawObjects)
      {
      Print("Name: " + draw.Name + " GetType().Name: " + draw.GetType().Name + " draw.Tag: " + draw.Tag);
      }

      Comment


        #4
        And all drawing object Brush

        Comment


          #5
          Hello oceanis400, thanks for your reply.

          If you make a reduced test script that I can test on my machine I will be happy to do so. Please make sure the script only re-creates the issue seen and I will provide feedback.

          I look forward to hearing from you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          566 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X