Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator code snippets to get Account, Quantity, ATM from ChartTrader?

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

    #16
    Thought I'd hijack this thread.

    If I have:
    Code:
    private void TestSelect()
    {
    accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
    accountSelector.SelectionChanged += (o, args) =>
    {
    accountSelector.SelectedAccount.AccountItemUpdate += OnAccountItemUpdate;
    };
    }
    How do I get the account name when the account selection changes?

    Comment


      #17
      Hello FatCanary,

      SelectedAccount is an Account object, and you can get the name from the Name property.

      I.E. Print(accountSelector.SelectedAccount.Name);

      Account - https://ninjatrader.com/support/help...ount_class.htm


      JimNinjaTrader Customer Service

      Comment


        #18
        Hi Jim

        Yes, I've got that, thank you.

        The problem I'm having is being able to run code when the accountSelector.SelectionChanged is triggered.

        Comment


          #19
          Hello FatCanary,

          Thanks or your reply.

          In your snippet, accountSelector.SelectedAccount.AccountItemUpdate += OnAccountItemUpdate; is executed when the selection changes. Any other code you place in that code block will execute when the selection changes.

          You can also subscribe a method to the SelectionChanged event, similar to how the TimerEventProcessor method is subscribed to the myTimer.Elapsed event in the Help Guide example code here: https://ninjatrader.com/support/help...ustomevent.htm which will allow any code within the subscribed method to be processed when that selection changes.
          JimNinjaTrader Customer Service

          Comment


            #20
            Hi Jim

            I have:
            Code:
            private void TestSelect()
            {
            accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
            accountSelector.SelectionChanged += (o, args) =>
            {
            accountSelector.SelectedAccount.AccountItemUpdate += OnAccountItemUpdate;
            };
            }
            And:
            Code:
            protected void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
            {
            Print("Selection changed");
            }
            But the Print statement does not appear to be executed when I change the account in ChartTrader account selector.
            Last edited by FatCanary; 06-18-2021, 12:55 PM.

            Comment


              #21
              I now have:
              Code:
              private NinjaTrader.Gui.Tools.AccountSelector accountSelector;
              
              accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
              accountSelector.SelectionChanged += OnAccountItemUpdate;
              
              private void OnAccountItemUpdate(object sender, SelectionChangedEventArgs e)
              {
              Print("Changed account to: " + accountSelector.SelectedAccount.Name);
              }
              Which seems to be working fine.

              Thank you for the guidance regarding the SelectionChanged event.
              Last edited by FatCanary; 06-20-2021, 03:12 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by torch2k, Today, 06:24 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by WalterSkinner, Yesterday, 02:37 PM
              3 responses
              21 views
              0 likes
              Last Post NinjaTrader_Jim  
              Started by Fer123, Yesterday, 04:57 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Jim  
              Started by Cormick, Today, 06:26 AM
              0 responses
              4 views
              0 likes
              Last Post Cormick
              by Cormick
               
              Started by Devside_Victor, Today, 04:57 AM
              0 responses
              1 view
              0 likes
              Last Post Devside_Victor  
              Working...
              X