Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TryStartDrawing

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

    TryStartDrawing

    Hi.

    I'm using the 'TryStartDrawing()' feature, and everything is OK (the platform starts drawing the related object). However, how can I programmatically capture this newly drawn object?

    I want to achive this:
    - draw the line using 'TryStartDrawing()';
    - identiify start and end point programmatically;

    #2
    Hello webus,

    Thank you for your post.

    Are you using TryStartDrawing() in a separate DrawingTool script?

    All drawing objects on the chart would be in the DrawObjects collection, which you can access programmatically:



    The Help Guide page linked above has code demonstrating looping through the collection to find specific draw objects.

    Please let us know if you have any further questions.

    Comment


      #3
      Hi NinjaTrader_Gaby​,

      Are you using TryStartDrawing() in a separate DrawingTool script?
      I'm using it in my Indicator. I click a button and as soon as the button is clicked - TryStartDrawing() is called from the related callback.

      All drawing objects on the chart would be in the DrawObjects collection, which you can access programmatically:
      Yes, I know this, but it is not a good approach. Your approach is linked with the OnBarUpdate(), but I can click the button even if the market is closed. I do not want to create a timer to monitor the DrawObjects collection; I want to achieve this via a callback. Is this possible to subsribe such a callback?​​

      Comment


        #4
        Hello webus,

        You would need to use the correct Draw method for your indicator to have it return an instance of the object which can then be accessed.

        If you made a custom drawing object, you would need to add the static Draw class elements into your code and make the methods to draw the object (the same way the internal DrawingTool scripts do).

        If you're using a normal object that comes with the platform, you could just use the standard Draw methods:


        Accessing the DrawObjects collection is not linked with OnBarUpdate(). The sample code in the Help Guide shows the code within OnBarUpdate() however you don't need to access it via OBU, it can be accessed via your button press as long as your script is working in realtime.

        Comment


          #5
          Hi NinjaTrader_Gaby​,​

          Probably I was not clear, or I'm missing something. Let me explain again how it work, the concept. I have an Indciator. The Indicator have a button. As soon as the button is clicked - ChartControl.TryStartDrawing("NinjaTrader.NinjaScr ipt.DrawingTools.Line") is called and the user start to draw the Line manually. The user can draw the line immideatelly, or he can draw it within 10 minutes (or 1 hour, or 5 seconds), or the user can press 'esc' and the drawing will be aborted -> all these evenst work OK. I want to catch the moment when the Line has been drawn (when the user has chosen the second anchor).
          Again, the Indicator does not draw the Line. The Line is drawn manually by the user (the related 'pen' appears with the selected 'Line' object ready for drawing manually).

          Comment


            #6
            Hello webus,

            While this is not documented, you may try adding an event handler to the ChartObjects.CollectionChanged event.
            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
            582 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            338 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
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X