Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sample P&L Error?

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

    Sample P&L Error?

    I am attempting to use logic built into your SampleP&L strategy but it doesn't appear to be working properly. I printed "Performance.AllTrades.TradesPerformance.Currency. CumProfit and "priorTradesCumProfit" to the output window and those values never differ.

    I have tried adjusting the start and end session times without any luck. Possibly I do not understand how this logic should be properly set up

    Please advise, thank you

    #2
    titleistbb22, I'm not sure what you expect, but accessing those stats will give you the combined performance of the strategy from the start of the chart to the point where you've started it up, this includes All trades, so the historical and later also the realtime trades portion of trades done.

    Comment


      #3
      Thanks - I am expecting the code to do as described in the following, specifically the locking in profits and cutting losses portion.

      http://www.ninjatrader.com/support/forum/showthread.php?t=4084

      In looking at the code if "Performance.AllTrades.TradesPerformance.Currency. CumProfit" always equals "priorTradesCumProfit" which it did when I printed these results to the output window how would this ever work to lock in profits and limit losses? Unless there is a specific way I should be setting up the chart to look at historical data or this code works only for real-time data on a go forward basis? Thank you


      protected override void OnBarUpdate()
      {
      // At the start of a new session
      if (Bars.FirstBarOfSession)
      {
      // Store the strategy's prior cumulated realized profit and number of trades
      priorTradesCount = Performance.AllTrades.Count;
      priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit;


      /* NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
      If you want to only count profits from real-time trades please use .RealtimeTrades. */
      }


      /* Prevents further trading if the current session's realized profit exceeds $1000 or if realized losses exceed $400.
      Also prevent trading if 10 trades have already been made in this session. */

      if (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit >= 1000
      || Performance.AllTrades.TradesPerformance.Currency.C umProfit - priorTradesCumProfit <= -400
      || Performance.AllTrades.Count - priorTradesCount > 10)
      {

      /* TIP FOR EXPERIENCED CODERS: This only prevents trade logic in the context of the OnBarUpdate() method. If you are utilizing
      other methods like OnOrderUpdate() or OnMarketData() you will need to insert this code segment there as well. */

      // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.

      return;
      }

      Comment


        #4
        It would work on a per session basis, storing the profit until the reset point to run comparisons then with the total profit later to determine when to return out of the OnBarUpdate() to not place anymore trades. Have you tested the sample strategy applied to a chart? Works for me as expected here.

        Comment


          #5
          Yes ran it on 5min chart, AUDNZD. I attached the strategy with the print alterations to the code. I am not sure how to attach/include the output window and the results attachment was too large, but there is no variance between the "current profit" or "prior profit"

          Please let me know how you tested and validated that this feature works

          Thank you
          Attached Files
          Last edited by titleistbb22; 07-27-2010, 04:50 AM.

          Comment


            #6
            Please add the prints in the section where it would return out of the strategies OnBarUpdate() method, it can return out if

            a) profits are higher than 1000
            b) losses are higher than 400
            c) or trades done for the session higher than 10

            Code:
             
            if (Performance.AllTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit >= 1000
            || Performance.AllTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit <= -400
            || Performance.AllTrades.Count - priorTradesCount > 10)
            {
            /* TIP FOR EXPERIENCED CODERS: This only prevents trade logic in the context of the OnBarUpdate() method. If you are utilizing
            other methods like OnOrderUpdate() or OnMarketData() you will need to insert this code segment there as well. */
            
            // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
            Print("Prior Profit " + " " + priorTradesCumProfit.ToString());
            Print("Current Profit " + " " + Performance.AllTrades.TradesPerformance.Currency.CumProfit.ToString());
            Print("Prior Trades " + " " + priorTradesCount.ToString());
            Print("Current Trades " + " " + Performance.AllTrades.Count.ToString());
            return;
            }

            Comment


              #7
              Thank you - this works. I tried it on 1440min charts (daily in Ninja 6.5) and it did not work even when I flipped update on bar close to false.

              Do the performance measures not update on each incomming tick? Do they need a close bar to calculate?

              Thank you

              Comment


                #8
                titleistbb22, the Performance class collection will update after the trade is completed, just as you would see for example when reviewing performance manually from the stratregies tab.

                Comment

                Latest Posts

                Collapse

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