Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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?
    BertrandNinjaTrader Customer Service

    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 adaisguy, Today, 10:27 PM
      0 responses
      5 views
      0 likes
      Last Post adaisguy  
      Started by Jltarrau, Today, 10:18 PM
      0 responses
      4 views
      0 likes
      Last Post Jltarrau  
      Started by Option Whisperer, Yesterday, 09:55 AM
      4 responses
      30 views
      0 likes
      Last Post bltdavid  
      Started by Philippe56140, Yesterday, 02:35 PM
      2 responses
      21 views
      0 likes
      Last Post bltdavid  
      Started by AaronKTradingForum, Today, 02:37 PM
      3 responses
      33 views
      0 likes
      Last Post bltdavid  
      Working...
      X