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 Haiasi, 04-25-2024, 06:53 PM
          2 responses
          16 views
          0 likes
          Last Post Massinisa  
          Started by Creamers, Today, 05:32 AM
          0 responses
          4 views
          0 likes
          Last Post Creamers  
          Started by Segwin, 05-07-2018, 02:15 PM
          12 responses
          1,785 views
          0 likes
          Last Post Leafcutter  
          Started by poplagelu, Today, 05:00 AM
          0 responses
          3 views
          0 likes
          Last Post poplagelu  
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,407 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Working...
          X