• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error while getting access to trades statistics

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

    Error while getting access to trades statistics

    Hello,

    I am facing a problem when getting access to strategy performance (the issue happens not on all computers, however...).

    Here is my code:

    Code:
    DateTime currentDay = new DateTime(Time[0].Year,Time[0].Month,Time[0].Day);
    TradeCollection currentDayTrades = null;
    double netProfit = 0;
    try{
        currentDayTrades = (TradeCollection)SystemPerformance.AllTrades.ByDay[currentDay];
        netProfit = currentDayTrades.TradesPerformance.NetProfit;
    }
    catch(Exception ex){
        Print("Error in trades performance calculation: "+ex.ToString());
    }
    And this is the exception I receive even after a trade was executed and closed:

    Error in trades performance calculation:
    System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    at System.ThrowHelper.ThrowKeyNotFoundException()
    at System.Collections.Generic.Dictionary`2.get_Item(T Key key)
    From the chart drop-down menu I am able to access the strategy performance, but programmatically - not. Can you please advise me on how I can solve this issue?

    Best regards,
    Alexei

    #2
    Hello Alexei,

    Thank you for your post.

    From the provided information I would be unsure why the key would be not found other than the key may have some other value which is different from what you used. have you at this point tried to iterate the collection to see what keys it has when this occurs?

    If your exception is being met and moving to your catch, you could use that logically to print out the keys of the collection after the error to see what the actual keys were. This would give better insight into what's happening on that use case.

    Code:
    foreach (KeyValuePair<object, TradeCollection> entry in SystemPerformance.AllTrades.ByDay) 
    {
        if(entry.Key is DateTime)
        {
            DateTime key = (DateTime)entry.Key ;
            Print(key);
        }
    }



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Thank you, I have done as you have advised but it has appeared to be that the trades collection is empty even though there are trades opened and closed by the strategy. Is there anything I can try to debug this further?

      Best regards,
      Alexei

      Comment


        #4
        Hello akuntysh,

        Thank you for your reply.

        The collection being empty would explain why the key could not be found.

        Without more specific details on the use case, I wouldn't be sure why the collection would be empty when checked. Do you have a simple example script which demonstrates this along with the steps to see this?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by digibob, Yesterday, 10:01 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by ldissinger, Today, 12:55 PM
        1 response
        6 views
        0 likes
        Last Post ldissinger  
        Started by pstrusi, Today, 09:06 AM
        1 response
        18 views
        0 likes
        Last Post marcus2300  
        Started by vpzdcv, Today, 02:31 AM
        0 responses
        12 views
        0 likes
        Last Post vpzdcv
        by vpzdcv
         
        Started by YevhenShynkarenko, Today, 01:22 AM
        1 response
        21 views
        0 likes
        Last Post YevhenShynkarenko  
        Working...
        X