• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


DrawObject error.

  • Filter
  • Time
  • Show
Clear All
new posts

    DrawObject error.

    I have the following Line of code.

    var lines = DrawObjects.Where(x => x is Line ); part of an anonymous async method, triggered with the TriggerCustomEvent() method.

    DrawObjects contains thousands of objects( including arrows, text and rectangles and lines) when this line runs. It returns different results when is in debug mode vs release mode, and either way, it does not return the real amount or lines I have in my chart. I have a similar line to return the rectangles on a collection, and that line works as expected( at least better than the code for the lines). Any idea on why this happens?

    Thank you.

    Hello Yandychang,

    Thank you for the post.

    While I can't provide any detail on the debug/release mode difference I can say that this could be related to where it is being called and the way you are calling it.

    You mentioned using TriggerCustomEvent and also an async method, where specifically is this syntax being called from? Also how are you checking the contents of what you find? I would not suggest using the visual studio tools to inspect objects but would suggest using a Print and iterating over the found items.

    As a side note, I see you are not using ToList(), this is required in some cases to avoid threading errors when accessing the Drawing Objects collection:

    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.

    Do you also see the same result in a more simple test, for example if you do not use the async method and execute this code in Realtime from OnBarUpdate from an indicator? If so can you provide a specific sample of the syntax used?

    If you are executing this code before realtime, the results also can be variable. There is no guarantee a manually drawn object will be added to the DrawObjects collection before an indicator starts processing data.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service


      I have it running on a method that gets triggered on a click event. Not sure if it fixed it, but adding DrawObjects.ToList() may have helped. Previously it was only collecting 10-15% of the amount of lines there where, now it collects about 85- 90% of them. The DrawObjects collection is large, so running it in the same thread as the chart freezes it for several minutes. I compared the number of lines when debugging on VS to the number of lines on the draw objects properties window and is close enough. Thanks for the help.


      Latest Posts


      Topics Statistics Last Post
      Started by harjinderjit, Today, 06:41 PM
      0 responses
      Last Post harjinderjit  
      Started by Herrwolf1, Today, 09:37 PM
      1 response
      Last Post NinjaTrader_ChelseaB  
      Started by tjendra, Today, 11:13 AM
      2 responses
      Last Post tjendra
      by tjendra
      Started by rgoudie, Today, 08:11 PM
      1 response
      Last Post NinjaTrader_ChelseaB  
      Started by simonerg, Today, 06:00 PM
      4 responses
      Last Post simonerg