Skip to content

Indicator

Summary

Base class for Indicators.

Remarks

Contains all necessary market information, provides access to built-in indicators and provides framework for convenient indicators' creation.

Signature

1
public abstract class Indicator : Algo

Namespace

cAlgo.API

Examples

1
2
3
4
5
6
 //...
 public override void Calculate(int index)
 {
     //This is where we place our indicator's calculation logic.
 }
 //...
1
2
3
4
5
6
 //...
 protected override void Initialize()
 {
 //Place your Initialization logic here
 }
 //...
1
2
3
4
5
6
7
8
9
 private IndicatorDataSeries input;
 protected override void Initialize()
 {
     input = CreateDataSeries();
 }
 public override void Calculate(int index)
 {
     input[index] = (MarketSeries.Close[index] + MarketSeries.Open[index]) / 2;
 }
1
2
3
4
5
6
7
8
9
 //...
 public override void Calculate(int index)
 {
     if (IsRealTime)
     {
         //Place the code-logic that you want to be calculated on incoming live data
     }
 }
 //...

Methods

Calculate

Summary

Calculate the value(s) of indicator for the given index.

Signature

1
public abstract void Calculate(int index)

Parameters

Name Type Description
index int The index of calculated value.

Return Value

void

Examples

1
2
3
4
5
6
 //...
 public override void Calculate(int index)
 {
     //This is where we place our indicator's calculation logic.
 }
 //...

ToString

Summary

The name of the indicator derived class.

Signature

1
public string ToString()

Return Value

string

Examples

1
2
3
4
 private SampleSMA sma;
 //...
 sma = Indicators.GetIndicator<SampleSMA>(Source, Period);
 Print(sma.ToString());

Properties

IsRealTime

Signature

1
public bool IsRealTime {get;}

Return Value

bool

IsLastBar

Summary

Returns true, if Calculate is invoked for the last bar

Signature

1
public bool IsLastBar {get;}

Return Value

bool

Examples

1
2
3
4
5
6
7
 public override void Calculate(int index)
{
    if (IsLastBar)
    {
        // this is the current (last) index
    }
}

IndicatorArea

Summary

Defines the area where the indicator is placed.

Signature

1
public IndicatorArea IndicatorArea {get;}

Return Value

IndicatorArea

Account

Summary

Contains information of the current account.

Signature

1
public IAccount Account {get;}

Return Value

IAccount

Examples

1
2
 if (Account.Balance < 10000)
     Print(Account.Balance);