DataSeries


Summary

Represents a read only list of values, typically used to represent market price series. The values are accessed with an array-like [] operator.

Syntax

public interface DataSeries : IEnumerable

Members

NameTypeSummary
Count PropertyGets the total number of elements contained in the DataSeries.
Last MethodAccess a value in the dataseries certain bars ago
LastValue PropertyGets the last value of this DataSeries.
this[int index] PropertyGets the value in the dataseries at the specified position.

Example 1

[Parameter]
public DataSeries Source { get; set; }
//...
[Output("Main")]
public IndicatorDataSeries Result{ get; set; }
//...
Result[index] = Source[index] * exp + previousValue * (1 - exp);
//...
Result[index] = (MarketSeries.Close[index] + MarketSeries.Open[index]) / 2;
//...

Example 2

using cAlgo.API;
namespace cAlgo
{
    // This sample shows how to work with data series
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DataSeriesSample : Indicator
    {
        private TextBlock _lastValueTextBlock;
        private TextBlock _lastClosedValueTextBlock;
        private TextBlock _countTextBlock;
        [Parameter()]
        public DataSeries Source { get; set; }
        protected override void Initialize()
        {
            var grid = new Grid(3, 2)
            {
                BackgroundColor = Color.DarkGoldenrod,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Bottom,
                Opacity = 0.5
            };
            grid.AddChild(new TextBlock
            {
                Text = "Last Value",
                Margin = 5
            }, 0, 0);
            _lastValueTextBlock = new TextBlock
            {
                Text = Source.LastValue.ToString(),
                Margin = 5
            };
            grid.AddChild(_lastValueTextBlock, 0, 1);
            grid.AddChild(new TextBlock
            {
                Text = "Last Closed Value",
                Margin = 5
            }, 1, 0);
            _lastClosedValueTextBlock = new TextBlock
            {
                Text = Source.Last(1).ToString(),
                Margin = 5
            };
            grid.AddChild(_lastClosedValueTextBlock, 1, 1);
            grid.AddChild(new TextBlock
            {
                Text = "Values Count",
                Margin = 5
            }, 2, 0);
            _countTextBlock = new TextBlock
            {
                Text = Source.Count.ToString(),
                Margin = 5
            };
            grid.AddChild(_countTextBlock, 2, 1);
            Chart.AddControl(grid);
        }
        public override void Calculate(int index)
        {
            // You can also use "LastValue" property if you don't have index
            _lastValueTextBlock.Text = Source[index].ToString();
            // You can also use "Last(1)" property if you don't have index
            _lastClosedValueTextBlock.Text = Source[index - 1].ToString();
            _countTextBlock.Text = Source.Count.ToString();
        }
    }
}
Reference