Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to find the 1st, 2nd, and 3rd highest volume for the day in real time

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

    #16
    Originally posted by Taddypole View Post
    Thanks koganam, I really appreciate your help!

    Can you help me with the declaration and Initialization sections for a SortedList. I've been trying but get compile errors.

    Variables:
    private int VolumeValue;
    private int VolumeBar;

    private SortedList<VolumeValue,VolumeBar> MySlVolume = new SortedList<VolumeValue,VolumeBar>();

    Initialize: ???

    I was reading this thread



    and someone was having problems with initialization the SortedList. So not which way to go.
    You create the object with the base types, not your declared variables.
    Code:
    private SortedList<int, int> MySlVolume = new SortedList<int, int>();

    Comment


      #17
      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


        #18
        Originally posted by Taddypole View Post
        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?
        They are both fine.

        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


          #19
          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.
          Attached Files

          Comment


            #20
            Originally posted by Taddypole View Post
            Ran 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.
            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.

            Comment


              #21
              Great! Thanks Koganam

              Works perfectly...

              hopefully no more speed bumps.

              Regards,
              taddypole...

              Comment


                #22
                Have you by any chance converted this for NT8?

                Comment


                  #23
                  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&lt;T&gt; 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 Hwop38, 05-04-2026, 07:02 PM
                  0 responses
                  160 views
                  0 likes
                  Last Post Hwop38
                  by Hwop38
                   
                  Started by CaptainJack, 04-24-2026, 11:07 PM
                  0 responses
                  308 views
                  0 likes
                  Last Post CaptainJack  
                  Started by Mindset, 04-21-2026, 06:46 AM
                  0 responses
                  245 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by M4ndoo, 04-20-2026, 05:21 PM
                  0 responses
                  349 views
                  0 likes
                  Last Post M4ndoo
                  by M4ndoo
                   
                  Started by M4ndoo, 04-19-2026, 05:54 PM
                  0 responses
                  179 views
                  0 likes
                  Last Post M4ndoo
                  by M4ndoo
                   
                  Working...
                  X