Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting all manually drawn objects on a chart using C#

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

    Getting all manually drawn objects on a chart using C#

    Hi!

    I am trying to figure out if there is a way to get all manually drawn objects (or just lines) on a chart using C# so I can relay that to a db for other users to see.

    Is there a way to do the detection part ? The second part, db population, is not a problem.

    Thanks​​

    #2
    Hello z679Gju,

    Thanks for your post.

    You could loop through the DrawObjects collection to get manually drawn objects on a chart window.

    See the help guide documentation below for more information about the DrawObjects collection and sample code demonstrating looping through the collection to find specific draw objects.

    DrawObjects: https://ninjatrader.com/support/help...rawobjects.htm
    IDrawingTool: https://ninjatrader.com/support/help...rawingtool.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Excellent this is exactly what I was looking for thanks!

      Comment


        #4
        It seems this collection gets all objects created after the indicator was loaded. Is there a way to load all objects even those created before adding the indicator ? I would like this to be persistent.

        Comment


          #5
          Hello z679Gju,

          Thanks for your notes.

          Looping through the DrawObjects collection will get all lines drawn on the chart both before the indicator was added to the chart and after the indicator is added to the chart.

          For example, if we draw two lines on the chart manually, the tag name of this first line would be "Line" and the tag name of the second line would be "Line 2".

          If we enable the indicator that loops through the DrawObjects collection on the chart after drawing the lines we could see the information of both lines drawn before the indicator was added.

          The prints might look something like:

          Line Object: Line Manually Drawn: True
          Line Object: Line 2 Manually Drawn: True


          Here is a demonstration video showing this: https://brandonh-ninjatrader.tinytak...MF8yMjk1OTg0Mw

          Please also note the following from the DrawObjects help guide:

          "When reloading NinjaScript, all objects (including manual drawing tools) are reloaded at the same time. There is no guarantee a manually drawn object will be added to the DrawObjects collection before an indicator starts processing data."

          "DrawObjects.ToList() is thread safe. DrawObjects collection itself is still dynamic (meaning it updates live) and as a result you can still run the risk of the collection being modified while you try to read it (and thus would see the related C# log entry) However, DrawObjects.ToList() is a snapshot of DrawObjects collection at the time the call is made."

          DrawObjects: https://ninjatrader.com/support/help...rawobjects.htm
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            One point to note when trying to access drawing objects from third party indicator is that the indicator is likely to have been supplied in dll form (compiled). If so then the code for looping through the drawing objects needs to be slightly different as per the Considerations For Compile Assemblies https://ninjatrader.com/support/help...assemblies.htm

            Here is an example to identify Extended Lines:

            Code:
            foreach (dynamic line in DrawObjects.ToList())
            {
                 // Use ToString().Equals() to detect the object's Type
                 if (line.ToString().Equals("NinjaTrader.NinjaScript.D rawingTools.ExtendedLine"))
                 {
                      // Access the object by assuming that it is the Type we expect
                      Print(String.Format("ExtendedLine Line {0} detected!", line.Tag));
                  }
            }​
            ​​


            See the following thread for for more about this issue https://forum.ninjatrader.com/forum/...41#post1102141
            Last edited by trader-ap; 07-31-2024, 03:40 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            608 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            355 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            561 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X