Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Formula - Position.GetProfitLoss(Close[0], PerformanceUnit.Percent)

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

    Formula - Position.GetProfitLoss(Close[0], PerformanceUnit.Percent)

    NT Support,

    Could you please help me?

    I am currently working with a strategy that uses Position.GetProfitLoss(Close[0], PerformanceUnit.Percent) during execution. That is, manage positions differently when they are given percentage in profit / loss.

    However, I am trying to reverse the formula that provides me with a projected price – for example, I would like to calculate price if the Position is 0.50% up.

    Could you please provide the formula that does that calculation? Or point me towards where it is at in the documentation?

    Thanks and regards,

    Dan

    #2
    Hello,

    I suggest storing the entry price of your position in a variable and manually check the % gain. This link will help with doing things based on performance data:
    DenNinjaTrader Customer Service

    Comment


      #3
      Ben,

      Thank you very much for your prompt response. And your pointer to the sample code.

      I have looked at the sample code. However, that doesn’t really answer the question. The sample code is focused on taking a view across a number of positions, doesn’t deal with a single position. Nor does it look at percentage return of the position, which is better used across a number of currency crosses.

      Could you please help me understand why are you suggesting to calculate the percentage manually in the code? The functionality exists inbuilt into NT, does it not? And can I not just be given the formula for the calculation?

      Thanks and regards,

      Dan

      Comment


        #4
        Dan, what Ben likely referred to is using Position.AvgPrice and then adding your percent offset to it to arrive at the projected price -

        Comment


          #5
          Bertrand,

          Thanks very much for that.

          I’m aware of the AvgPrice functionality. I was trying use the inbuilt functionality of NT for 3 reasons. Firstly, it avoids coding it by hand. Secondly, the information aligns with the performance reports in the Strategy Analyser (e.g. MAE). Thirdly, we’ve developed other code which uses Stridsman’s trade lifecycle analysis (to perform analysis on a bar by bar bases (http://www.amazon.com/gp/product/007...pf_rd_i=507846). We would like the strategy to manage positions based on information that aligns with this as well.

          Are you saying that we are unable to use the inbuilt functionality as referred to below?

          Thanks and regards,

          Dan

          Comment


            #6
            Dan, you're welcome but I'm not sure I fully follow here - the GetPnL formula you're using will give you the unrealized Pnl in %.

            Your formula for the projected price need to be custom coded as it's not available per default. You could add a percentage offset to the Position.AvgPrice (your entry) to have this as projected price level value then.

            Comment


              #7
              Bertrand,

              Thank you again for your response.

              Yes, I understand that Position.GetProfitLoss(Close[0], PerformanceUnit.Percent) will give me the unrealised %. We would like the formula that this method implements, i.e. what is the actual implementation of x/y which provides the unrealised value of 0.5, for example. How is it calculated? The help file refers to “Percent based calculations are per traded unit” (see help file TradesPerformanceValues Class).

              I understand that I can manually calculate a percentage projection, however we are trying to use the inbuilt functionality as we use it many places, not least when analysing strategy performance.

              Thanks and regards,

              Dan

              Comment


                #8
                Dan, unfortunately we can't publish the source code of this method. It's just basic math behind it, lets consider the following example.

                A long entry in today's ES at 1078 exited at 1082, 4 pts higher. With a master instrument pointvalue of 50 (4 ticks ES) the currency value of this trade would be 200$.

                If you divide then points made by the Position.AvgPrice, you would arrive at a percentage value for this trade of 0.37%

                Comment


                  #9
                  Bertrand,

                  Thank you very much for your reply.

                  So I make the formula from our example (using Forex):

                  Pips (+made / -loss) / Average Entry price

                  I’m a little confused by your comment below of $200. I think you are trying to make the point that the pip value is different for different instruments. That is, the Master Instrument point value is defined in the Instrument Manager (see screen shot). Is that correct?

                  Thanks and regards,

                  Dan
                  Attached Files

                  Comment


                    #10
                    Bertrand,

                    Further to the post below, when the strategy is executing the final element of the execution of the formula to implement this calculation as a true percentage (i.e. our formula below Pips (+made / -loss) / Average Entry price * 100/1) is not done during execution. When using Visual Studio to inspect the variables on the fly in debug mode that’s what I’m seeing.

                    Can you please confirm?

                    Thanks and regards,

                    Dan

                    Comment


                      #11
                      Correct Dan, just to illustrate different point values can come into play - sorry I'm not sure which exact values you're comparing / debugging in VS, please clarify - thanks.

                      Comment


                        #12
                        Bertrand,

                        Thanks for the reply.

                        When using VS to inspect the variables during execution, the conversation into a percentage is not happening. It is leaving the value as a raw decimal (i.e. double in .Net). Therefore, the number is transposed two decimal places to the right.

                        For example, if the position is 0.70% up, during execution if the GetProfitLoss function is run, it will report as 0.007 up. The line of code is below that I’m using to inspect the function results.


                        Code:
                        double temp_return = Position.GetProfitLoss(Close[1], PerformanceUnit.Percent);
                        Kind regards,

                        Dan

                        Comment


                          #13
                          Dan, seeing the same here - just multiply by 100 and it should be in line with what you expect. Will check into with development if there's more to it, thanks.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          647 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
                          573 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X