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

Methods

Name Description
Last Gets the last value of this DataSeries.

Properties

Name Description
Item { get; }
LastValue { get; } Gets the last value of this DataSeries.
Count { get; } Gets the total number of elements contained in the DataSeries.

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();
         }
     }
 }

Last update: July 1, 2022

Comments