FloatSeries Class
Previous Topic  Next Topic 

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


Creating FloatSeries Objects

To create a FloatSeries object:


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

#region Variables
    private FloatSeries myFloatSeries; // Define a FloatSeries variable
#endregion

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

* FloatSeries 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.


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


FloatSeries.Set(float value)

Setting a value on a FloatSeries object is automatically aligned to the current bar being evaluated. This ensures values across all FloatSeries 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 FloatSeries object.


protected override void OnBarUpdate()
{
    float range = (float) High[0] - Low[0];
    myFloatSeries.Set(range);
}

FloatSeries.Set(int barsAgo, bool 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. FloatSeries 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 FloatSeries object but decide not to set a value for a specific bar. Internally, a dummy value does exist however, if you wanted to check to see if it was a valid value that you set, you can check the following method.


FloatSeries.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 " + myFloatSeries[0] + " " + myFloatSeries[1]);
}