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 from NT8

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

    Account.Name from NT8

    Hello,

    I use "Account.Name" with NT7 but in NT8 it doen't exist. So, I need to know the name of the "active account" from my strategy without checking the rest of the accounts in "Account. All".

    Is it possible to access directly to this information?

    Thanks in advance.

    #2
    Hello,

    Thank you for the post.

    The same syntax should work as it did in NT7, I currently see the following working for me:

    Code:
    protected override void OnBarUpdate()
    {
    	Print(Account.Name);
    }
    Where are you trying to access the Account property in the strategy?

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

    Comment


      #3
      Hello Jesse,

      I'm using "Account.Name" in "OnBarUpdate()" like you, and this is the NinjaScript Error:

      "An object reference is required for the non-static field, method, or property Ninjatrader.Cbi.Account.Name.get"

      Comment


        #4
        Hello,

        Thank you for the reply.

        Have you changed the using statements at the top of the script or defined your own object named Account?

        Account is an inherited property of every strategy so unless you have one of the items I have noted then this syntax should work.

        I would suggest generating a brand new empty strategy and try placing the code in the OnBarUpdate to see if you still have the same error.

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

        Comment


          #5
          Hello Jesse,

          I have found the problem. I can access to "Account" from a strategy but I can't do it from an indicator.

          How can I get the "Account.Name" from an indicator?

          Comment


            #6
            Hello soyjesus,

            Correct, the Account inherited property is only relevant to objects that require an account such as a Strategy.

            In contrast to the details that this is an Indicator, you would instead have a few alternatives.

            Assuming you are calling the indicator from a strategy, you can pass the Account as an overload to the indicator or a String with the account name so you can use Account.All from the indicators code.

            Alternatively, you would need to make a input or string with the account name in the indicator and you would need to use the Addon methods to access the account you want. As the indicator has no idea what account is selected, you need to either supply an Account object, string with the account name or make some kind of input property for the account name so it can be accessed.

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

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Alternatively, you would need to make a input or string with the account name in the indicator and you would need to use the Addon methods to access the account you want. As the indicator has no idea what account is selected, you need to either supply an Account object, string with the account name or make some kind of input property for the account name so it can be accessed.
              Could you please provide a sample code to get account name using Addon method for an indicator?
              All I need to do is to change the indicator on chart according to current account, but I am having difficulty to get the account name in indicator code.

              Comment


                #8
                Hello istock999,

                Do you mean the selected chart trader account?

                This thread was specifically referring to how Indicators do not have an associated account, and how you would need to manually specify an account for the indicator to use.

                Your question sounds more like it is targeted at finding the selected chart trader account, is this correct? If so, please see the following post: https://ninjatrader.com/support/foru...51&postcount=2

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

                Comment


                  #9
                  Hi, in my strategy I am able to get the SELECTED account name by using the following code:

                  Code:
                  NinjaTrader.Gui.Tools.AccountSelector xAlselector;
                  
                  ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                  {
                  xAlselector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
                  Print(xAlselector.SelectedAccount.ToString());
                  }));
                  However, I cannot assign 'xAlselector.SelectedAccount.ToString())' to a string variable, cause it loses scope. I tried setting the xAlselector string to a global variable that I setup in an add on but that didn't work either cause scope is lost and I just get a null string. I also tried Account.Name.. that does not provide the user selected account name, it only retruns the 1st sim account name.


                  My goal is to obtian the account name that the user selected on the chart that the strategy is running on and set it to a string variable in the strategy. The strategy will later on use tthat account name to execute certain requirements.


                  Please advice, thank you.
                  Jess

                  Comment


                    #10
                    Hello xmess7,

                    You tried the xAlselector.SelectedAccount.Name? (This would already be a string)

                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello xmess7,

                      You tried the xAlselector.SelectedAccount.Name? (This would already be a string)

                      https://ninjatrader.com/support/foru...98#post1055898

                      Hi, I figured it out. Account.Name is all that I need. Turns out that I was not changing the account in the strategy inputs window, thus the reason for me seeing the same name each time I ran the strategy. In addition I was miinterpreting the code I had posted, that code only grabs the account name from the one of the chart menu elements (like the chartTrader).

                      Thnx for responding,
                      Take care
                      Jess

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by cre8able, Today, 03:20 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post cre8able  
                      Started by Fran888, 02-16-2024, 10:48 AM
                      3 responses
                      47 views
                      0 likes
                      Last Post Sam2515
                      by Sam2515
                       
                      Started by martin70, 03-24-2023, 04:58 AM
                      15 responses
                      114 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by The_Sec, Today, 02:29 PM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      2 responses
                      31 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Working...
                      X