Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Account items

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

    Account items

    I'm trying to get Realized pnl and Unrealized pnl from "Accounts" tab (want same numbers reflected in "Accounts" tab on aggregate day's all trades basis).

    I am able to run the following but it seems to be based on the current strategy NOT aggregate "Accounts" tab...

    protected override void OnAccountItemUpdate(Account account, AccountItem accountItem, double value)
    {
    Realized = (double)AccountItem.RealizedProfitLoss;
    UnRealized = (double)AccountItem.UnrealizedProfitLoss;

    Print(Realized + " " + UnRealized);
    }
    Last edited by EthanHunt; 03-13-2018, 02:29 PM.

    #2
    Hello EthanHunt,

    Thanks for opening the thread.

    OnAccountItemUpdate() will iterate for updates for the account that the NinjaScript is applied to, and will not be limited to the executions of your strategy.

    I have attached a demonstration of this method in use where manual trades are taken and the strategy outputs data to the Output Window.

    Demonstration: https://www.screencast.com/t/DhF7tjEaL

    I've also attached a screenshot of my Control Center for this test.

    If you would like to specify the account(s) you wish to see updates for, you can subscribe to AccountItemUpdate events for a particular account. I'll provide a publicly available documentation link and example where this gets implemented in an indicator.

    AccountItemUpdate - https://ninjatrader.com/support/help...itemupdate.htm

    Please let me know if I can be of further assistance.
    Attached Files

    Comment


      #3
      Thanks. I see the following line. How do I set a variable for Realized pnl and Unrealized pnl? Thanks.

      NinjaTrader.Code.Output.Process(string.Format("Acc ount: {0} AccountItem: {1} Value: {2}",
      e.Account.Name, e.AccountItem, e.Value), PrintTo.OutputTab1);

      Comment


        #4
        Hello EthanHunt,

        You will want to check if the Accounttem that is updating in the method is AccountItem.RealizedProfitLoss, or AccountItem.UnrealizedProfitLoss, and then you will want to set a variable to hold the value of e.Value when e is AccountItemEventArgs.

        For example:
        Code:
        private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
        {
        	if(e.AccountItem == AccountItem.UnrealizedProfitLoss)
        	{	
        		double UnrealizedPnl = e.Value;
        	}
        }
        Additional AccountItems are publicly documented here: https://ninjatrader.com/support/help...ccountitem.htm

        I look forward to being of further assistance.

        Comment


          #5
          Originally posted by NinjaTrader_Jim View Post
          Hello EthanHunt,

          You will want to check if the Accounttem that is updating in the method is AccountItem.RealizedProfitLoss, or AccountItem.UnrealizedProfitLoss, and then you will want to set a variable to hold the value of e.Value when e is AccountItemEventArgs.

          For example:
          Code:
          private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
          {
          if(e.AccountItem == AccountItem.UnrealizedProfitLoss)
          {
          double UnrealizedPnl = e.Value;
          }
          }
          Additional AccountItems are publicly documented here: https://ninjatrader.com/support/help...ccountitem.htm

          I look forward to being of further assistance.


          I added this code but I get the following error:

          Class, delegate, enum, interface, or struct expected.

          Comment


            #6
            Hello EthanHunt,

            Can you copy/paste the script as you have it now? This error would generally be shown if you have an error in the overall structure of the file. For example if you added too many brackets or placed this in an incorrect location.

            This is a method so it would go below OnBarUpdate or outside the other methods in your class:
            Code:
            protected override void OnBarUpdate()
            {
            
            }
            
            private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
            {
                if(e.AccountItem == AccountItem.UnrealizedProfitLoss)
                 {
                    double UnrealizedPnl = e.Value;
                  }
            }
            I look forward to being of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X