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.

[fon‌t=Arial Unicode MS]►[/font]
Sample 1 – Using the strategy UserDefinedMethods.cs file
[fon‌t=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.

[fon‌t=Arial Unicode MS]•[/font]
There is one UserDefinedMethods.cs file that contain your user defined methods for custom strategies
[fon‌t=Arial Unicode MS]•[/font]
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.

[Image: user_defined_methods_1.png]

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.

[fon‌t=Arial]1.[/font]
Via Tools–>Edit NinjaScript–>Indicators open the “UserDefinedMethods” file
[fon‌t=Arial]2.[/font]
From within the NinjaScript Editor, right click and select the menu “Save As…”
[fon‌t=Arial]3.[/font]
From within the Dialog window, enter a name, for example “MyMethod”

[fon‌t=Arial]4.[/font]
Add your user defined method and then compile

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.