Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

sort question

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

    sort question

    Hi ... Zacahry assisted me awhile back on a section of code that selects the most current instrument form the Default instrument list. The code is as follows:

    NinjaTrader.Cbi.InstrumentList list = NinjaTrader.Cbi.InstrumentList.GetObject("Default" );
    bool contractFound = false;
    List<string> selectedInstruments = new List<string>();
    foreach (Instrument myInstrument in list.Instruments)
    {
    if (myInstrument.FullName.Contains(defaultInst)) {selectedInstruments.Add(myInstrument.FullName); contractFound = true;}
    }

    if (contractFound)
    {
    selectedInstruments.Sort();
    selectedInstruments.Reverse();
    selected_contract = selectedInstruments[0];
    }
    else
    {
    selected_contract = "";
    runProgram = false;
    }

    This works find except when I have a contract that is for a prior year but a greater month. For example if I have the current ES contract "ES 09-15" as well as an older contract, "ES 12-14", the selectedInstruments.Sort(); selectedInstruments.Reverse(); lines will sort the "ES 12-14" first. But I want "ES 09-15". The issue being how the order of the text puts the month before the year. How do I sort first but year, then by month while keeping the text format in tact?

    thanks!

    #2
    Hello,

    Thank you for the post, It looks like this is a duplicate of your prior post in this forum:


    Please refrain from making multiple posts on the same question, If you need to you can reply to the prior post and that would alert the support staff if you feel the time has been long between posts or is still not resolved.

    Please let me know if I may be of further assistance.

    Comment


      #3
      Originally posted by FCatan View Post
      Hi ... Zacahry assisted me awhile back on a section of code that selects the most current instrument form the Default instrument list. The code is as follows:

      NinjaTrader.Cbi.InstrumentList list = NinjaTrader.Cbi.InstrumentList.GetObject("Default" );
      bool contractFound = false;
      List<string> selectedInstruments = new List<string>();
      foreach (Instrument myInstrument in list.Instruments)
      {
      if (myInstrument.FullName.Contains(defaultInst)) {selectedInstruments.Add(myInstrument.FullName); contractFound = true;}
      }

      if (contractFound)
      {
      selectedInstruments.Sort();
      selectedInstruments.Reverse();
      selected_contract = selectedInstruments[0];
      }
      else
      {
      selected_contract = "";
      runProgram = false;
      }

      This works find except when I have a contract that is for a prior year but a greater month. For example if I have the current ES contract "ES 09-15" as well as an older contract, "ES 12-14", the selectedInstruments.Sort(); selectedInstruments.Reverse(); lines will sort the "ES 12-14" first. But I want "ES 09-15". The issue being how the order of the text puts the month before the year. How do I sort first but year, then by month while keeping the text format in tact?

      thanks!
      ref: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

      Comment


        #4
        sorry about that ... not sure how reposting to an old thread works ... will wait for response on the other thread

        Comment


          #5
          Hello,

          You can just reply to your own post in the other thread just as you have replied to this thread, that would update the ticket.

          Please let me know if I may be of further assistance.

          Comment

          Latest Posts

          Collapse

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