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 value in Indicator

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

    Account value in Indicator

    Is there any way to pull Account value into an indicator? Tried GetAccountValue() but this seems to be restricted to strategies. Goal is to display desired position size on my chart within an indicator. Thanks

    #2
    Hello,

    Thank you for the question.

    This is possible by use of undocumented items. I had posted in a thread about this in the past here: http://ninjatrader.com/support/forum...78&postcount=2

    This is a general example that could be modified as needed.

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

    Comment


      #3
      Hi Jesse thanks for the pointer, it appears that the GetAccountValue method still won't compile in the indicator context. This code:

      private void StoreAccountValue()
      {
      foreach (Account acct in Cbi.Globals.Accounts)
      {
      string acctvalstr = acct.GetAccountValue.ToString();
      Print(acctvalstr);
      }
      }

      generates: "method not valid in the given context" Works fine for acct.Name

      Is there another way to access the account value using acct. ? Thanks!

      Comment


        #4
        Hello NT - wondering if you were able to find a solution for this or if I'm perhaps doing something wrong? Thanks!

        Comment


          #5
          Hello,

          Thank you for the reply.

          Unfortunately the syntax you had provided would still only work in a Strategy but would also need to be valid syntax as shown in the help guide. You have provided only part of the syntax shown in the help guide therefore this would cause a compile error.

          For what you are trying to do, because this is a unsupported approach you would need to subscribe to the account values and store these in variables yourself. you would be unable to actively "poll" or request the data at arbitrary times.

          Here is a simple example showing Printing the values, again this only happens during an account update event so it would not print unless you connect or place an order or any account related action.

          Code:
          protected override void OnStartUp()
          {
          	foreach (Account acct in Cbi.Globals.Accounts)
          	{
                      acct.AccountUpdate += Acct_AccountUpdate;
          	}	
          }
          
          private void Acct_AccountUpdate(object sender, AccountUpdateEventArgs e)
          {
              Print(e.ItemType.ToString() + " " + e.Value);
          }
          Please let me know if I may be of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Originally posted by entropy View Post
            Hi Jesse thanks for the pointer, it appears that the GetAccountValue method still won't compile in the indicator context. This code:

            private void StoreAccountValue()
            {
            foreach (Account acct in Cbi.Globals.Accounts)
            {
            string acctvalstr = acct.GetAccountValue.ToString();
            Print(acctvalstr);
            }
            }

            generates: "method not valid in the given context" Works fine for acct.Name

            Is there another way to access the account value using acct. ? Thanks!
            That is because your syntax for GetAccountValue() is incorrect. Here is an example of how to do it correctly.
            Code:
            Print("Accounts Enumerated from 'for' loop");
            			for (int i = 0; i <= NinjaTrader.Cbi.Globals.Accounts.Count - 1; ++i)
            			{
            				Print(String.Format("{0}: {1}: {2}"
            				, NinjaTrader.Cbi.Globals.Accounts[i].Name
            				, NinjaTrader.Cbi.Globals.Accounts[i].GetAccountValue(AccountItem.CashValue, Currency.Unknown)
            				, NinjaTrader.Cbi.Globals.Accounts[i].ToString()));
            			}

            Comment


              #7
              This worked, thank you!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by inanazsocial, Today, 01:15 AM
              0 responses
              1 view
              0 likes
              Last Post inanazsocial  
              Started by trilliantrader, 04-18-2024, 08:16 AM
              5 responses
              22 views
              0 likes
              Last Post trilliantrader  
              Started by Davidtowleii, Today, 12:15 AM
              0 responses
              3 views
              0 likes
              Last Post Davidtowleii  
              Started by guillembm, Yesterday, 11:25 AM
              2 responses
              9 views
              0 likes
              Last Post guillembm  
              Started by junkone, 04-21-2024, 07:17 AM
              9 responses
              70 views
              0 likes
              Last Post jeronymite  
              Working...
              X