Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Account PnL

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

    Account PnL

    Good afternoon, I have several strategies running at the same time, I would like to get the PnL value of the whole account. I tried using Position Account.Get Unrealized Profit Loss(Performance Unit.Point, Close[0] ), but it returns the PnL value of the strategy. How can I get the PnL value of an entire account? Thanks

    #2
    Hello Bogdan097,

    PositionAccount would be how to do that from a strategy. Are you certain that both strategies placed realtime positions? The account values are only for realtime positions so if one strategy had entered historically and the other in realtime that would be a situation where you would only see the pnl for one strategy.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Yes, the two strategies work in real time since I disabled the history in the code. I make a conclusion and get the PnL of each strategy.

      double totalUnrealizedProfit = PositionAccount.GetUnrealizedProfitLoss(Performanc eUnit.Points, Close[0]);
      Print(totalUnrealizedProfit);

      Comment


        #4
        Hello Bogdan097,

        Did the two strategies enter at about the same price point? The account positions average price is used to calculate the unrealized, if both strategies entered near the same price then the unrealized may match one of the strategies directly.

        You should see that the value you get back is the same value as the control center positions tab unrealized pnl for the position on the instrument. Are you seeing that match?



        JesseNinjaTrader Customer Service

        Comment


          #5
          No, the entry price is different because one Expert opens a buy-stop limit and the second one opens a sell-stop limit. Is this most likely a mistake? And how can I get a PnL account?

          Comment


            #6
            Hello Bogdan097,

            If you are buying and selling on the same account and instrument that would make the account flat but each strategy would think it was in a position. Two strategies cannot trade opposite from each other on the same account. Are you trying to get PnL from multiple accounts?

            JesseNinjaTrader Customer Service

            Comment


              #7
              No, I have a strategy that works on two different currency pairs. My idea is that if one strategy loses -100 and the second one earns +200, I get a PnL account and if I earn for example $ 100, then I close all transactions

              Comment


                #8
                Hello Bogdan097,

                A position is your current buy or sell into a single market, if you are using multiple currencies you have multiple positions. Each strategy would have a unique position that is not shared with the other strategy because it is running on a different instrument. If you want the overall accounts unrealized PnL that you see in the account tab you need to use the addon framework to find an account and then use the Account.Get method.



                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thank you very much, you helped me a lot.
                  May I also ask if it is possible to make flatten everything in the code?

                  Comment


                    #10
                    Hello Bogdan097,

                    I would suggest to have the strategies close their own positions using exit orders so the strategies individualized performance can collect the exit and maintain the strategies logic. Closing positions from outside the strategies using the addon approach will prevent them from knowing that happened and could allow them to still exit the non existing positions.

                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      I get it, thanks a lot for the help.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Haiasi, 04-25-2024, 06:53 PM
                      2 responses
                      16 views
                      0 likes
                      Last Post Massinisa  
                      Started by Creamers, Today, 05:32 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post Creamers  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      12 responses
                      1,786 views
                      0 likes
                      Last Post Leafcutter  
                      Started by poplagelu, Today, 05:00 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post poplagelu  
                      Started by fx.practic, 10-15-2013, 12:53 AM
                      5 responses
                      5,407 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Working...
                      X