Skip to content

Last Method

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

Declaring Type

cAlgo.API.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: March 23, 2023