AccountSelector

View as Markdown

Definition

AccountSelector can be used as an UI element users can interact with for selecting accounts.

Events and Properties

Method/PropertyDescription
Cleanup()Disposes of the AccountSelector (Note: calling the NTTabPage base.Cleanup() is sufficient to clean up this control)
SelectedAccountReturns an Account representing the selected account
SelectionChangedEvent handler for when the selected account has changed

Examples

1/* Example of subscribing/unsubscribing to market data from an Add On. The concept can be carried over
2to any NinjaScript object you may be working on. */
3public class MyAddOnTab : NTTabPage
4{
5 private AccountSelector accountSelector
6
7 public MyAddOnTab()
8 {
9 // Note: pageContent (not demonstrated in this example) is the page content of the XAML
10 // Find account selector
11 accountSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "accountSelector") as AccountSelector;
12
13 // When the account selector's selection changes, unsubscribe and resubscribe
14 accountSelector.SelectionChanged += (o, args) =>
15 {
16 if (accountSelector.SelectedAccount != null)
17 {
18 // Unsubscribe to any prior account subscriptions
19 accountSelector.SelectedAccount.AccountItemUpdate -= OnAccountItemUpdate;
20 accountSelector.SelectedAccount.ExecutionUpdate -= OnExecutionUpdate;
21 accountSelector.SelectedAccount.OrderUpdate -= OnOrderUpdate;
22 accountSelector.SelectedAccount.PositionUpdate -= OnPositionUpdate;
23
24 // Subscribe to new account subscriptions
25 accountSelector.SelectedAccount.AccountItemUpdate += OnAccountItemUpdate;
26 accountSelector.SelectedAccount.ExecutionUpdate += OnExecutionUpdate;
27 accountSelector.SelectedAccount.OrderUpdate += OnOrderUpdate;
28 accountSelector.SelectedAccount.PositionUpdate += OnPositionUpdate;
29 }
30 };
31 }
32
33 // Called by TabControl when tab is being removed or window is closed
34 public override void Cleanup()
35 {
36 // Clean up our resources
37 base.Cleanup();
38 }
39
40 // Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code.
41}
<page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:accountdata="clr-namespace:NinjaTrader.Gui.AccountData;assembly=NinjaTrader.Gui"
xmlns:accountperformance="clr-namespace:NinjaTrader.Gui.AccountPerformance;assembly=NinjaTrader.Gui"
xmlns:atmstrategy="clr-namespace:NinjaTrader.Gui.NinjaScript.AtmStrategy;assembly=NinjaTrader.Gui"
xmlns:tools="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrader.Gui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<grid>
<tools:accountselector horizontalalignment="Left" verticalalignment="Top" x:name="accountSelector"></tools:accountselector>
</grid>
</page>