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

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


      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()
            {[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 andrewtrades, Today, 04:57 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by chbruno, Today, 04:10 PM
              0 responses
              3 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by josh18955, 03-25-2023, 11:16 AM
              6 responses
              436 views
              0 likes
              Last Post Delerium  
              Started by FAQtrader, Today, 03:35 PM
              0 responses
              7 views
              0 likes
              Last Post FAQtrader  
              Started by rocketman7, Today, 09:41 AM
              5 responses
              19 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X