Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print PnL

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

    Print PnL

    Hi guys

    How do I print the realized PnL of each trade, at trade close.
    when the trade close and prints on the chart, I want it to also display how much that trade has made in Profit or Loss in dollar currency like ($100 or -$100)
    I don't want the total PnL, only the PnL made by each trade
    is that possible? how?

    #2
    Hello onlinebusiness,

    Thanks for your post.

    You get the last trade that was made from the TradeCollection and access information about that last trade.

    The TradesPerformance collection could then be used to access TradePerformanceValues in currency, such the PnL, of the last trade that was made.

    See the sample code on help guide page for information about how to get the last trade from the TradeCollection: https://ninjatrader.com/support/help...collection.htm

    See this help guide page for information about accessing the TradePerformanceValues of a trade in currency: https://ninjatrader.com/support/help...ancevalues.htm

    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


      #3
      Thanks for the reply Brandon.

      so I thook this code

      Code:
        // Accesses the first/last trade in the strategy (oldest trade is at index 0)
        // and prints out the profit as a percentage to the output window
        if (SystemPerformance.AllTrades.Count > 1)
        {
            Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
            Trade firstTrade = SystemPerformance.AllTrades[0];
      
            Print("The last trade profit is " + lastTrade.ProfitPercent);
            Print("The first trade profit is " + firstTrade.ProfitPercent);
        }
      }​
      I tried using it as it under my protected override void OnBarUpdate() but it didn't display anything on chart

      is there something else I need to add? excuse my ignorance i'm still learning how to code strategies.
      I am guessing I need to add some of the code after my ExitLong and ExitShort, but I might be wrong

      What I want is that after each trade Exit, the PnL of that trade in currency get printed on chart,
      Could you be kind enough to provide a sample example of how to do this?

      Thanks

      Comment


        #4
        Hello onlinebusiness,

        Thanks for your note.

        Prints will not display on a chart window. Prints will only display in a New > NinjaScript Output window.

        If you want values to display on a chart, Draw.Text() would need to be used to draw the value onto the chart window.

        See this help guide page for information about Draw.Text() and sample code: https://ninjatrader.com/support/help.../draw_text.htm

        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

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        62 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        134 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 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
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X