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

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        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.

            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Richozzy38, Today, 01:06 PM
            3 responses
            14 views
            0 likes
            Last Post Richozzy38  
            Started by ttrader23, Today, 09:04 AM
            2 responses
            10 views
            0 likes
            Last Post ttrader23  
            Started by geotrades1, Today, 07:54 AM
            10 responses
            26 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by ninza33, Yesterday, 12:31 PM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by patrickmlee007, Today, 09:33 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Working...
            X