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

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 implementation.

                  Use the SortedList class, which enables binary search. Call the ContainsKey and IndexOfKey methods.


                  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 fx.practic, 10-15-2013, 12:53 AM
                  5 responses
                  5,404 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by Shai Samuel, 07-02-2022, 02:46 PM
                  4 responses
                  95 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by DJ888, Yesterday, 10:57 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by MacDad, 02-25-2024, 11:48 PM
                  7 responses
                  159 views
                  0 likes
                  Last Post loganjarosz123  
                  Started by Belfortbucks, Yesterday, 09:29 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post Belfortbucks  
                  Working...
                  X