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 wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              27 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 04-23-2024, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              193 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,235 views
              0 likes
              Last Post xiinteractive  
              Working...
              X