Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unrealized profit on the latest trade

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

    Unrealized profit on the latest trade

    I want to identify the unrealized profit on an individual trade which happens to be the most recent trade. My understanding is that Position.UnrealizedProfit calculates that on all outstanding trades in an account..

    #2
    Hello galsermil,

    Thanks for your post.

    Position.GetUnrealizedProfitLoss would return the Unrealized PnL of that particular strategy. This would return the PnL for the current open strategy position, which could be any number of entries into a direction.

    See this help guide page for more information about Position.GetUnrealizedProfitLoss: https://ninjatrader.com/support/help...profitloss.htm

    AccountPosition.GetUnrealizedProfitLoss would return the Unrealized PnL of the entire Account.

    See this help guide page for more information about PositionAccount.GetUnrealizedProfitLoss: https://ninjatrader.com/support/help...profitloss.htm

    A trade would be a pair of Entry/Exit orders. To get the Profit/Loss of the last trade, you would need to use the TradeCollection to get the last trade. You could then access a TradePerformance value for that last trade.

    See this help guide page for more information about TradeCollection: https://ninjatrader.com/support/help...collection.htm

    See this help guide page for more information about TradePerformance values: https://ninjatrader.com/support/help...erformance.htm

    And, see this help guide page also: https://ninjatrader.com/support/help...ancevalues.htm

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Brandon, your explanation is the clearest that I have been given and I appreciate it. The one thing that I am not clear on is how deep do to go in trying to produce the information that you want. What I mean by that is that System Performance seems to precede Trade Collection which precedes Trade Performance which precedes Trade Values and the objects farther up the chain seem to be general enough to accommodate enquiry at several levels. How do you know how deep to go?

      Comment


        #4
        Hello galsermil,

        Thanks for your note.

        To get the last Trade that was made, see the Example 1 sample code on the TradeCollection help guide page linked in post #2.

        This sample code demonstrates how to get the last trade from the TradeCollection and how to print out a value from that last Trade.

        Also, see this help guide page https://ninjatrader.com/support/help.../nt8/trade.htm

        Let us know if we may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Trade lastTrade Brandon, I've never seen anything declared as a trade.

          Comment


            #6
            Hello galsermil,

            Thanks for your note.

            A trade is considered to be a pair of entry and exit orders.

            To get the last trade from the TradeCollection, the sample code would look something like this.

            Code:
            if (SystemPerformance.AllTrades.Count > 1)
              {
                  Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
            
                  Print("The last trade profit is " + lastTrade.ProfitPercent);
              }
            If you do not see a print occur for the last trade, you would need to take debugging steps to determine how your script is behaving

            Below is a link to a forum post that demonstrates how to use prints to understand behavior.
            https://ninjatrader.com/support/foru...121#post791121

            Let me know if I may assist further.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Brandon,

              Since what I am trying to do is calc the unrealized profit to compare to my target to determine whether an exit is appropriate. I cannot use a simple SetTarget as I must change a bool to false from true at the same time. In my strategy, I have four possible trade entries, long and short first trade and long and short second trade. I can't take a second trade unless the first is still open therefore when I calc unrealized profit for the second trade I need a way to isolate the second trade from the first. When taking the first trade, I use <Position> and it does not matter that it considers the whole account as there is only one position open but I don't have the same luxury with the second trade entry. The only possibility that I see is to assign the first unrealized profit to a variable and the subtract it from the second calc of unrealized profit but that seems to be a vary awkward step. Do you have any better ideas?

              Comment


                #8
                Hello galsermil,

                Thanks for your note.

                If you would like the Unrealized PnL of a single entry order, you would need to calculate this value yourself.

                Something you could consider is to calculate that value by using either the Close price at the time of the entry or the entry's average price, then calculate that value from the current Close price.

                Let me know if I may assist further.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  Brandon-

                  Quick question on the Position.GetUnrealizedProfitLoss.

                  I have a strategy that I run on ES, NQ, CL. The same strategy.

                  If I have open positions in 2 different futures, will the Position.GetUnrealizedProfitLoss get the unrealized for both futures on each one individually or add them together?

                  For simplicity's sake, lets say I want a profit target of $300 for each trade. If I am up $200 on ES and $100 on NQ will the strategy sell?

                  I want each future to run the same strategy individually if that makes sense.

                  Thank you,

                  Nick

                  Comment


                    #10
                    Hello Nick,

                    When adding multiple instruments with AddDataSeries(), this will make a position for each instrument in the Positions collection. These positions will be separate.


                    This means the Positions[barsArrayIndex].GetUnrealizedProfitLoss() for one instrument will be different than the position for a different instrument.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    55 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    132 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    73 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    49 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X