Working with the collection would just require using any C# means to find the element you want. That won't be specific to NinjaScript so you can find examples of selecting elements from a KeyValuePair in external C# resources. I would suggest searching online for "C# KeyValuePair linq examples" or "C# linq" to have a more firm understanding of working with this type of collection or selecting elements.
One method you may be able to use here is the LastOrDefault:
KeyValuePair<string, IEnumerable<AlertEventArgs>> alert = NinjaTrader.NinjaScript.Alert.AlertHistory.LastOrDefault();
Another approach is to keep using the loop and put that in a method, that would be if you need to call this in multiple areas. The loop is really not going to be that bad unless you are doing a lot of work inside the loop and there are many alerts. If you are just looping to select the last item that won't really hurt performance as you are not doing any work in the loop.
I look forward to being of further assistance.
Comment