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!
Comment