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

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
    BertrandNinjaTrader Customer Service

    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 Kaledus, Today, 01:29 PM
          5 responses
          12 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by alifarahani, Today, 09:40 AM
          5 responses
          23 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          16 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by PhillT, Today, 02:16 PM
          2 responses
          7 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Working...
          X