NinjaScript > Language Reference > Data >


Print this Topic Previous pageReturn to chapter overviewNext page

The Initialize() method is called once when starting a strategy. This method can be used to configure indicator and strategy properties.
For example:


Strategies - Call the Add() method to add indicators to charts and to add additional Bars objects to the strategy
Indicators - Set configuration properties such as Overlay and PaintPriceMarkers
Although this method is called once on the start of an indicator or strategy, there are times that this method is also called (Opening an indicator dialog) when you may not expect it to. FOR ADVANCED PROGRAMMERS, DO NOT USE THIS METHOD TO RUN CUSTOM ROUTINES SUCH AS OPENING FORMS, MAKING EXTERNAL CALLS SUCH AS A LICENSE CHECK. PLEASE USE OnStartUp() FOR THOSE PURPOSES.


Method Return Value

This method does not return a value.


See example below. The NinjaScript indicator and strategy wizards automatically generate the method syntax for you.


protected override void Initialize()
    // Adds a 5-minute Bars object to the strategy and is automatically assigned
    // a Bars object index of 1 since the primary data the strategy is run against
    // set by the UI takes the index of 0.
    Add(Instrument, PeriodType.Minute, 5);