Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Learning how to debug

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

    Learning how to debug

    the code below is inside onBarUpdate():.
    Why AllTrades (without //) prints the "P" when cumulative profit is negative, but RealtimeTrades (in red) do not print "P" when current trade is presenting a loss?
    What RealtimeTrades performance shows? Is the P&L of open positions (real time)?
    How can I print "something" when a position is losing money?


    if (ToTime(Time[0]) >= beginOpenTrading && ToTime(Time[0]) <= stopOpenTrading)
    {
    //if (Performance.AllTrades.TradesPerformance.Currency. CumProfit < 0)
    if (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit < 0)
    {
    DrawText(CurrentBar+"1","P",0,High[0],Color.Blue);
    }

    Another question would be, How can I print inside OnBarUpdate()?
    Something like: Print("Average MAE of all trades is: " +
    Performance.AllTrades.TradesPerformance.Currency.
    AvgMae);

    I use it inside OnBarUpdate but nothing happen..
    Last edited by dafonseca; 03-15-2013, 08:53 PM.

    #2
    To get the unrealized PnL you could use
    Position.GetProfitLoss(double marketPrice, PerformanceUnit performanceUnit)


    Your example will not display the result after the live trade has closed out as a loss but not before.

    If you're using: Print("Average MAE of all trades is: " + Performance.AllTrades.TradesPerformance.Currency.A vgMae);

    and not getting anything to print there must be some logic that's preventing it from not being hit. Try putting this at the start of your OnBarUpdate() and testing again.
    LanceNinjaTrader Customer Service

    Comment


      #3
      So, in OnExecution tra+Profitloss_Current (below) will get the P&L of the position just before it is closed?


      protected override void OnExecution(IExecution execution)
      {
      trade_ProfitLoss_Current =Position.GetProfitLoss(Close[0],PerformanceUnit.Currency);
      if (trade_ProfitLoss_Current < 0)
      {
      timeToLoss = ToTime(Time[0]);
      }
      }

      Comment


        #4
        debuging

        If I code this.. Would I check AvgProfit on strategy analyzer-> backtesting->chart.
        where would it be printed??


        protected override void OnBarUpdate()
        {
        Print("Average profit of all trades is:" Performance.AllTrades.TradesPerformance.Currency.A vgProfit);

        Comment


          #5
          If I code this.. Would I check AvgProfit on strategy analyzer-> backtesting->chart.
          where would it be printed??


          protected override void OnBarUpdate()
          {
          Print("Average profit of all trades is:" Performance.AllTrades.TradesPerformance.Currency.A vgProfit);
          This will be printed to the Output window (Control center -> tools -> output window)


          Originally posted by dafonseca View Post
          So, in OnExecution tra+Profitloss_Current (below) will get the P&L of the position just before it is closed?

          protected override void OnExecution(IExecution execution)
          {
          trade_ProfitLoss_Current =Position.GetProfitLoss(Close[0],PerformanceUnit.Currency);
          if (trade_ProfitLoss_Current < 0)
          {
          timeToLoss = ToTime(Time[0]);
          }
          }
          My initial thought is that this is correct but you would want to test it with a Print() statement.

          That being said you could get the full profit from an individual recent trade using TradesPerformance and subtracting the CumProfit - the Prior trades cum profit

          An example to help get you started with this can be found here: http://www.ninjatrader.com/support/f...ead.php?t=4084
          LanceNinjaTrader Customer Service

          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