Skip to content

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.

Signature

1
public abstract interface DataSeries

Namespace

cAlgo.API

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 [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;
 //...
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 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();
         }
     }
 }

Methods

Last

Summary

Gets the last value of this DataSeries.

Remarks

The last value may represent one of the values of the last bar of the market series, e.g. Open, High, Low and Close. Therefore, take into consideration that on each tick, except the Open price, the rest of the values will most probably change.

Signature

1
public abstract double Last(int index)

Parameters

Name Type Description
index int

Return Value

double

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 //...
 protected override void OnTick()
 {
     double lastValue = MarketSeries.Close.LastValue;
        Print("The last value of MarketSeries.Close Series is: {0}", MarketSeries.Close.LastValue);
     // Property LastValue has an accessor but no setter, i.e. LastValue can be retrieved but not set.
     // The following code will produce an error
     MarketSeries.Close.LastValue = 100;
 }
 //...

Properties

Item

Signature

1
public abstract double Item {get;}

Return Value

double

LastValue

Summary

Gets the last value of this DataSeries.

Remarks

The last value may represent one of the values of the last bar of the market series, e.g. Open, High, Low and Close. Therefore, take into consideration that on each tick, except the Open price, the rest of the values will most probably change.

Signature

1
public abstract double LastValue {get;}

Return Value

double

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 //...
 protected override void OnTick()
 {
     double lastValue = MarketSeries.Close.LastValue;
        Print("The last value of MarketSeries.Close Series is: {0}", MarketSeries.Close.LastValue);
     // Property LastValue has an accessor but no setter, i.e. LastValue can be retrieved but not set.
     // The following code will produce an error
     MarketSeries.Close.LastValue = 100;
 }
 //...

Count

Summary

Gets the total number of elements contained in the DataSeries.

Signature

1
public abstract int Count {get;}

Return Value

int

Examples

1
2
3
4
5
6
7
8
9
 protected override void OnTick()
 {
     int total = MarketSeries.Close.Count;
     Print("The total elements contained in the MarketSeries.Close Series is: {0}", total);
     int lastIndex = total - 1;
     double lastCloseValue = MarketSeries.Close[lastIndex];
        //Print the last value of the series
     Print("The last value of Close Series is: {0}", lastCloseValue);
 }