NinjaScript > Language Reference > Data >

Add()

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
Adds a Bars object to an indicator or strategy for developing a multi-series (multi-time frame or multi-instrument) NinjaScript. When running NinjaScript, you will be able to choose the primary instrument and bar interval to run on. This primary Bars object will carry a BarsInProgress index of 0. In a multi-time frame and multi-instrument NinjaScript, supplementary Bars objects are added via this method in the Initialize() method and given an incremented BarsInProgress index value. See additional information on running multi-series scripts.

 

* For adding Bars of special types please use these methods:
AddKagi()

AddLineBreak()

AddPointAndFigure()

AddRenko()

 

 

Syntax

The following syntax will add another Bars object to the strategy for the primary instrument of the script.
Add(PeriodType periodType, int period)

 

The following syntax allows you to add another Bars object for a different instrument to the script.
Add(string instrumentName, PeriodType periodType, int period)

Add(string instrumentName, PeriodType periodType, int period, MarketDataType marketDataType)

 

NOTE: You can optionally add the exchange name as a suffix to the symbol name. This is only advised if the instrument has multiple possible exchanges that it can trade on and it is configured within the Instrument Manager. For example: Add("MSFT Arca", PeriodType.Minute, 5).

 

 

Parameters

instrumentName

An instrument name such as "MSFT"

periodType

The period type of the bar such as:
PeriodType.Day
PeriodType.Minute

PeriodType.Range

PeriodType.Second
PeriodType.Tick
PeriodType.Volume

period

The period interval such as "3" for 3 minute bars

marketDataType

Possible values are:

MarketDataType.Ask

MarketDataType.Bid

MarketDataType.Last

 

* Please see the article here on using Bid/Ask series.

 

 

Examples

protected override void Initialize()
{
    // Add a 5 minute Bars object - BarsInProgress index = 1
    Add(PeriodType.Minute, 5);

 

    // Add a 100 tick Bars object for the ES 12-06 contract - BarsInProgress index = 2
    Add("ES 12-06", PeriodType.Tick, 100);
}
 
protected override void OnBarUpdate()
{
    // Ignore bar update events for the supplementary Bars object added above
    if (BarsInProgress == 1 || BarsInProgress == 2)
        return;
 
    // Go long if we have three up bars on all bars objects
    if (Close[0] > Open[0] && Closes[1][0] > Opens[1][0] && Closes[2][0] > Opens[2][0])
         EnterLong();
}