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

Highest Value in a Series

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

    Highest Value in a Series

    I have 7 different values for the last seven bars:

    ParabolicSar(0.2, 0.08, 0.2)[1] - Close[1]
    ParabolicSar(0.2, 0.08, 0.2)[2] - Close[2]
    ParabolicSar(0.2, 0.08, 0.2)[3] - Close[3] . . .

    I would like to identify the highest 2 values and disclude them. How can I do this?

    Any advice is greatly appreciated

    #2
    Hello ronaldgreene828, thanks for your post.

    Put all of the values into a List<double>. You can sort the list from highest to lowest then remove the first two values.
    Here's a method I found on the web for getting the highest and second-highest value of the list, you can use that and remove the two highest values:
    Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


    Here are some other publicly available links that can help:
    The List&lt;T&gt; class in C# and .NET represents a strongly typed list of objects. List.Remove() and List.RemoveAt() methods with List.Clear() method can be used to remove items of a List&lt;T&gt; in C#. The code examples in this article demonstrates how to remove an item of a List using C#.

    Sorts the elements or a portion of the elements in the List using either the specified or default IComparer implementation or a provided Comparison delegate to compare list elements.


    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. If I remove only the highest value, how do I remove it from the list? I wish to add the remaining values in the list and divide by 5. I'm trying to simplify things -- thanks


      public static int TheFurthest()

      {

      List<int> myList = new List<int>() { H1, H2, H3, H4, H5, H6 };

      int Furthest = int.MinValue;

      foreach (var item in myList)

      {

      if (item > Furthest)

      {

      Furthest = item;

      }

      }

      Return Furthest;

      }
      Last edited by ronaldgreene828; 09-04-2020, 09:07 AM.

      Comment


        #4
        Hello, thanks for your reply.

        To remove an item you need to call myList.Remove(item). You would not want this in a method, you need a reference to the List as an object of your strategy/indicator class.

        The easiest way of doing this would be to sort the list and do: list.RemoveAt(0);

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          I was hoping for something I can understand or see an example. Like many of us, I apologize that I have very little experience working with code and the formatting required.
          Actually I think what you gave me that provides the max and second max values will give me what I'm looking for without removing anything from the list. I hope I can make it work by plugging it into my strategy.
          Last edited by ronaldgreene828; 09-04-2020, 12:05 PM.

          Comment


            #6
            Hi ronaldgreene828, thanks for your reply.

            Unfortunately working with lists and manipulation goes out of the scope of support I can provide. We do have many active members that help out with things like this. I suggest getting very comfortable using C# and all the wonderful things it can do. When you are comfortable with using and manipulating objects and data structures, you can do just about anything in a script. I recommend this publicly available help guide on C# called dotnetpearls, it is a great resource for learning C#:
            Create a new List, add elements to it, and loop over its elements with for and foreach.


            Kind regards.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              No problem, I found a way to do it with a series of sets in the strategy builder and I can duplicate and edit the sets so that it won't be too difficult. Then I can paste the sets into the unlocked strategy.

              Comment


                #8
                Originally posted by ronaldgreene828 View Post
                No problem, I found a way to do it with a series of sets in the strategy builder and I can duplicate and edit the sets so that it won't be too difficult. Then I can paste the sets into the unlocked strategy.
                Great, can you share your findings? I am also thinking of something similar, so that would be very helpful. Thanks.

                Comment


                  #9
                  Ok,
                  It uses almost 70 sets, but each has very few lines and there are no calculations so it shouldn't create any problems. The same would have the signs reversed for indicator values below the bar. I'll attach the steps and the code
                  Attached Files

                  Comment


                    #10
                    I made changes to the document above and re-uploaded and now all of the variables match with the code

                    Comment


                      #11
                      Here it is again with another note. H1 - H10 are the values in a series
                      Attached Files

                      Comment


                        #12
                        In this edit, I removed the variables [B1highest – B4highest] from the steps. They were not needed and are not in the code
                        Attached Files

                        Comment


                          #13
                          Wow. Large code. I will inspect it later. Thanks. Great that you found a solution!

                          Comment


                            #14
                            For just the highest and lowest values ("nearest" and "furthest" variables), you can take the last steps for the nearest value and then copy and flip the signs for the furthest value. This would eliminate half the sets and is simpler

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by proptrade13, Today, 11:06 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post proptrade13  
                            Started by kulwinder73, Today, 10:31 AM
                            1 response
                            10 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Started by RookieTrader, Today, 09:37 AM
                            3 responses
                            15 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by terofs, Yesterday, 04:18 PM
                            1 response
                            24 views
                            0 likes
                            Last Post terofs
                            by terofs
                             
                            Started by CommonWhale, Today, 09:55 AM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Working...
                            X