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
                  http://ninjatrader.com/support/forum...ad.php?t=78479

                  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 Ithinkimlost, Yesterday, 08:50 PM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_PaulH  
                        Started by Stanfillirenfro, Today, 05:31 AM
                        0 responses
                        22 views
                        0 likes
                        Last Post Stanfillirenfro  
                        Started by sidlercom80, Today, 04:45 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post sidlercom80  
                        Started by NT-Roland, Today, 04:44 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post NT-Roland  
                        Started by knarfoe, Today, 04:26 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post knarfoe
                        by knarfoe
                         
                        Working...
                        X