Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PnL Calculation Bug?

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

    PnL Calculation Bug?

    Im using NT8 B6, never tested this in the older versions.

    I think I found a bit of a PNL calculation bug. I can reproduce it, I created a basic strategy that enters 10k long on bar 25, and then 20k short on bar 50. Both have a set profit target of 50pips. When one of the profit targets is hit the PNL is way out.

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    //This namespace holds Strategies in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Strategies.PH
    {
     public class phStrat1 : Strategy
     {
      protected override void OnStateChange()
      {
       if (State == State.SetDefaults)
       {
        Description       = @"Go long at bar 50";
        Name        = "phStrat1";
        Calculate       = Calculate.OnBarClose;
        EntriesPerDirection     = 1;
        EntryHandling      = EntryHandling.AllEntries;
        IsExitOnSessionCloseStrategy  = false;
        ExitOnSessionCloseSeconds   = 30;
        IsFillLimitOnTouch     = false;
        MaximumBarsLookBack     = MaximumBarsLookBack.TwoHundredFiftySix;
        OrderFillResolution     = OrderFillResolution.Standard;
        Slippage       = 0;
        StartBehavior      = StartBehavior.WaitUntilFlat;
        TimeInForce       = TimeInForce.Gtc;
        TraceOrders       = false;
        RealtimeErrorHandling    = RealtimeErrorHandling.StopCancelClose;
        StopTargetHandling     = StopTargetHandling.PerEntryExecution;
        BarsRequiredToTrade     = 20;
        dir         = true;
       }
       else if (State == State.Configure)
       {
       }
      }
      protected override void OnBarUpdate()
      {
       //Add your custom strategy logic here.
       if(CurrentBar == 25 && dir == true){EnterLong(10000,"Long");}
       if(Position.MarketPosition==MarketPosition.Long)
       {
        SetProfitTarget("Long",CalculationMode.Pips,50);
       }
       if(CurrentBar == 50 && dir == false){EnterShort(20000,"Short");}
       if(Position.MarketPosition==MarketPosition.Short)
       {
        SetProfitTarget("Short",CalculationMode.Pips,50);
       }
      }
     
     #region Properties
     
      [NinjaScriptProperty]
      [Display(Name="Dir", Order=3, GroupName="Settings")]
      public bool dir
      { get; set; }
     
     #endregion
     
     }
    }
    Attached Files
    Last edited by happypappy; 10-28-2015, 06:00 PM.

    #2
    I did some further testing, split the strategy into to separate strategies with the same entries etc. The AVG price is wrong for starters. And the strategy positions compared to Position avg is out.
    Attached Files

    Comment


      #3
      Are your MAE/MFE and Entry/Exit/Total Efficiency charts all messed up? (identical)

      Comment


        #4
        Some times. I haven't done any live trading with B6 yet but B4 has some weird MAE results, I had a MAE near $12k appear once on a $200 trade....
        Last edited by happypappy; 10-29-2015, 03:23 AM.

        Comment


          #5
          I hope this gets some attention, a stock program with bad maths is not something people want, it looks like the maths used to determine position avg is not working properly.

          Comment


            #6
            Are you exciting trades on session close? There was a big submitted for that and i think supposed to be fixed in latest build.

            And there is a massive big in account performance report when running more than 2 strategies.

            Comment


              #7
              happypappy, can you please provide a sample strategy that is consistently producing an incorrect average position price? It is difficult to spot the issue without seeing exactly what the average price should be, compared to what is actually reported.
              Dave I.NinjaTrader Product Management

              Comment


                #8
                Originally posted by NinjaTrader_Dave View Post
                happypappy, can you please provide a sample strategy that is consistently producing an incorrect average position price? It is difficult to spot the issue without seeing exactly what the average price should be, compared to what is actually reported.
                Dave,

                I put one in the original post. Run 2 strategies with it one with the property Dir = False and one with Dir = True. And you'll get the results I posted below use any Forex once both take a position the AVG is out, once one hits a profit target the PNL is out.

                Comment


                  #9

                  Comment


                    #10
                    Thanks guys. I was able to reproduce the issue this morning using the steps outlined in this thread, and I've submitted a report with tracking ID # NTEIGHT-9047.
                    Dave I.NinjaTrader Product Management

                    Comment


                      #11
                      Originally posted by NinjaTrader_Dave View Post
                      Thanks guys. I was able to reproduce the issue this morning using the steps outlined in this thread, and I've submitted a report with tracking ID # NTEIGHT-9047.
                      Cheers Dave thanks for the update.

                      Comment


                        #12
                        I'm happy to report that we have applied a fix to resolve this issue. Please keep this issue in mind to test once more when the Beta 8 build is released.
                        Dave I.NinjaTrader Product Management

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by DJ888, 04-16-2024, 06:09 PM
                        6 responses
                        18 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by Jon17, Today, 04:33 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post Jon17
                        by Jon17
                         
                        Started by Javierw.ok, Today, 04:12 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post Javierw.ok  
                        Started by timmbbo, Today, 08:59 AM
                        2 responses
                        10 views
                        0 likes
                        Last Post bltdavid  
                        Started by alifarahani, Today, 09:40 AM
                        6 responses
                        41 views
                        0 likes
                        Last Post alifarahani  
                        Working...
                        X