Skip to main content Skip to footer

A Series is a special generic type of data structure that can be constructed with any chosen data type and holds a series of values equal to the same number of elements as bars in a chart.

Series had direct indexing, i.e. Series[0] contains the oldest data. But it is possible to use backward indexing with help of Indexer function of CalculationContext parameter inside OnCalculate function.

For series there are 3 important points: start of series, end of series and current calculating bar. Current calculating bar is changing on every call of OnCalculate function and Indexer[0] returns element at current calculating bar, not the end of the series.

The following snippet of the code shows how to set value to the current calculating element of Series _main

 protected override void OnCalculate(CalculateContext ctx)
 {
      // Write your specific code to calculate indicator values
      ctx.Indexer(_main)[0] = 0;
      // or ctx.SetValue(_main, 0, 0);
      // or _main.SetValueAt(ctx.CurrentBarIndex, 0);

}

Series elements are calculeted only by request. For example if to ask value at 300th bar it will check if this value was calculated. If it was not, then it will be calculated up to 300th bar, not further. 

Each element of a Series has a property IsValid, that checks whether value was set to an element or not.

As Indicator is inherited from ISeries interface, it can be passed to another indicator or strategy as abstract data source.

Cookies Notice

We use cookies to improve your experience, personalize content, and analyze our traffic. By clicking "Accept All Cookies," you agree to the storing of cookies on your device. You can manage your cookie preferences at any time by visiting our Cookie Settings.