Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trouble with reporting correct profit/loss

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

    Trouble with reporting correct profit/loss

    I have a system that is giving me trouble with regard to reporting the correct profit/loss......

    As you can see below, this is what I am using to get the PnL for the GBPUSD:

    primaryPnL = (Closes[1][0] - Positions[1].AvgPrice) ;

    And, this is what I am using to get the PnL of the EURUSD;

    secondaryPnL = (Positions[2].AvgPrice - Closes[2][0]) - eurSpread;

    It enters the positions properly, but does not give me the correct totals with the "Print" command?????

    Any ideas????

    It looks like this:
    ==================================================
    protected override void Initialize()
    {
    Add("$GBPUSD", PeriodType.Minute, 5);
    Add("$EURUSD", PeriodType.Minute, 5);
    EntryHandling = EntryHandling.AllEntries;
    EntryHandling = EntryHandling.UniqueEntries;
    TraceOrders = true;
    ExitOnClose = false;
    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()

    // ================================================== =========
    eurSpread = GetCurrentAsk() - GetCurrentBid();
    // ================================================== ===========
    {

    if ( Positions[1].MarketPosition == MarketPosition.Long
    && Positions[2].MarketPosition == MarketPosition.Short)

    bothInPosition = true;

    {
    if ((BarsInProgress == 1)
    && bothInPosition == false)

    EnterLong(10000, "GBP/USD Long");


    if ((BarsInProgress == 2)
    && bothInPosition == false)

    EnterShort(10000, "EUR/USD Short");

    }
    }

    //================================================== =============

    if (Positions[1].MarketPosition == MarketPosition.Long)
    {
    primaryPnL = (Closes[1][0] - Positions[1].AvgPrice) ;
    }
    if (Positions[2].MarketPosition == MarketPosition.Short)
    {
    secondaryPnL = (Positions[2].AvgPrice - Closes[2][0]) - eurSpread;
    }


    Print("This is the profit of GBD/USD");
    Print (primaryPnL * 10000);
    Print("This is the profit of EUR/USD");
    Print (secondaryPnL * 10000);
    Print("This is the Overall Profit right now");
    Print (currentTotal);

    #2
    edgeliner,

    How is eurSpread defined?

    Could you clarify what the PnL is displaying incorrectly in your output window?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Adam........

      eurSpread is defined like this in the #region Variables section:

      private double eurSpread;

      The numbers are always off by a little for both the EURUSD and the GBPUSD, but not as a constant number like always off by one or two???

      Comment


        #4
        edgeliner,

        It looks like you are trading synthetic spreads here on the GBPUSD and EURUSD.

        The eurSpread, if set statically, wouldn't necessarily be the actual spread between bid/ask. Generally with Forex instruments the spread is pretty static, but its possible for them to change a little for a brief moment.

        Are you comparing this PnL to a particular place like on the DOM or in Chart Trader?

        Also please note that the Bid/Ask would need to possibly be taken into account here as Closes[X][0] would return the Last price. For example, for a buy you are being filled at the ask price, but with Closes[X][0] and "calculate on bar close" = false you are getting the "last" price, which is the price of the last transaction.

        GetCurrentBid() and GetCurrentAsk() would possible work for you here.



        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Adam........

          I tried this (below), but it still returned wrong amounts????

          if (Positions[1].MarketPosition == MarketPosition.Long)
          {
          primaryPnL = (currentGBPbid - Positions[1].AvgPrice) ;


          }
          if (Positions[2].MarketPosition == MarketPosition.Short)
          {
          secondaryPnL = (Positions[2].AvgPrice - currentEURask);
          }

          Comment


            #6
            edgeliner,

            Where are you assigning : currentEURask and currentGBPbid ?
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              #region Variables
              private double currentGBPbid;
              private double currentEURask;

              and...........

              protected override void OnBarUpdate()

              if (BarsInProgress == 1)
              {
              currentGBPbid = GetCurrentBid();
              }

              if (BarsInProgress == 2)
              {
              currentEURask = GetCurrentAsk();
              }

              Comment


                #8
                Edgeliner,

                How much is it off again? Is it some static value or are you getting varied amounts again?

                Could you possible post your code file? Alternatively you can send it to Support at Ninjatrader dot com with :

                ATTN : Adam


                In the message body if you would like it to be private.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Adam......I emailed it to you..........

                  Comment


                    #10
                    edgeliner,

                    I received it, thanks for that. Ill continue corresponding with you through email.
                    Adam P.NinjaTrader 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