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 Ashkam, 04-29-2024, 09:28 AM
          3 responses
          28 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by i2ogu3, Yesterday, 11:31 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by NinjaTrader_ChelseaB, 03-14-2017, 10:17 AM
          229 responses
          34,328 views
          7 likes
          Last Post rare312
          by rare312
           
          Started by Graci117, Yesterday, 11:40 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by nissan200sx55, Today, 06:25 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X