Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order by Descending/Ascending of SortedList

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

    Order by Descending/Ascending of SortedList

    I'm developing a MACD indicator for which I need to store the bar number and value of the MACD pivots. I am doing so using a SortedList which provides a Key/Value pair.

    I'm keeping a list of the last 10 pivots above and below the MACD zero line. The piece I can't get is to sort the values in descending or ascending order.

    I know this is beyond the support normally provided, but was hoping someone can give me a hint.

    Thanks,
    taddypole...
    Attached Files

    #2
    Taddypole, I would suggest checking into this thread from Stackoverflow on the same topic to resort by value - http://stackoverflow.com/questions/1...-value-c-sharp

    Comment


      #3
      Following the examples, I was able to get my list sorted in ascending/descending order. I was also able to print out the list using pair.Key and pair.Value.

      What I am struggling with now is to access the pairs by index. Like in SortedList there are methods to access the '.Keys and '.Values.

      These are not available in Lists. I want to iterate through the list in order to compare the next value with the previous. I'm not sure how to do that.


      List<KeyValuePair<int, int>> myHighList = highPvtMacdList.ToList();
      myHighList.Sort((x,y)=>y.Value.CompareTo(x.Value)) ;


      Print("Macdtest - high Pivot");
      foreach(KeyValuePair<int,int> pair in myHighList)
      {
      Print("Macdtest - high Pivot" + " Key = " + pair.Key + " Value = " + pair.Value);
      }

      thanks,
      taddypole...
      Attached Files

      Comment


        #4
        Using a List to keep track of the anchor bars and to manage the collection to a set of 10 and then using a SortedList to keep a collection of KeyValue pairs of Macd Pivot values to anchor bars in a sorted manor, I was able to accomplish what I wanted.
        Attached Files

        Comment


          #5
          Hi Taddypole,

          Thanks for following up with your solution! I'm sure your example will be useful for other users in the future.
          MatthewNinjaTrader Product Management

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          560 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          325 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X