usingcAlgo.API;namespacecAlgo{// This sample shows how to work with data series[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassTest: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();}}}
123456789
""" Source and Result are two data series defined as parameter and output in indicator C# file, ex: [Parameter] public DataSeries Source { get; set; } [Output("Main")] public IndicatorDataSeries Result{ get; set; } """api.Result[index]=api.Source[index]*exp+previousValue*(1-exp)api.Result[index]=(api.Bars.ClosePrices[index]+api.Bars.OpenPrices[index])/2
import clr
clr.AddReference("cAlgo.API")
from cAlgo.API import *
# Source is a parameter of type DataSeries defined in C# file of indicator
class Test():
def initialize(self):
grid = Grid(3, 2)
grid.BackgroundColor = Color.DarkGoldenrod
grid.HorizontalAlignment = HorizontalAlignment.Left
grid.VerticalAlignment = VerticalAlignment.Bottom
grid.Opacity = 0.5
grid.AddChild(self.get_text_block("Last Value"), 0, 0)
self.lastValueTextBlock = self.get_text_block(str(api.Source.LastValue))
grid.AddChild(self.lastValueTextBlock, 0, 1)
grid.AddChild(self.get_text_block("Last Closed Value"), 1, 0)
self.lastClosedValueTextBlock = self.get_text_block(str(api.Source.Last(1)))
grid.AddChild(self.lastClosedValueTextBlock, 1, 1)
grid.AddChild(self.get_text_block("Values Count"), 2, 0)
self.countTextBlock = self.get_text_block(str(api.Source.Count))
grid.AddChild(self.countTextBlock, 2, 1)
api.Chart.AddControl(grid)
def calculate(self, index):
# You can also use "LastValue" property if you don't have index
self.lastValueTextBlock.Text = str(api.Source[index])
# You can also use "Last(1)" property if you don't have index
self.lastClosedValueTextBlock.Text = str(api.Source[index - 1])
self.countTextBlock.Text = str(api.Source.Count)
def get_text_block(self, text):
textBlock = TextBlock()
textBlock.Text = text
textBlock.Margin = Thickness(5)
return textBlock
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
publicabstractdoubleLast(intindex)
Parameters
Name
Type
Description
index
int
Return Value
double
Examples
12345678
protectedoverridevoidOnTick(){doublelastValue=Bars.ClosePrices.LastValue;Print("The last value of Bars.ClosePrices Series is: {0}",Bars.ClosePrices.LastValue);// Property LastValue has an accessor but no setter, i.e. LastValue can be retrieved but not set.// The following code will produce an errorBars.ClosePrices.LastValue=100;}
123456
defon_tick(self):lastValue=api.Bars.ClosePrices.LastValueprint(f"The last value of Bars.ClosePrices Series is: {api.Bars.ClosePrices.LastValue}")# Property LastValue has an accessor but no setter, i.e. LastValue can be retrieved but not set.# The following code will produce an errorapi.Bars.ClosePrices.LastValue=100
Properties
Item
Signature
1
publicabstractdoubleItem{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
publicabstractdoubleLastValue{get;}
Return Value
double
Examples
12345678
protectedoverridevoidOnTick(){doublelastValue=Bars.ClosePrices.LastValue;Print("The last value of Bars.ClosePrices Series is: {0}",Bars.ClosePrices.LastValue);// Property LastValue has an accessor but no setter, i.e. LastValue can be retrieved but not set.// The following code will produce an errorBars.ClosePrices.LastValue=100;}
123456
defon_tick(self):lastValue=api.Bars.ClosePrices.LastValueprint(f"The last value of Bars.ClosePrices Series is: {api.Bars.ClosePrices.LastValue}")# Property LastValue has an accessor but no setter, i.e. LastValue can be retrieved but not set.# The following code will produce an errorapi.Bars.ClosePrices.LastValue=100
Count
Summary
Gets the total number of elements contained in the DataSeries.
Signature
1
publicabstractintCount{get;}
Return Value
int
Examples
123456789
protectedoverridevoidOnTick(){inttotal=Bars.ClosePrices.Count;Print("The total elements contained in the Bars.ClosePrices Series is: {0}",total);intlastIndex=total-1;doublelastCloseValue=Bars.ClosePrices[lastIndex];//Print the last value of the seriesPrint("The last value of Close Series is: {0}",lastCloseValue);}
1234567
defon_tick(self):total=api.Bars.ClosePrices.Countprint(f"The total elements contained in the Bars.ClosePrices Series is: {total}")lastIndex=total-1lastCloseValue=api.Bars.ClosePrices[lastIndex]# Print the last value of the seriesprint(f"The last value of Close Series is: {lastCloseValue}")