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

Using C#.Net 2.0 Generic Lists in NinjaScript

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

    Using C#.Net 2.0 Generic Lists in NinjaScript

    I am trying to use a C# Generic List to maintain a list of orderId pairs that I need to revisit at a later time. Using Generic Lists is a great way to maintain a dynamic collection of items of various data types (e.g., string, integer, double) and comes with numerious built-in methods to manipulate the List content over and above ArrayList functionality, so I would like to get this to work.

    The code complies fine, and I have verified that I can add multiple elements and recall their values at runtime, no problem. However, once I have processed an OrderId pair I want to remove it from the list using RemoveAt( idx) so I don't have to read it again, but when I do I get the following error:

    "Error on calling 'OnBarUpdate' method for strategy 'mystrategy'. Collection was modified; enumeration operation may not execute."

    and the strategy code stops working. I would appreciate it to learn if Support or other advanced users have used Generics and might know whether there are special considerations for removing elements from a generic list within Ninja? Thanks.

    Regards,

    Whitmark
    whitmark
    NinjaTrader Ecosystem Vendor - Whitmark Development

    #2
    - the issue is not related to generics
    - as the error message suggest the collection is modified as you iterate through it. If the collection is completely managed by your code, the your code modifies this collection within the "foreach" loop

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by FrazMann, Today, 11:21 AM
    2 responses
    6 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by rjbtrade1, 11-30-2023, 04:38 PM
    2 responses
    80 views
    0 likes
    Last Post DavidHP
    by DavidHP
     
    Started by Spiderbird, Today, 12:15 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by lorem, Yesterday, 09:18 AM
    5 responses
    18 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by cmtjoancolmenero, Yesterday, 03:58 PM
    12 responses
    42 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X