NinjaScript > Educational Resources > Tips >

User Defined Methods

Print this Topic Previous pageReturn to chapter overviewNext page

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.

 

 

Sample 1 - Using the strategy UserDefinedMethods.cs file
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.

 

User_Defined_Methods_1

 

 

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.

 

1.Via Tools-->Edit NinjaScript-->Indicators open the "UserDefinedMethods" file
2.From within the NinjaScript Editor, right click and select the menu "Save As..."
3.From within the Dialog window, enter a name, for example "MyMethod"
4.Add your user defined method and then compile