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

Announcement

Collapse
No announcement yet.

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 Beauregard, Today, 04:36 AM
      0 responses
      2 views
      0 likes
      Last Post Beauregard  
      Started by fx.practic, Today, 04:34 AM
      0 responses
      1 view
      0 likes
      Last Post fx.practic  
      Started by thomaspartyof10, Today, 02:33 AM
      0 responses
      7 views
      0 likes
      Last Post thomaspartyof10  
      Started by ArmKnuckle, Today, 01:59 AM
      0 responses
      12 views
      0 likes
      Last Post ArmKnuckle  
      Started by seppyr, Today, 01:53 AM
      0 responses
      10 views
      0 likes
      Last Post seppyr
      by seppyr
       
      Working...
      X