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 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
    JimNinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        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.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bmartz, 03-12-2024, 06:12 AM
            4 responses
            31 views
            0 likes
            Last Post bmartz
            by bmartz
             
            Started by Aviram Y, Today, 05:29 AM
            4 responses
            11 views
            0 likes
            Last Post Aviram Y  
            Started by algospoke, 04-17-2024, 06:40 PM
            3 responses
            28 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by gentlebenthebear, Today, 01:30 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by cls71, Today, 04:45 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X