SimulationAccountReset

View as Markdown

Definition

SimulationAccountReset can be used for subscribing to simulation account reset events. These resets occur whenever the user manually resets an account as well as when the user rewinds/fast forwards the Playback connection. When the reset occurs due to changes to the Playback connection it is important to recreate bar requests.

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

Syntax

SimulationAccountReset

Examples

1/* Example of subscribing/unsubscribing to sim account reset events from an Add On. The concept can be carried over to any NinjaScript object you may be working on. */
2public class MyAddOnTab : NTTabPage
3{
4 public MyAddOnTab()
5 {
6 // Subscribe to sim account resets
7 Account.SimulationAccountReset += OnSimulationAccountReset;
8 }
9
10 /* This method is fired on sim account reset events. It is important to recreate bar requests
11 after a reset on the Playback connection */
12 private void OnSimulationAccountReset(object sender, EventArgs e)
13 {
14 Account simAccount = (sender as Account);
15
16 // If the account was reset due to a rewind/fast forward of the Playback connection
17 if (simAccount != null && simAccount.Provider == Provider.Playback)
18 {
19 // Redo our bars requests here
20 }
21 }
22
23 // Called by **TabControl** when tab is being removed or window is closed
24 public override void Cleanup()
25 {
26 // Make sure to unsubscribe to the simulation account reset subscription
27 Account.SimulationAccountReset -= OnSimulationAccountReset;
28 }
29
30 // Other required **NTTabPage** members left out for demonstration purposes. Be sure to add them in your own code.
31}