Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difference PnL versus Position.GetProfitLoss(Close[0], PerformanceUnit.Points);

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

    Difference PnL versus Position.GetProfitLoss(Close[0], PerformanceUnit.Points);

    Hello,

    Why PnLEnCours = Position.GetProfitLoss(Close[0], PerformanceUnit.Points);

    give a different result thant PnL (in point) display in the window Positions / PnL

    Thanks

    #2
    Hello Pcomm69,
    Position.GetProfitLoss will calculate the PnL for the strategy only while the positions tab will calculate the PnL for that instrument. For example if your strategy had placed one trade and you have manually placed another trade, then the Position.GetProfitLoss will show the PnL for the strategy only while the Positions tab will show the aggregate PnL.

    Can you confirm there is only one running trade.

    I look forward to assisting you further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      YES I confirm :
      - No Manual order
      - One personnal Strategy
      - in one instrument (FDax 06-12)
      - one autamated position (by this strategy)

      I have difference between
      PnLEnCours = Position.GetProfitLoss(Close[0], PerformanceUnit.Points);

      versus

      the window Positions / PnL

      Comment


        #4
        Hello,
        Unfortunately I could not replicate the issue.

        Can you further tell me who your connectivity provider is?

        Also can you tell the exacts steps to reproduce this or any screenshot.

        I look forward to assisting you further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          NinjaTrader

          So i Try to reinstall and recompile

          Last Question :
          in the same Instrument how can my Strategy know if she is already in position UP or in position Down, in live during the position

          (for not take a contre order)
          Last edited by Pcomm69; 05-11-2012, 08:14 AM.

          Comment


            #6
            Hello Pcomm69,
            You can use the MarketPosition property to know the current position.

            Code:
            if (Position.MarketPosition == MarketPosition.Long)
            {
                //do something
            }
            else if (Position.MarketPosition == MarketPosition.Short)
            {
                 //do something
            }


            However the above code will tell you the Market Position for the current strategy only and not for the entire instrument (if you have multiple strategy for the same instruments). However it is possible to find out this using unsupported NinjaScript methods (as a hint you can look into Account.Positions property).

            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Ok I have a peace of solution

              on NO position (window Position/PNL are Empty)
              *Position.MarketPosition
              and
              * Position.GetProfitLoss(Close[0], PerformanceUnit.Points);

              give me both the LAST position
              while the strategy have closed the last position few minutes ago

              *Position.MarketPosition
              and
              * Position.GetProfitLoss(Close[0], PerformanceUnit.Points);
              are not Reset by ExitLong or ExitShort

              Comment


                #8
                Hello Pcomm69,
                Position.GetProfitLoss will return the unrealized PnL of the strategy position.

                If your strategy is flat then it will return 0 (zero). If your strategy is Long or Short then it will return the unrealized PnL.


                If you are getting any other result then please upload a NinjaScript code replicating it.

                I look forward to assisting you further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  YES I Confirm

                  when my strategy is flat
                  Position.GetProfitLoss(Close[0], PerformanceUnit.Points); (or Currency idem)
                  will return something different of 0

                  it is a problem of initialisation

                  what do you mean by
                  "please upload a NinjaScript code replicating it."
                  sorry I don t understand

                  Comment


                    #10
                    Hello Pcoomm69,
                    When I tested it using the below code
                    Code:
                    Print(Position.GetProfitLoss(Close[0], PerformanceUnit.Points));
                    It is returning 0 (zero) when the strategy is flat, and the correct PnL when I am in a position.

                    Can you send a sample code to support[AT]ninjatrader[DOT]com replicating the error you are getting. Please append Attn:Joydeep in the subject of the email and a give a reference of this thread in the body of the email.

                    I look forward to assisting you further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      oh yes thanks
                      I clean it this WE and post it to you next week
                      thanks

                      Comment


                        #12
                        Hello Pcomm69,
                        Thanks for your note.
                        I look forward to assisting you further.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Joydeep View Post
                          Hello Pcomm69,
                          Position.GetProfitLoss will return the unrealized PnL of the strategy position.

                          If your strategy is flat then it will return 0 (zero). If your strategy is Long or Short then it will return the unrealized PnL.


                          If you are getting any other result then please upload a NinjaScript code replicating it.

                          I look forward to assisting you further.
                          Hi NinjaTrader_Joydeep,

                          Isn't there any workaround to get the Profit/Loss AFTER a position is closed (realized PNL)?

                          I have made some thoughts regarding this issue:
                          Could you please advise me if this could work or in case what to change to get
                          the realized PNL AFTER a trade

                          ...
                          protected override void Initialize()
                          {
                          .
                          ...
                          posavgprice = Position.AvgPrice;
                          ...
                          }
                          ..
                          protected override void OnExecution(IExecution execution)
                          {


                          if (execution.Order != null && execution.Order.OrderState == OrderState.Filled && ExTime.Date >= currentDateTime.Date)

                          {

                          if (Position.MarketPosition == MarketPosition.Long) //Long position
                          {
                          if (execution.Price > posavgprice) // In case of profit
                          {
                          PNL_points = (execution.Price - posavgprice);
                          Print("PNL_points : " + PNL_points);
                          PNL_percent = (execution.Price / posavgprice - 1)*100;
                          Print("PNL_percent : " + PNL_percent);
                          PNL_currency = (execution.Price - posavgprice) * quantity * Instrument.MasterInstrument.PointValue;
                          Print("PNL_currency : " + PNL_currency);
                          }
                          else // Im Fall von Loss
                          {
                          PNL_points = (posavgprice - execution.Price);
                          Print("PNL_points : " + PNL_points);
                          PNL_percent = (1 - posavgprice / execution.Price)*100;
                          Print("PNL_percent : " + PNL_percent);
                          PNL_currency = (posavgprice - execution.Price) * quantity * Instrument.MasterInstrument.PointValue;
                          Print("PNL_currency : " + PNL_currency);
                          }
                          }

                          if (Position.MarketPosition == MarketPosition.Short) // Short Position
                          {
                          if (posavgprice > execution.Price) // In case of profit
                          {
                          PNL_points = (posavgprice - execution.Price);
                          Print("PNL_points : " + PNL_points);
                          PNL_percent = (1 - posavgprice / execution.Price);
                          Print("PNL_percent : " + PNL_percent);
                          PNL_currency = (posavgprice - execution.Price) * quantity * Instrument.MasterInstrument.PointValue;
                          Print("PNL_currency : " + PNL_currency);
                          }
                          else // In case of loss
                          {
                          PNL_points = (execution.Price - posavgprice);
                          Print("PNL_points : " + PNL_points);
                          PNL_percent = (execution.Price / posavgprice - 1);
                          Print("PNL_percent : " + PNL_percent);
                          PNL_currency = (execution.Price - posavgprice) * quantity * Instrument.MasterInstrument.PointValue;
                          Print("PNL_currency : " + PNL_currency);
                          }
                          }

                          }
                          }


                          Many thanks.

                          Rob

                          Comment


                            #14
                            Hello Robertp75,
                            Yes, you can get the realized PnL from the trade collections class.

                            Code:
                            foreach (Trade t in Performance.AllTrades)
                            {
                            	Print(t.ProfitPoints);
                            }
                            Please refer to our help guide to know more about it
                            JoydeepNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by argusthome, Yesterday, 10:06 AM
                            0 responses
                            22 views
                            0 likes
                            Last Post argusthome  
                            Started by NabilKhattabi, 03-06-2026, 11:18 AM
                            0 responses
                            19 views
                            0 likes
                            Last Post NabilKhattabi  
                            Started by Deep42, 03-06-2026, 12:28 AM
                            0 responses
                            14 views
                            0 likes
                            Last Post Deep42
                            by Deep42
                             
                            Started by TheRealMorford, 03-05-2026, 06:15 PM
                            0 responses
                            10 views
                            0 likes
                            Last Post TheRealMorford  
                            Started by Mindset, 02-28-2026, 06:16 AM
                            0 responses
                            41 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Working...
                            X