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!
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
NinjaTrader
Account name dropdown selector in strategy
Collapse
X
-
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?Tags: None
-
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
-
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
-
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
-
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
by DynamicTest
Today, 08:25 PM
|
||
Started by ScottWalsh, Today, 06:52 PM
|
4 responses
36 views
0 likes
|
Last Post
by ScottWalsh
Today, 07:40 PM
|
||
Started by olisav57, Today, 07:39 PM
|
0 responses
7 views
0 likes
|
Last Post
by olisav57
Today, 07:39 PM
|
||
Started by trilliantrader, Today, 03:01 PM
|
2 responses
21 views
0 likes
|
Last Post
by helpwanted
Today, 07:25 PM
|
||
Started by cre8able, Today, 07:24 PM
|
0 responses
10 views
0 likes
|
Last Post
by cre8able
Today, 07:24 PM
|
Comment