Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CumProfit is lagging behind due to open trades

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

    CumProfit is lagging behind due to open trades

    Hi there,
    I’m trying to use the cumulative profit of an strategy for calculating the position size. However, I’ve noticed that the Performance.AllTrades.TradesPerformance.Currency.C umProfit variable is lagging behind (with two trades) the closed trades in a backtest (see screenshot, I couldn't upload the Excel file). That’s weird in my opinion, because the CumProfit should be updated after each trade, and thus should not be lagging behind, if I understand CumProfit correctly?

    I searched this forum, and found various topics on CumProfit, including an sample, yet all of them used Performance.AllTrades.TradesPerformance.Currency.C umProfit, which in my case gives wrong values, which suggest that I’m doing something terribly wrong.

    So, how can I use CumProfit in a way that is usable and true to the real strategy results during backtesting? I tried checking with Print() for open positions at the time of closing an trade (there were), and thus tried Position.GetProfitLoss(Close[0], PerformanceUnit.Currency), which still lags (though now one trade), and also gives wrong values.

    I’ve tried changing my simple crossover strategy (see attachment), so that there weren’t any short trades entered on the same bar an long was exited; this didn’t help. I also included the condition “if (Performance.AllTrades.Count > 1)” to remove the lagging; this worked, however, for the last trades this doesn’t give any values, so that is also not an solution.

    How can I use the correct cumulative profit in an backtest strategy? Any ideas are highly appreciated,

    Regards,
    Attached Files

    #2
    J_o_s, can you please upload a version of the script that would compile for testing here? You would see a lag of one bar update I believe, have you tried accessing it after the Position Update was in?

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      J_o_s, can you please upload a version of the script that would compile for testing here? You would see a lag of one bar update I believe, have you tried accessing it after the Position Update was in?
      Thanks for your quick reply Bertrand. Thanks for the tip regarding the overloading of OnPositionUpdate(), I didn't realize this method existed. With the use of OnPositionUpdate() my problem is solved.

      Thanks for your help!

      Btw, for other users, the following code solved the 'cumprofit lagging behind'-problem:
      Code:
      protected override void OnPositionUpdate(IPosition position)
              {
                  if (position.MarketPosition == MarketPosition.Flat && BarsSinceExit() == 0)
                  {
                      Print(Time[0] + ". CumProfit: " + Performance.AllTrades.TradesPerformance.Currency.CumProfit);
                  }
              }
      Regards,

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X