Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PnL Wrongly calculated

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

    PnL Wrongly calculated

    Hello!!

    I'm having problems getting the realtime PnL of my operations... In the way I'm trying to do that, I'm getting a wrong value:


    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
    if (Position.MarketPosition != MarketPosition.Flat)
    {
    double currentProfit = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Closes[0][0]);
    }

    }

    In the major cases that currentProfit is not the real PnL obtained by the entry...

    #2
    Hello ricardovejarano,

    It looks like you are supplying the close price of the bar 'Closes[0][0]'. If the script is running with Calcuate.OnBarClose, this value would only update when the bar closes.

    Are you wanting the value from the market data update?
    If so, use the marketDataUpdate.Price.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks...

      I decided to get the unrealized PnL with this (that worked):

      Math.Round(PositionAccount.GetUnrealizedProfitLoss (PerformanceUnit.Currency), MidpointRounding.AwayFromZero)

      But my Idea is always to check a total based in the sum of Unrealized and realized Pnl, so in the beginning, the realized value should be zero... I've been looking for the way to get that realized value and I found:

      Account.GetAccountItem(AccountItem.RealizedProfitL oss, NinjaTrader.Cbi.Currency.UsDollar).Value

      But I'm getting a really rare value and it does not change after some position close...
      Last edited by ricardovejarano; 06-08-2020, 03:45 PM.

      Comment


        #4
        Hello ricardovejarano,

        Thank you for your note.

        If you plan to get the account realized pnl and not the strategies pnl, check for the account item after the account position updates. As a heads up, the account pnl may not match the strategy pnl. Instead this will match the pnl shown on the Accounts tab of the Control Center.

        https://ninjatrader.com/support/foru...21#post1061121
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello, thanks

          I tried to reproduce the example code inside the mine, but doing this:

          else if (State == State.DataLoaded)
          {
          lock (Account.All)
          myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");

          if (myAccount != null)
          myAccount.PositionUpdate += MyAccount_PositionUpdate;
          }
          I'm not getting any print response to my function:

          private void MyAccount_PositionUpdate(object sender, PositionEventArgs e)
          {
          Print(string.Format("Position: {0} {1}", e.MarketPosition, e.Quantity));
          }

          Comment


            #6
            Hello ricardovejarano,

            Is the test script I have linked working ok on your end?

            Is myAccount null after it is assigned?

            Are you placing orders to the Sim101 account?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello ChelseaB!

              Is the test script I have linked working ok on your end?
              Answer:
              No, I just tested that indicator and following the steps of the video doesn't appear anything in the output window

              Comment


                #8
                Hello ricardovejarano,

                After the entry order fills please take a screenshot of the Positions tab of the Control Center and attach this with your next post.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ChelseaB,

                  I now know that there are some things I think I'm missing when I work with MarketReplay data (I don't know which ones)... When I probed for the first time the example I was working with replay data, but a few minutes ago with a demo account data, I could see the messages in the output window ... So, my question at this point Is how or what I have to do or configure to be able to get the realized amount value that appears in Control Center working with replay data (In order to test my total PnL, because the unrealized value is already gotten and works fine in the market replay).

                  Comment


                    #10
                    Hello ricardovejarano,

                    The Playback connection places orders to the Playback101 account not the Sim101 account. If you are in playback you will need to change the code in the script to reflect Playback101.

                    Check the Positions tab of the Control Center to see the account the order is on.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello ChelseaB

                      Thanks!!... My mistake was in the account reference!

                      My finally 2 questions:

                      1. When I work with a real account I only need to change the reference to a "Live101" or something like that?... Or I need to handle it in a different way.

                      2. Now it's working ok, but I have and specific flow that does not work... For example, I placed my strategy on the Control Center, and then I had a profit of 200USD, so next, I remove the strategy from the Control Panel and then I place again it on the window... At that moment the realized value is Zero (control center window) but getting the value from the strategy I get 200USD,
                      it's like the value doesn't reset... There is a way to reset or handle that flow?

                      Comment


                        #12
                        Hello ricardovejarano,

                        When working with a funded brokerage account, you will need to use that account with the name for that account.

                        The SystemPerformance collection will have the correct pnl for each trade.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks for your answer ChelseaB,

                          So, for every different customer, I need to change the account number in the source code before compile?

                          Comment


                            #14
                            Hello ricardovejarano,

                            You could change the hard coded account name in the script for each of your customers.

                            Or you could have an input to allow the user to type their account name or select an account...
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Right!!... Thanks for all your answers ChelesaB!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by WHICKED, Today, 12:56 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cre8able, Today, 01:16 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post cre8able  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              2 responses
                              47 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by WHICKED, Today, 12:45 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by samish18, Today, 01:01 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post samish18  
                              Working...
                              X