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()
    {[INDENT]accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
    [/INDENT][INDENT]accountSelector.SelectionChanged += (o, args) =>[/INDENT][INDENT]{[/INDENT][INDENT=2]accountSelector.SelectedAccount.AccountItemUpdate += OnAccountItemUpdate;[/INDENT][INDENT]};[/INDENT]
     
     }
    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


      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.

          Comment


            #20
            Hi Jim

            I have:
            Code:
            private void TestSelect()
            {[INDENT]accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("C hartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;[/INDENT][INDENT]accountSelector.SelectionChanged += (o, args) =>[/INDENT][INDENT=2]{[/INDENT][INDENT=3]accountSelector.SelectedAccount.AccountItemUpdate += OnAccountItemUpdate;[/INDENT][INDENT=2]};[/INDENT]
             
             }
            And:
            Code:
            protected void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
            {[INDENT]Print("Selection changed");[/INDENT]
             
             }
            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)
              {[INDENT]Print("Changed account to: " + accountSelector.SelectedAccount.Name);[/INDENT]
               
               }
              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 Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              602 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              347 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              560 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              559 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X