Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

DrawObject error.

Collapse
X
 
  • 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.

    #2
    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

    Comment


      #3
      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.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by alifarahani, Today, 09:40 AM
      2 responses
      12 views
      0 likes
      Last Post alifarahani  
      Started by junkone, Today, 11:37 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by pickmyonlineclass, Today, 12:23 PM
      0 responses
      1 view
      0 likes
      Last Post pickmyonlineclass  
      Started by frankthearm, Yesterday, 09:08 AM
      12 responses
      44 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by quantismo, 04-17-2024, 05:13 PM
      5 responses
      35 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X