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 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.
    JesseNinjaTrader Customer Service

    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.


        JesseNinjaTrader Customer Service

        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 judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          59 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          36 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          21 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          10 views
          0 likes
          Last Post cre8able  
          Working...
          X