Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Account name dropdown selector in strategy

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

    Account name dropdown selector in strategy

    I would like to be able to select the account to use for a strategy by selecting an option for a dropdown menu, much like selecting from a custom enum. But I don't want to hardcode my account names in an enum - I just want to somehow get the possible account names and somehow put those into a NinjaScriptProperty. How do I do that in my strategy code?

    #2
    Hello westofpluto,

    Your strategy already has a dropdown of the available accounts wherever you apply it. Adding a second property would not allow you to select a different account, you would still need to use the original account selector for that purpose. In the strategy code you can use Account to access the selected account.

    When you apply a strategy the account is listed as the first option in the Setup section.

    Please let me know if I may be of further assistance.

    Comment


      #3
      Thanks, that's great but I also need to get the account value for whatever account is selected. It looks to me like the only way to do this is using the account name, but I don't know how to do that. What is the best way to get the Account object and account balance for this account - ie for whatever account is selected in that default dropdown that every strategy provides?

      Comment


        #4
        Hello westofpluto,

        What specific value are you trying to get from the account? The current CashValue?

        You have access to the selected account, that is: Account. https://ninjatrader.com/support/help...gy_account.htm

        You could use Account.Get to get different values from the strategies selected account:




        I look forward to being of further assistance.


        Comment


          #5
          Well, ok, I just figured it out. It turns out that Account is not only the name of the account class. There is also a Strategy.Account variable that represents the account object (yes, of type Account) that is currently selected. Having a member variable with the exact same name as a class name is not good software design, but it is what it is.

          Anyway, in my strategy I can use the Account object (or this.Account to make it slightly more readable) and get account value like this:

          private double getAccountValue() {
          return this.Account.Get(AccountItem.CashValue, Currency.UsDollar);
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          44 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
          65 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