Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Alert Manager

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Hello oceanis400,

    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:

    Code:
    KeyValuePair<string, IEnumerable<AlertEventArgs>> alert = NinjaTrader.NinjaScript.Alert.AlertHistory.LastOrDefault();
    You could give this a try and see if that returns the correct alert, I have not tested this as I don't currently have any alerts set up.

    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

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X