![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Sep 2007
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
Suppose I have the following code snippet:
LinkedList<int> a = new LinkedList<int>(); a.AddLast(1); foreach(int i in a){ } A window pops up at compilation because of the foreach statement. But then even the foreach is removed, NinjaTrader cannot compile the strategy. Only a restart can solve this problem. Here's what I don't understand: 1) foreach works well in .NET on LinkedList, why not in NinjaTrader? 2) why I have to restart NinjaTrader because of a bug or mis-use of keywords in my program? (If Visual Studio .NET does this, I'd short MSFT!) |
|
|
|
|
|
#2 |
|
Junior Member
Join Date: Sep 2007
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
Perhaps I was wrong. NinjaTrader's exception report might not be relevant to foreach. Since the following code snippet produces the exception as well,
// iSL is a linkedlist IEnumerator<int> e = iSL.GetEnumerator(); while(e.MoveNext()){ int i = e.Current; Print(" " + this.pl(i2j(i))); } The problem is not consistent. The following procedure solved the problem sometimes: 1) Close the strategy editor 2) Open the strategy editor 3) compile EXACTLY the same code that previously leads to error works sometimes!
|
|
|
|
|
|
#3 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
I don't believe .NET has a linked list by default. http://www.codeproject.com/csharp/doubly-linkedlist.asp
foreach should work fine. I used it in this indicator sample with no problems. I'm not sure which error window pop up you are referring to, but if you are seeing the same one I think you are seeing you can do this instead of restarting NinjaTrader.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Sep 2007
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
Thx for the prompt reply, Josh.
Though I'm not an expert, .NET does have a LinkedList implementation in the namespace System.Collections.Generic. I tried it in studio.net, it works well. I got those error reporting under VMWare Fusion hosted on an iMac. I just rebooted my computer (an iMac) into windows XP. It seems I can't reproduce that problem. ![]() Really confused! |
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Ahh. Generic does the trick. Thanks for the info. The NinjaScript editor issue happens once in awhile. Majority of the times you won't experience it.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 | |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Quote:
Please try adding Code:
using System.Collections.Generic;
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
|
Borrowing this thread for a related question;
foreach loop gives error even though Iīve been adding the System.Collections.Generic namespace. Code; foreach (int bars in HighestbarsDS) { if (bars != 0) { PeaksDS.Set(bars); } } Error message; foreach statement cannot operate on variables of type 'NinjaTrader.Data.DataSeries' because 'NinjaTrader.Data.DataSeries' does not contain a public definition for 'GetEnumerator' Why canīt the foreach loop access the HighestbarsDS dataseries array? Any suggestion on how to resolve this?
Last edited by FREEN; 02-11-2011 at 03:10 AM.
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
FREEN, the dataseries do not implement an IEnumerable interface...try looping trough them the regular way.
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling Code | moflaherty | Suggestions And Feedback | 2 | 08-22-2007 07:23 PM |
| Compiler Error when compiling standard Ninja indicators | MarlinTrader | General Programming | 1 | 05-25-2007 01:28 PM |
| Unhandled Exception, Strategy & Market Replay Connection | californiaruby | Automated Trading | 5 | 02-20-2007 01:24 AM |
| Compiling NinjaScript Files - How does it work? | NinjaTrader_Ray | General Programming | 0 | 01-24-2007 03:00 AM |
| Unhandled Exception? | copodon | Miscellaneous Support | 1 | 03-08-2006 04:11 AM |