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

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 RookieTrader, Today, 09:37 AM
          3 responses
          13 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by kulwinder73, Today, 10:31 AM
          0 responses
          3 views
          0 likes
          Last Post kulwinder73  
          Started by terofs, Yesterday, 04:18 PM
          1 response
          22 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by CommonWhale, Today, 09:55 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by Gerik, Today, 09:40 AM
          2 responses
          7 views
          0 likes
          Last Post Gerik
          by Gerik
           
          Working...
          X