Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

P&L of previous trade

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

    P&L of previous trade

    Trying to test a money management system out....

    say I have 10 trades...when I try and print the last trade using

    Code:
    Print (Performance.RealtimeTrades[0].ToString());

    it prints the very first trade I made, not the last trade made...

    any ideas?
    Last edited by BigDog008; 08-05-2009, 02:07 AM.

    #2
    BigDog008, please check example 1 from this link for the indexing used - http://www.ninjatrader-support.com/H...tionClass.html

    Comment


      #3
      Thanks Bertrand....

      I'm assuming then what's posted here was a typo? .... if not a typo, confusing... it says Get the last completed real-time trade, then it says at index 0...





      Code:
      protected override void OnBarUpdate() 
      { 
          // Check to make sure there is at least one trade in the collection 
          if (Performance.RealtimeTrades.Count > 0) 
          { 
              // Get the last completed real-time trade (at index 0) 
              Trade lastTrade = Performance.RealtimeTrades[0]; 
       
              // Calculate the PnL for the last completed real-time trade 
              double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity; 
       
              // Pring the PnL to the Output window 
              Print("The last trade's profit is " + lastProfit); 
          } 
      }

      Comment


        #4
        Hi there, which entry contains the typo? I checked the link Bertrand sent you and didn't see it. Anyways, the performance arrays are actually reverse indexed (most recent is largest value, first is at index 0).

        The general idea to get the most recent trade's profit:
        Code:
        if (Performance.RealtimeTrades.Count > 0)
        {
            Trade mostRecentTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
            if (mostRecentTrade != null)
            {
                double profit = mostRecentTrade.ProfitCurrency;
            }
        }
        That code hasn't been tested, but it should show the general idea. I actually created a reference sample that I pulled this code from. There are many more comments in the code sample located here.

        Let us know if you have any other questions.
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X