Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check if current DrawingTool instance is the latest one on chart

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

    Check if current DrawingTool instance is the latest one on chart

    I have a custom DrawingTool that I created.
    Let's call it ABC for the simplicity.

    ABC tool (like any other DrawingTool) can have many instances on the same chart.

    How can I check programmatically if the current instance is the latest one?

    I need the ABC tool to perform some additional action if it is the only instance on the chart or latest instance drawn (so the previous ones will stop to perform this specific action).

    How can I loop through all ABC tools drawn on the chart and decide if this is the latest one of its kind?

    Thanks in advance.

    #2
    Hello xfactscout,

    A simple way would be to add the CurrentBar number to the tag string.

    When looping through the DrawObjects collection, you can check the string for the highest bar number.


    Use string.SubString() to retrieve a specific part of the string.
    Retrieves a substring from this instance. This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks ChelseaB.
      Can you please write a more specific explanation with an example?
      Starting with how to add the current bar number to the Tag. Since my tags are created automatically by NinjaTrader (ABC then ABC 2 then ABC 3 etc.) every time I draw a new instance of the tool.

      Comment


        #4
        Append your incrementing number, and then add CurrentBar

        Even though CurrentBar is an int, when an int is appended to a string,
        the int value is automatically converted to a string by C#.

        That is,
        string tagName = "ABC" + CurrentBar;
        is equal to
        string tagName = "ABC" + CurrentBar.ToString();

        So, just use "ABC" + CurrentBar, then "ABC2" + CurrentBar, then "ABC3" + CurrentBar, etc

        Make sense?

        Comment


          #5
          Hello xfactscout,

          Attached is an example.
          FindDrawObjectWithHighestBarNumberExample_NT8.zip
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 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
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X