You can create user defined methods (global methods or functions) that can be accessed by all custom indicators and strategies. User defined methods should ONLY be created if you intend to re-use these methods over and over again across different custom indicators or strategies. Otherwise, just code your method logic directly into your indicator or strategy.
[font=Arial Unicode MS]►[/font]
Sample 1 – Using the strategy UserDefinedMethods.cs file
[font=Arial Unicode MS]►[/font]
Sample 2 – Using a separate file for user defined methods
UserDefinedMethods.cs
You can define and manage all of your user defined methods from within one of two available UserDefinedMethods.cs files.
There is one UserDefinedMethods.cs file that contain your user defined methods for custom strategies
There is one UserDefinedMethods.cs file that contain your user defined methods for custom indicators
You can not share user defined methods created for custom strategies with custom indicators. You can edit and manage the UserDefinedMethods.cs file via Tools–>Edit NinjaScript–>Indicators or Tools–>Edit NinjaScript–>Strategies menus from within the NinjaTrader Control Center window.
UserDefinedMethods.cs files have unique icons in the Indicators or Strategy Dialog windows.
Creating A Separate File Per User Defined Method (Function)
If you do not want to have one file that manages all of your user defined methods, you can create a separate file for each user defined method.
Via Tools–>Edit NinjaScript–>Indicators open the “UserDefinedMethods” file
From within the NinjaScript Editor, right click and select the menu “Save As…”
From within the Dialog window, enter a name, for example “MyMethod”
[font=Arial]4.[/font]
Add your user defined method and then compile