usingcAlgo.API;namespacecAlgo{// This sample shows how to work with data series[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassDataSeriesSample:Indicator{privateTextBlock_lastValueTextBlock;privateTextBlock_lastClosedValueTextBlock;privateTextBlock_countTextBlock;[Parameter()]publicDataSeriesSource{get;set;}protectedoverridevoidInitialize(){vargrid=newGrid(3,2){BackgroundColor=Color.DarkGoldenrod,HorizontalAlignment=HorizontalAlignment.Left,VerticalAlignment=VerticalAlignment.Bottom,Opacity=0.5};grid.AddChild(newTextBlock{Text="Last Value",Margin=5},0,0);_lastValueTextBlock=newTextBlock{Text=Source.LastValue.ToString(),Margin=5};grid.AddChild(_lastValueTextBlock,0,1);grid.AddChild(newTextBlock{Text="Last Closed Value",Margin=5},1,0);_lastClosedValueTextBlock=newTextBlock{Text=Source.Last(1).ToString(),Margin=5};grid.AddChild(_lastClosedValueTextBlock,1,1);grid.AddChild(newTextBlock{Text="Values Count",Margin=5},2,0);_countTextBlock=newTextBlock{Text=Source.Count.ToString(),Margin=5};grid.AddChild(_countTextBlock,2,1);Chart.AddControl(grid);}publicoverridevoidCalculate(intindex){// 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();}}}
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
publicabstractdoubleLast(intindex)
Parameters
Name
Type
Description
index
int
Return Value
double
Examples
1 2 3 4 5 6 7 8 910
//...protectedoverridevoidOnTick(){doublelastValue=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 errorMarketSeries.Close.LastValue=100;}//...
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
publicabstractdoubleLastValue{get;}
Return Value
double
Examples
1 2 3 4 5 6 7 8 910
//...protectedoverridevoidOnTick(){doublelastValue=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 errorMarketSeries.Close.LastValue=100;}//...
Gets the total number of elements contained in the DataSeries.
Signature
1
publicabstractintCount{get;}
Return Value
int
Examples
123456789
protectedoverridevoidOnTick(){inttotal=MarketSeries.Close.Count;Print("The total elements contained in the MarketSeries.Close Series is: {0}",total);intlastIndex=total-1;doublelastCloseValue=MarketSeries.Close[lastIndex];//Print the last value of the seriesPrint("The last value of Close Series is: {0}",lastCloseValue);}