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 fernandobr, Today, 09:11 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by timmbbo, Today, 08:59 AM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by KennyK, 05-29-2017, 02:02 AM
          2 responses
          1,281 views
          0 likes
          Last Post marcus2300  
          Started by itrader46, Today, 09:04 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by bmartz, 03-12-2024, 06:12 AM
          5 responses
          33 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Working...
          X