NinjaScript > Language Reference > Data >

IntSeries Class

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
An IntSeries is a special type of data structure that holds a series of int values and always contains the same number of elements as bars in a chart. See the DataSeries Class for related information.

 

Creating IntSeries Objects

To create a IntSeries object:

 

1.Define a variable ("myIntSeries" used in this example) of type IntSeries that will hold a IntSeries object
2.In the Initialize() method, create a new IntSeries object and assign it to the "myIntSeries" variable

 

#region Variables
private IntSeries myIntSeries; // Define a IntSeries variable
#endregion

 

// Create a IntSeries object and assign it to the variable
protected override void Initialize()
{
    myIntSeries = new IntSeries(this); // "this" refers to the indicator, or strategy
                                      // itself. This syncs the IntSeries object
                                       // to historical data bars
}

 

* IntSeries objects can be used on supplementary series in a multi-time frame and instrument strategy. Please see our support forum NinjaScript reference samples section for further information.

 

Note: By default NinjaTrader limits the number of values stored for IntSeries objects to 256. This drastically improves memory performance by not holding onto old values that are generally not needed. Should you need more values than the last 256 please be sure to create the IntSeries object so that it stores all values instead through the use of the MaximumBarsLookBack property.

 

#region Variables
private IntSeries myIntSeries; // Define a IntSeries variable
#endregion

 

// Create a IntSeries object and assign it to the variable
protected override void Initialize()
{

    // MaximumBarsLookBack determines how many values the IntSeries will have access to
    myIntSeries = new IntSeries(this, MaximumBarsLookBack.Infinite);
}

 

Setting Values - IntSeries.Set() & IntSeries.Reset()
You can set value (plug in a value) into a IntSeries object by calling the Set() method.

 

IntSeries.Set(int value)

Setting a value on a IntSeries object is automatically aligned to the current bar being evaluated. This ensures values across all IntSeries objects are always in sync by the CurrentBar index. The following code samples demonstrates calculating the range of each bar and storing the value in an IntSeries object.

 

protected override void OnBarUpdate()
{
    int rangeInTicks = (int) ((High[0] - Low[0]) / TickSize);
    myIntSeries.Set(rangeInTicks);
}

 

IntSeries.Set(int barsAgo, int value)
You can also set the value for historical bars by including a "barsAgo" value that represents the number of bars ago that you want the bool value to be stored at.

 

Calling the Reset() method is unique and can be very powerful for custom indicator development. IntSeries objects can hold null values which simply means that you do not want to store a value for the current bar. Reset() will reset the current index value to null.

 

 

Checking for Valid Values
It is possible that you may use an IntSeries object but decide not to set a value for a specific bar. However, you should not try to access a IntSeries value that has not been set. Internally, a dummy value does exists, but you want to check to see if it was a valid value that you set before trying to access it for use in your calculations.

 

IntSeries.ContainsValue(int barsAgo)
Returns a true or false value.
 
 

Getting Values
You can access IntSeries object values using the syntax IntSeries[int barsAgo] where barsAgo represents the data value n number of bars ago.

 

protected override void OnBarUpdate()
{
    // Prints the current and last bar value
    Print("The values are " + myIntSeries[0] + " " + myIntSeries[1]);
}