NinjaScript > Language Reference > Data >
Creating DataSeries Objects
When creating custom indicators, DataSeries objects are automatically created for you by calling the Add() method and can be subsequently referenced by the Value and/or Values property. However, you may have a requirement to create a DataSeries object to store values that are part of an overall indicator value calculation. This can be done within a custom indicator or strategy.
To create a DataSeries object:
* DataSeries 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 DataSeries 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 DataSeries object so that it stores all values instead through the use of the MaximumBarsLookBack property.
Setting Values - DataSeries.Set() & DataSeries.Reset()
Setting a value on a DataSeries object is automatically aligned to the current bar being evaluated. This ensures values across all DataSeries 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 a DataSeries object.
DataSeries.Set(int barsAgo, double value)
Calling the Reset() method is unique and can be very powerful for custom indicator development. DataSeries objects can hold dummy values (usually the Input series for the script which generally would be the Close price) which simply means that you do not want to store a value for the current bar. Reset() method allows you to effectively ignore the value of the current bar for plotting purposes. For calculation purposes you will want to use .ContainsValue() to ensure you are not calculating off of any dummy values assigned by the Reset() method.
Checking for Valid Values
Methods that Accept DataSeries as Arguments