NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 10-08-2007, 06:54 AM   #1
whitmark
Certified NinjaScript Consultant
 
Join Date: Nov 2005
Location: Virginia, USA
Posts: 441
Thanks: 0
Thanked 12 times in 7 posts
Send a message via Skype™ to whitmark
Default 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 is offline  
Reply With Quote
Old 10-08-2007, 07:08 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

- 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
NinjaTrader_Dierk is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
NinjaScript Editor Bug NinjaTrader_Josh Suggestions And Feedback 11 08-17-2007 12:34 AM
Where to learn NinjaScript ?? ts888 General Programming 3 06-30-2007 01:58 PM
Parameter selection lists ThePatientOne Indicator Development 3 05-11-2007 08:48 AM
ASM Reversals from NinjaScript? DarrylT Strategy Development 1 01-19-2007 10:49 AM
NT6 NinjaScript Vs NT5 underground Indicator Development 2 11-22-2006 05:44 AM


All times are GMT -6. The time now is 12:44 AM.