• 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

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, 09: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, 09:27 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jvanelli, Today, 09:23 PM
          0 responses
          5 views
          0 likes
          Last Post jvanelli  
          Started by lavalampmj, Today, 06:07 PM
          1 response
          6 views
          0 likes
          Last Post bltdavid  
          Started by Sameer, Today, 04:40 PM
          1 response
          35 views
          0 likes
          Last Post NinjaTrader_EricB  
          Started by Teebone21, Today, 04:34 PM
          0 responses
          9 views
          0 likes
          Last Post Teebone21  
          Started by KarstenKafl, Today, 03:34 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X