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

DataSeries tracking PnL

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

    DataSeries tracking PnL

    I’m trying to use DataSeries to track intraday PnL on an hourly basis.

    I’m using a data series like so:

    Code:
                        if (Performance.AllTrades.Count != tradeCount)
                        {
                            tradeCount = Performance.AllTrades.Count;
    
                            foreach (Trade x in Performance.AllTrades)
                            {
                                if (x.Exit.Time.Date.CompareTo(Time[0].Date) == 0)
                                {
                                    dayPnL += x.ProfitCurrency;
    
                                }
    
                            }
    
                        }
    
                        int y = 0;
                        dayPnL = 0;
    
                        foreach (Position x in Positions)
                        {
    
                            dayPnL += x.GetProfitLoss(Closes[y][0], PerformanceUnit.Currency);
    
                            y++;
    
                        }
    
                        intraDayPnL.Set(dayPnL);
                        intraDayPnLList.Add(dayPnL);
    However, when using printing these values in OnTerminate I get 0 as the max and min (see below)

    Code:
                    double test = MAX(intraDayPnL, 200)[0];
    
                    double max = double.MinValue;
                    double min = double.MaxValue;
    
                    foreach (object item in intraDayPnLList) {
    
                        if (item is double)
                        {
                            if ((double)item > max) {
                                max = (double)item;
                            }
    
                            if ((double)item < min)
                            {
                                min = (double)item;
    
                            }
                        }
    
                    }
    
    
                    Print("The highest intra-day PnL is " + MAX(intraDayPnL, (intraDayPnL.Count - 1))[0]);
                    Print("The lowest intra-day PnL is " + MIN(intraDayPnL, (intraDayPnL.Count - 1))[0]);
    
                    Print("Highest list value " + max);
                    Print("Highest list value " + min);
    Yet, when using the list I created I get different values?

    Could you please help?

    #2
    Hello systemtrader10,

    Thank you for your post.

    I am investigating this further on my end and I will follow up with you shortly.

    Comment


      #3
      Hello systemtrader10,

      Thank you for your patience.

      I cannot recreate this on my end. The Output I am seeing when OnTermination() is called contains a value. However, if you could provide a simplified version of your script that we may test on our end to isolate this matter it would be most helpful.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by elirion, Today, 09:32 PM
      0 responses
      2 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by cre8able, Today, 09:15 PM
      1 response
      5 views
      0 likes
      Last Post bltdavid  
      Started by cummish, Today, 08:43 PM
      0 responses
      9 views
      0 likes
      Last Post cummish
      by cummish
       
      Started by Option Whisperer, Today, 07:58 PM
      4 responses
      19 views
      0 likes
      Last Post Option Whisperer  
      Started by ETFVoyageur, 05-07-2024, 07:05 PM
      13 responses
      87 views
      0 likes
      Last Post ETFVoyageur  
      Working...
      X