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 sjsj2732, 03-23-2026, 04:31 AM
          0 responses
          49 views
          0 likes
          Last Post sjsj2732  
          Started by NullPointStrategies, 03-13-2026, 05:17 AM
          0 responses
          300 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          294 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          139 views
          1 like
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          98 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Working...
          X