private SortedList<int, int> MySlVolume = new SortedList<int, int>();
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to find the 1st, 2nd, and 3rd highest volume for the day in real time
Collapse
X
-
While you were responding I was able to try enough variations to come up with the attached indicator using Volume. This sortedList keeps a list of the 4 highest volumes looking for duplicates before adding a new one. This is just what I was looking for and will allow me to finish my project.
In your response you suggested:
#region Variables
private SortedList<int, int> MySlVolume = new SortedList<int, int>();
Does this code declare and initialize at the same time?
In my code:
#region Variables
private SortedList<int, int>
Initialize()
MySlVolume = new SortedList<int, int>();
Is either way OK? or is one preferable?Attached Files
Comment
-
They are both fine.Originally posted by Taddypole View PostWhile you were responding I was able to try enough variations to come up with the attached indicator using Volume. This sortedList keeps a list of the 4 highest volumes looking for duplicates before adding a new one. This is just what I was looking for and will allow me to finish my project.
In your response you suggested:
#region Variables
private SortedList<int, int> MySlVolume = new SortedList<int, int>();
Does this code declare and initialize at the same time?
In my code:
#region Variables
private SortedList<int, int>
Initialize()
MySlVolume = new SortedList<int, int>();
Is either way OK? or is one preferable?
It is great news that you came to the solution yourself, with barely hints from me as to what to do. I kind of sensed that you might prefer to reach your own solution, and am glad to think that I may have been right.
All the best to you, and may all your trades be winners!
Last edited by koganam; 05-22-2013, 05:34 PM.
Comment
-
Ran into another bump along the way.
Print("Test" + Time[0] + MySlVolume[0].ToString());
Print("Test" + Time[0] + MySlVolume[1].ToString());
Print("Test" + Time[0] + MySlVolume[2].ToString());
Print("Test" + Time[0] + MySlVolume[3].ToString());
Tried to print out the values at indexes 0,1,2,3 in MySlVolume. The code compiles but when applied to a chart I get an error message as follows:
System.Collections.Generic.KeyNotFoundException was unhandled by user code
Message=The given key was not present in the dictionary.
tried many things but can't get the print to work. Can't find a method to get key or value by index. This seems to be my problem. ????
Have attached updated VolTwo.cs file and a picture of the debugging session showing the SortedList with keys and values populated. Don't understand why i get this error message.
Comment
-
Your formatting will look kind of wacky on the screen, but just to correct your syntax, you are missing what is shown in red, that I have added, in your original text. IOW, you failed to reference the correct property.Originally posted by Taddypole View PostRan into another bump along the way.
Print("Test" + Time[0] + MySlVolume.Keys[0].ToString());
Print("Test" + Time[0] + MySlVolume.Keys[1].ToString());
Print("Test" + Time[0] + MySlVolume.Keys[2].ToString());
Print("Test" + Time[0] + MySlVolume.Keys[3].ToString());
Tried to print out the values at indexes 0,1,2,3 in MySlVolume. The code compiles but when applied to a chart I get an error message as follows:
System.Collections.Generic.KeyNotFoundException was unhandled by user code
Message=The given key was not present in the dictionary.
tried many things but can't get the print to work. Can't find a method to get key or value by index. This seems to be my problem. ????
Have attached updated VolTwo.cs file and a picture of the debugging session showing the SortedList with keys and values populated. Don't understand why i get this error message.
Comment
-
Hello Mindset,
The SortedList<int, int> is general c# and is not specific to NinjaScript.
Represents a collection of key/value pairs that are sorted by key based on the associated IComparer<T> implementation.
This specific object type will work in a script made for NinjaTrader 7 or a script made for NinjaTrader 8.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
571 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
330 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
548 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
549 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment