Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible to catch 'Draw' event?

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

    Is it possible to catch 'Draw' event?

    Hello,

    Is it possible to catch the event when an object is drawn by NinjaScript?

    Is it possible to access iDraw object's properties - color, y-position, etc?

    Thanks,

    Valentin

    #2
    Hello,

    Thank you for the question.

    I am unsure of a way to catch the actual event of the drawing object being added, but you could certainly look for new objects with each tick or in OnBarUpdate.

    There is a post that demonstrates looping through the DrawingObjects collection to find a specific object. This type of logic could be added to any of the override methods to check this when you need it. In the post I look for a Ray object and cast it to a Ray so I can get its specific properties.



    I look forward to being of further assistance.

    Comment


      #3
      Thank you Jesse. Is it possible to access the last drawing object without looping through the entire DrawingObjects collection?

      Also, I see that Y position is integer - maybe it shows position in pixels. How could I compare Y position of the drawing object with High / Low price of the corresponding bar?
      Last edited by Valyo; 08-12-2015, 07:57 AM.

      Comment


        #4
        Hello,

        There is no significant variable that defines this and also the DrawObjects collection does not have a Index you can use, it accepts a ["tag"] instead so a foreach is really the only way to iterate over this collection.

        You can use DrawObjects.Count to get a Count, this could be used to check if the count has increased to trigger logic so the loop does not run all the time.

        Unfortunately some logic would be required as this is not really a supported item to start with so there was no intended "last added" variable or anything.

        For the Y position, this would be a price that is returned if you have used the same as the example. The values would be the same values you see in the objects properties -> data tab.

        For example if I draw a Ray at a price of 2000, the Anchor1Y would be 2000, depending where I had placed the second point, the Anchor2Y would be that value.

        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 08-12-2015, 08:57 AM.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello,

          Thank you for the question.

          I am unsure of a way to catch the actual event of the drawing object being added, but you could certainly look for new objects with each tick or in OnBarUpdate.

          There is a post that demonstrates looping through the DrawingObjects collection to find a specific object. This type of logic could be added to any of the override methods to check this when you need it. In the post I look for a Ray object and cast it to a Ray so I can get its specific properties.



          I look forward to being of further assistance.
          DrawObjects is a collection. You can always get a particular item by its index. The last item in a collection is always at index (Count - 1).

          Once you have the object, test and cast it, if suitable, then access its properties.

          Comment


            #6
            DrawObjects[] accepts only string as identifier.
            DrawObjects[DrawObjects.Count-1] cannot be compiled.

            Comment


              #7
              Hello,

              also the DrawObjects collection does not have a Index you can use, it accepts a ["tag"] instead so a foreach is really the only way to iterate over this collection.
              My phrasing could have been better, I mean that it does not accept an index location but rather accepts a Tag.

              You could also get the enumerator and use a While to loop through this but I personally feel this is more effort than the foreach.

              IEnumerator enu = DrawObjects.GetEnumerator();

              while (enu.MoveNext())
              {
              object value = enu.Current as IDrawObject;
              if(value != null)
              {
              if(value.GetType().ToString() == "NinjaTrader.Gui.Chart.ChartRay")
              {
              IRay ray = value as IRay;
              Print(ray.Anchor1Y);
              }
              }
              }

              Either way still looping through the collection to find the object.

              I look forward to being of further assistance.

              Comment


                #8
                Jesse, I have another question. Is it possible to get bar's properties of the bars plotted on the chart? For example color, outline, etc. Are there 'bar' objects similar to drawing objects?

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                580 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                335 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                102 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