Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AccountItem on OnBarUpdate()

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

    AccountItem on OnBarUpdate()

    Hi, I'm trying to display some of my account profit and loss (realized and unrealized) on my indicator. When printing
    Code:
     Print(AccountItem.GrossRealizedProfit)
    , it actuall just read out a string "GrossRealizedProfit".

    What am i doing wrong, I want to display the realized and unrealized profit.

    thanks

    #2
    Hello thaison316, thanks for your post.

    An Account object must be created to reference its values. Have you set up an account object like in the example on this page?

    https://ninjatrader.com/support/help...ount_class.htm

    Please let me know if this does not resolve your inquiry.

    Comment


      #3
      I was able to follow that setup but cannot only do it for Sim101. When I set it to a different account name, always get an error

      Indicator '_CustomTickCounter': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

      Is there a way to print the list of Name to see if what account name the system have to what i'm comparing it to?
      Code:
      myAccount = Account.All.FirstOrDefault(a => a.Name != "myaccountname here");

      Comment


        #4
        Hello thaison316, thanks for your reply.

        The name must match the exact account name that you see in the Accounts tab of the Control Center. Make sure this string matches exactly. You can print out the name of each account with this bit of code:

        foreach(Account a in Account.All)
        {
        Print(a.Name.ToString());
        }

        And also make sure you are connected to the right data feed so your account will show up.

        Please let me know if this does not resolve your inquiry.

        Comment


          #5
          thanks that works, right now I have this on "onStateChange", the problem is, on start up everyday, it errors out and stop working because when you first start, the connection is not establish yet so it cannot find any account until the connect is fully established. What do you recommend that I do?

          Comment


            #6
            Hello thaison316 thanks for your reply.

            In this scenario, you would need to set up the account object within OnConnectionStatusUpdate. Notice the connectionStatusUpdate args includes an connectionStatusUpdate.Connection.Accounts array of accounts that can be looped through in the same way. See the Net Change Display indicator for a full example.

            Please let me know if I can assist any further.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            672 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X