Other Uses for an AddOn
Modifying Existing NinjaTrader Windows
To modify an existing type of NinjaTrader window (for example, to add a button to all charts), you will first need to obtain a reference to each individual window of that type that is open. This can be done by overriding the OnWindowCreated() method, then declaring an object of the Type of the window you are looking for, and finally assigning the object a reference to the Window passed into the method:
If you are unsure of the Type name for a particular type of window, you can open an instance of that window then run the code below, which will print the Type to the Output Window:
Once you’ve obtained a reference to a window, you can then directly manipulate the WPF grids, controls, and other elements to customize its user interface or functionality. For example, if your goal was to add a new button to Chart Trader on all charts, you could use your reference to Chart objects to first locate their attached Chart Trader instances, then place a custom-defined button directly into the WPF grid used to lay out buttons in Chart Trader. Since this code would run within OnWindowCreated(), it would be applied to every Chart Trader instance that is open. You would not be changing the format used to create Chart Traders in the first place, but would rather be detecting every open instance and adding the buttons into them. This is an important distinction to make, because this approach requires that you also remove the elements you’ve added when each window is destroyed.
Since we are dynamically adding elements to open windows, it is important to clean up any unused resources and detach any event handlers when the affected windows are destroyed. You can use the same approach as shown above to obtain a reference to each affected window within the OnWindowDestroyed() method:
Below is another example of adding elements into chart windows. In this example, we add a new panel to the top of all chart windows, then take all existing chart content and move it into a row beneath the panel we’ve just added:
Accessing Account Data
From time to time, you may need to access certain global data, such as account values, order states, position info, etc. In these cases, you can subscribe to an appropriate event using a custom event handler method. Below is a list of a few such events which can be captured:
-
Method
-
Description
-
<account>.AccountItemUpdate
-
Triggers on account item updates
-
<account>.ExecutionUpdate
-
Triggers on any execution
-
<account>.OrderUpdate
-
Triggers on any order state changes
-
<account>.PositionUpdate
-
Triggers on any position updates
Accessing Market Data
Market data can be accessed via a BarsRequest object, which can provide real-time or snapshot data for use by your classes. A BarsRequest object can be loaded with a series of bar data without the need to actually draw bars on a chart. The BarsRequest object can then be accessed via the BarsUpdateEventArgs object passed into your event handler via the BarsRequest’s Update method. The process for using a BarsRequest is as follows:
- Instantiate an Instrument object
- Instantiate and parameterize a BarsRequest object
- Hook the BarsRequest’s Update event to a custom event handler
- Call the BarsRequest’s Request() method
- Access bars data directly from the BarsRequest object within your event handler method

