Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetProfitLoss

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

    GetProfitLoss

    I am using the example found at:



    I am testing the function GetProfitLoss. The number reported makes sense to me for 1 contract. But if I add another contract, the number doesn't make sense. How do I get the function to work with position sizing?

    #2
    Hello,

    Can you please give me a snippet of the code you are using to call GetProfitLoss(), and describe exactly what kind of discrepancy you are seeing? Are you seeing PnL for only one contract when you are in a larger position?
    Dave I.NinjaTrader Product Management

    Comment


      #3
      I am entering at 2 different prices for a total of 2 contracts. This seems to work for the first contract but after the second contract is entered, the unrealized doesn't makes sense:

      Code:
      DrawTextFixed("UnPNL", string.Format("Unrealized: {0}", 
      	Math.Round(Position.GetProfitLoss(Close[0], PerformanceUnit.Points), 2)), 
      	TextPosition.TopRight, Color.Green, new Font("Arial",16), Color.Blue, Color.DarkGray, 10);

      Comment


        #4
        Thank you -- I should have also asked for a snippet showing your order entry logic. Would you mind sharing that, so I can make sure I'm doing entries exactly the same way that you are?
        Dave I.NinjaTrader Product Management

        Comment


          #5
          Sure, I can do that - i'll have to get it together -- let me first ask, do I have to iterate through trades/positions? I looked into it but couldn't get it.

          Comment


            #6
            I do not believe so -- GetProfitLoss() should be return a value based upon all open positions and all contracts.
            Dave I.NinjaTrader Product Management

            Comment


              #7
              How do I access the Unrealized number on the Strategies tab?

              Comment


                #8
                Hello,

                Thank you for the question.

                There is not a supported way to access specifically that field in the control center.

                I can provide a forum post with a script example on how to calculate the Unrealized PnL for an order. http://ninjatrader.com/support/forum...1&postcount=19

                In this example, in the OnBarUpdate there are a few Prints that show how to calculate the Unrealized PnL for given orders.

                I look forward to being of further assistance.

                Comment


                  #9
                  Thanks for the link. Yes, I'll probably end up doing something similar, calculating it manually.

                  Comment

                  Latest Posts

                  Collapse

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