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

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.
    JesseNinjaTrader Customer Service

    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.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by JonesJoker, 04-22-2024, 12:23 PM
          8 responses
          41 views
          0 likes
          Last Post JonesJoker  
          Started by timko, Today, 06:45 AM
          0 responses
          3 views
          0 likes
          Last Post timko
          by timko
           
          Started by Waxavi, 04-19-2024, 02:10 AM
          2 responses
          39 views
          0 likes
          Last Post poeds
          by poeds
           
          Started by chbruno, Yesterday, 04:10 PM
          1 response
          44 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Max238, Today, 01:28 AM
          1 response
          25 views
          0 likes
          Last Post CactusMan  
          Working...
          X