Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily Profit & Loss

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

    Daily Profit & Loss

    I'm building an addon for NT8 that monitors Trader's daily P&L.

    I have noticed that Realized P&L is supplied by the brokerage connected. Brokerage also resets Realized P&L to zero from time to time.

    Inside NinjaScript, is there any way of knowing daily P&L?

    If not,how do I detect when P&L is reset by the brokerage?

    Thanks!

    #2
    Hello,

    You should be able to use the OnAccountItemUpdate() event callback method to track any changes to your account's cash value throughout the day. You could then use your own variable to track changes in cash value throughout the day. This method should not be affected by any server-side reset of PnL values, and would allow you to precisely track any changes in cash value throughout each day (or any other supported account item you wished to check).

    The Help Guide page below should provide insight into how to check your account item values via an AddOn:

    http://ninjatrader.com/support/helpGuides/nt8/en-us/?accountitemupdate.htm
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Using OnAccountItemUpdate() I can track AccountItem.GrossRealizedProfitLoss. That works.
      The problem is, to calculate Daily realized PnL I need to know when exactly broker resets realized PnL, so I can use last GrossRealizedProfitLoss for the offset.

      I tried to treat an event when GrossRealizedProfitLoss becomes zero as a reset, but this could happen naturally, so this is not a reliable way of detecting realized PnL reset.

      Can you suggest any other way?

      P.S. To recap, my goal is to calculate daily PnL of an account, 12:00 AM - 12:00 AM

      Comment


        #4
        Hello,

        Thank you for the question.

        In this case, it would seem this is only reset when NinjaTrader is restarted so although the broker may reset the value, a running instance of NInjaTrader would persist the values until the platform is restarted as you are still in the same trading session.

        You could find out from the broker when this is reset with your account and then track this manually in the script resetting each day at that specified time.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi. I don't see a clear answer michaelsh's question and I would like the same answer or sample code on how to do this INSIDE my strategy.

          I'd like to know how to actually code:

          1) "get" all trades for the current day for this strategy
          2) Calculate the total net profit, number of trades... # winners, # losers... all the metrics

          Can you provide some sample code on where to put all of this?

          I don't know when to use

          A) ACCOUNT (under ADDON in the help)
          B) Strategy->System Performance
          C) Strategy->Trades->Trade Collection
          D) Strategy->TradePerformanceValues

          Can you please advise us on where and when to use these areas and provide some sample strategies?

          Thanks

          Originally posted by michaelsh View Post
          I'm building an addon for NT8 that monitors Trader's daily P&L.

          I have noticed that Realized P&L is supplied by the brokerage connected. Brokerage also resets Realized P&L to zero from time to time.

          Inside NinjaScript, is there any way of knowing daily P&L?

          If not,how do I detect when P&L is reset by the brokerage?

          Thanks!

          Comment


            #6
            Hi. Can someone please post an example of how to do an AddOn for the Account info so I can in my strategy pull this information. I don't have a clue as to how to do that, and I really need to read my IB account information, and the Control Center-Positions information.

            This is so complicated.... I have read all the help files, they are not complete, or don't go from A to Z - they seem to start 1/2 way through the process.

            Everytime I go to use the Account stuff, I get compile errors because I think it is supposed to be called from an AddOn. Anyway, I don't have a clue.

            Thanks for any help.

            Originally posted by michaelsh View Post
            I'm building an addon for NT8 that monitors Trader's daily P&L.
            !
            Last edited by DaFish; 03-07-2016, 09:45 PM.

            Comment


              #7
              Hello,

              Originally posted by DaFish View Post
              Hi. I don't see a clear answer michaelsh's question and I would like the same answer or sample code on how to do this INSIDE my strategy.

              I'd like to know how to actually code:

              1) "get" all trades for the current day for this strategy
              2) Calculate the total net profit, number of trades... # winners, # losers... all the metrics

              Can you provide some sample code on where to put all of this?

              I don't know when to use

              A) ACCOUNT (under ADDON in the help)
              B) Strategy->System Performance
              C) Strategy->Trades->Trade Collection
              D) Strategy->TradePerformanceValues

              Can you please advise us on where and when to use these areas and provide some sample strategies?

              Thanks
              Regarding question 1 and 2, To get all trades for a specific strategy but only for the current day, that would depend on if the strategy remains running or not day to day. If it is restarted daily, you can just use the Performance collections as they would only show trades for that strategies trading session or while it was active: http://ninjatrader.com/support/helpG.../alltrades.htm
              Using this approach you can also use all of the built in performance statistics: http://ninjatrader.com/support/helpG...ancevalues.htm

              The other direction if the strategy would be enabled for multiple days, I do not have a sample of as you would need to develop your own custom logic that suits any needs you have. One way to determine each day would be to store the trade count at the end or beginning of the session and then utilize logic to only use the trades after that point.

              Regarding the remainder of the questions:
              A). Addons in general are a very advanced subject that assumes the user is well versed in C# already so there is not much documentation on this subject. There is a full sample using account in the help guide page which may help explain this further: http://ninjatrader.com/support/helpG...ount_class.htm regarding your second post on this question, likely the sample would not assist in what you are trying to do as what you are trying to do is not a documented or supported approach.

              For B, C and D, these items are strategy specific as they are only held in the Strategy section of the help guide, these would be used to get performance metrics and trade information for the specific strategy where you call these methods. Also these do each have examples in the help guide:





              Regarding the second post:


              Hi. Can someone please post an example of how to do an AddOn for the Account info so I can in my strategy pull this information. I don't have a clue as to how to do that, and I really need to read my IB account information, and the Control Center-Positions information.

              This is so complicated.... I have read all the help files, they are not complete, or don't go from A to Z - they seem to start 1/2 way through the process.

              Everytime I go to use the Account stuff, I get compile errors because I think it is supposed to be called from an AddOn. Anyway, I don't have a clue.

              Thanks for any help.
              What you are trying to do by how it is described would not be a documented or supported approach at creating a strategy. In general each strategy can be though of as a single instance or a bubble that is not aware of outside changes once enabled. The strategy can initially sync the account position but then would assume it is the only logic running on that instrument to prevent any errors or incorrect positions.

              While you can utilize an Addon to access account information (link provided earlier), getting that information in a strategy would not be something I could comment on as this would likely require using static programming or undocumented approaches. I do not have any samples of this scenario as likely it would require you to create a custom solution specific to the strategy you are using.


              If you have specific questions on any of these items, please feel free to provide further information on the questions.

              Please let me know if I may be of further assistance.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mestor, 03-10-2023, 01:50 AM
              16 responses
              388 views
              0 likes
              Last Post z.franck  
              Started by rtwave, 04-12-2024, 09:30 AM
              4 responses
              31 views
              0 likes
              Last Post rtwave
              by rtwave
               
              Started by yertle, Yesterday, 08:38 AM
              7 responses
              29 views
              0 likes
              Last Post yertle
              by yertle
               
              Started by bmartz, 03-12-2024, 06:12 AM
              2 responses
              22 views
              0 likes
              Last Post bmartz
              by bmartz
               
              Started by funk10101, Today, 12:02 AM
              0 responses
              7 views
              0 likes
              Last Post funk10101  
              Working...
              X