Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling 'OnMarketData' method on bar -1: Collection was modified

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

    Error on calling 'OnMarketData' method on bar -1: Collection was modified

    > Error on calling 'OnMarketData' method on bar -1: Collection was modified; enumeration operation may not execute.




    What would this signify? my IsDataSeriesRequired = false, Calculate is OnEachTick no other defaults have been changed except description and name.

    At first I was thinking to add a CurrentBar < 1 check in OnMarketData but re-reading the message, I don't think that would help, right?

    How can I avoid this error?

    #2
    Hello NinjaCustomer,
    Thanks for your post.

    In general, this error is caused when you are iterating over a collection and modifying it at the same time. For example, if you were using a foreach loop on a list, and removing an item or adding an item to that list in the loop.

    Can you show use the specific snippet that is causing this error?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      ah I see the part before the colon is just saying what bar it occurred on, I'm not entirely sure what code it is as I use OnMarketData in several indicators and columns

      I suspect I know what MarketAnalyzer column is causing it but it loops through several HashSets, Dictionaries and Lists so it will take some time to figure out. Would it be ok just to have the MarketAnyalyzerColumn lock these things while it processes them?

      ... I think the problem might be that I'm using IEnumerable (when I'm using .Where() ) on some lists and such and passing that around, I guess if I change that to ToList() this should solve my problems.
      Last edited by NinjaCustomer; 05-03-2019, 08:18 AM.

      Comment


        #4
        NinjaCustomer,

        Since this is a C# error message you can likely find any information by searching google for the message itself.

        Perhaps "collection was modified enumeration operation may not execute c#" would be a good start point
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          yes thanks, I realized after doing some searches that the text right of the colon was an actual C# error. I'll keep that in mind in the future when I see similar messages with events and colons.

          note to self:

          c# - Collection was modified; enumeration operation may not execute - Stack Overflow

          c# - IEnumerable Where() and ToList() - What do they really do? - Stack Overflow
          Last edited by NinjaCustomer; 05-03-2019, 08:27 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by b16_aln, Today, 05:15 AM
          0 responses
          4 views
          0 likes
          Last Post b16_aln
          by b16_aln
           
          Started by sidlercom80, Today, 04:57 AM
          0 responses
          7 views
          0 likes
          Last Post sidlercom80  
          Started by patricia70, Today, 03:57 AM
          0 responses
          5 views
          0 likes
          Last Post patricia70  
          Started by pjsmith, Today, 03:25 AM
          0 responses
          7 views
          0 likes
          Last Post pjsmith
          by pjsmith
           
          Started by cincai, Today, 01:04 AM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Jason  
          Working...
          X