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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          79 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          40 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          63 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          63 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          54 views
          0 likes
          Last Post CarlTrading  
          Working...
          X