AccountItemUpdate

View as Markdown

Definition

AccountItemUpdate is used for subscribing to account item update events.

Remember to unsubscribe if you are no longer using the subscription.

Syntax

AccountItemUpdate

Example

1/* Example of subscribing/unsubscribing to account item update events 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 Account account;
6 public MyAddOnTab()
7 {
8 // Find our Sim101 account
9 lock (Account.All)
10 account = Account.All.FirstOrDefault(a => a.Name == "Sim101");
11
12 // Subscribe to account item updates
13 if (account != null)
14 account.AccountItemUpdate += OnAccountItemUpdate;
15 }
16
17 // This method is fired on any change of an account value
18 private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
19 {
20 // Output the account item
21 NinjaTrader.Code.Output.Process(string.Format("Account: {0} AccountItem: {1} Value: {2}",
22 e.Account.Name, e.AccountItem, e.Value), PrintTo.OutputTab1);
23 }
24
25 // Called by TabControl when tab is being removed or window is closed
26 public override void Cleanup()
27 {
28 // Make sure to unsubscribe to the account item subscription
29 if (account != null)
30 account.AccountItemUpdate -= OnAccountItemUpdate;
31 }
32
33 // Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code.
34}