Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cumulative Profit for a session

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

    Cumulative Profit for a session

    Hello,

    I would like to calculate Cumulative Profit per session and to compare it with a loss limit parameter.

    What is the best way to calculate Cumulative Profit per session?

    Thanks,

    Valentin

    #2
    Hello Valentin,

    The formula for Cumulative profit can be found in the NinjaTrader help guide statistics section which I am linking below.
    http://www.ninjatrader.com/support/h...efinitions.htm

    You would want to calculate this and store to a variable which would be reset on the start of a new session using Bars.FirstBarOfSession.
    http://www.ninjatrader.com/support/h...rofsession.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      The strategy will run with ExitOnClose = false and CalculateOnBarClose = false. As I understand, I will need to reset the variable to 0 at FirstBarOfSession and FirstTickOfBar, and then to add profit for each new trade. Is it correct?

      Thanks,

      Valentin

      Comment


        #4
        Hello Valentin,

        Your understanding is correct.

        If you want to reset on the first tick of the first session, this is fine to do. I didn't mention it because it is not likely a trade would enter and exit before the first bar closes, but it is a possibility.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          As I understand

          Code:
          Performance.AllTrades[ ... ].ProfitCurrency
          is calculated for one traded unit, but

          Code:
          Position.GetProfitLoss(Input[0], PerformanceUnit.Currency)
          is calculated for the whole position.

          So if I want unrealized PnL for for one traded unit, I have to divide

          Code:
          Position.GetProfitLoss(Input[0], PerformanceUnit.Currency) / Position.Quantity
          Is it correct?

          Thanks,

          Valentin

          Comment


            #6
            Hello Valyo,

            This is correct, however, this would not be reset for each new session. This would be cumulative for the entire time the strategy is running.

            If you want to calculate per session you would need to store this calculated information to a variable.


            (edit)
            Also, when you mention one traded unit first, I want to be clear this is one trade and not one contract. The second mention would be one contract.

            Performance.AllTrades[ ... ].ProfitCurrency -> one closed trade realized PnL
            Position.GetProfitLoss(Input[0], PerformanceUnit.Currency) / Position.Quantity -> one contract of position unrealized PnL
            Last edited by NinjaTrader_ChelseaB; 06-10-2015, 07:48 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              Here is what I read in NT Help:

              ProfitCurrency

              A double value representing profit in currency for one traded unit. Multiply this value by the trade Quantity to get the total profit in currency for the trade.
              And this is from the example in NT Help:

              // Calculate the PnL for the last completed real-time trade
              double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;
              So it says that

              Performance.AllTrades[ ... ].ProfitCurrency

              is for one traded unit and

              Performance.AllTrades[ ... ].ProfitCurrency * Performance.AllTrades[ ... ].Quantity

              is for the trade.

              Which one is correct?

              I store cumulative profit in a variable and reset that variable at each session start.

              But I would like to calculate the final profit as

              Cumulative Profit for the session + Unrealized PnL for the last position.

              I test the strategy and

              Position.GetProfitLoss(Input[0], PerformanceUnit.Currency) has very high values.

              Is Position.GetProfitLoss(Input[0], PerformanceUnit.Currency) cumulative for the entire time the strategy is running?

              How could I get unrealized PnL for the last open position only?

              Thanks,

              Valentin

              Comment


                #8
                Hi Valyo,

                You are correct about Performance.AllTrades[ ... ].ProfitCurrency that is only one unit.
                (I was still thinking of CumProfit, sorry about that)

                Position.GetProfitLoss() is for the open position. This includes all trades that are open but no trades that have been exited. This does not accumulate exited trades.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  OK, thank you. I understood why unrealized PnL is so high - I had to multiply price change by point value.

                  I have another question for this strategy - is it possible to flatten all on termination automatically?

                  I think about OnTermination() method - could I place ExitLong / ExitShort orders there?

                  Thanks,

                  Valentin

                  Comment


                    #10
                    Hi Valentin,

                    Yes, you can place exit orders in OnTermination to flatten on disable.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    574 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    332 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    553 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    551 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X