Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

example of accountSelector.SelectionChanged for indicator?

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

    example of accountSelector.SelectionChanged for indicator?

    Hello,

    is there an example of how to subscribe to the accountSelector.SelectionChanged event for an indicator?

    the help system has one for an AddOnTab

    and it has a base.Cleanup that would not be appropriate for an Indicator...

    Thanks

    #2
    this will not compile

    private void accountSelectorChanged (object sender, AccountSelector.SelectionChangedEvent e)
    {​}

    this will compile but gets a run time error (from the help)

    accountSelector = chartWindow.FindFirst("ChartTraderControlAccountSe lector") as AccountSelector;

    accountSelector.SelectionChanged += (o, args) =>
    {
    };​

    Comment


      #3
      Hello llanqui,

      Thank you for your post.

      I am not aware of an indicator samples that use AccountSelector.SelectionChanged in the script.

      However, as it says in the sample code on the Account Selector help guide page, the code for the account selector can be carried over to any NinjaScript object you may be working on.

      Take a look at the AddOnFramework script which demonstrates using AccountSelector.SelectionChanged:




      Please take a look at the sample code which demonstrates how to properly implement the AccountSelector:



      If you have any further questions, please let us know.

      Comment


        #4
        from the help system example...this won't compile in an indicator

        // Find account selector

        accountSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "accountSelector") as AccountSelector;


        this will..

        accountSelector = chartWindow.FindFirst("ChartTraderControlAccountSe lector") as AccountSelector;


        however, when loaded, I get this error

        Indicator 'AAATM01': Error on calling 'OnStateChange' method: Value cannot be null.
        Parameter name: element​

        apparently caused by this block

        accountSelector.SelectionChanged += (o, args) =>
        {
        accountChanged = true;
        Print ("AAATM01 Account CHANGED");
        };

        seems to me that the interface for the chartWindows AccountSelector is not the same as for the AddOn

        which is why I need your help...or someone else in the thread​

        thankx

        Comment


          #5
          Hello,

          My colleague made me aware of an indicator sample we have that does use AccountSelector.SelectionChanged the script. It is attached below.

          If you need any further assistance, please let us know.
          Attached Files

          Comment


            #6
            this will not compile

            accountSelector = chartWindow.FindFirst("ChartTraderControlAccountSe lector") as AccountSelector; // compiles OK
            accountSelector.SelectionChanged += accountSelectorChanged;​


            private void accountSelectorChanged (object sender, AccountSelector.SelectionChangedEvent e) // <<<<< not ok
            {
            }

            I get this compile error
            The type name 'SelectionChangedEvent' does not exist in the type 'NinjaTrader.Gui.Tools.AccountSelector'

            so, what I really need is the interface for the event....... ​​

            Comment


              #7
              Hello,

              This is demonstrated in the sample script I attached in my previous post, which I encourage you to take a look at for a complete picture of how to properly implement this within an indicator.

              For your convenience, here it is below:

              private void AccountSelector_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)

              If you need any further assistance please let me know.

              Comment


                #8
                Oh, I didn't that last post of yours...will check it..thx

                Comment


                  #9
                  works good, thank you

                  Comment


                    #10
                    Works well, thank you.
                    Question though: you want to add event handler for ExecutionUpdate (or OrderUPdate).

                    How do you handle unsubscribing from the old account ,and subscribing to the new account when they change?
                    I can't find an example, except for an addon here


                    But if you follow that logic, you just end up unsubscribing then resubscribing to the new account, without unsubscribing to the previously selected account.
                    (tested this with print statements).
                    thnkxs!!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    648 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    369 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    572 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    574 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X