---
id: "T:cAlgo.API.Functions"
kind: "class"
namespace: "cAlgo.API"
url: "https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# Functions (class)

This class contains valuable functions that apply to DataSeries.

Environments: Desktop supported · CLI supported · Cloud supported.

## Definition

```csharp
public static class Functions
```

## Examples

C#:

```csharp
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    // This sample shows how to use the data series functions
    public partial class DataSeriesFunctionsSample : Indicator
    {
        private SimpleMovingAverage _smaFast, _smaSlow;

        protected override void Initialize()
        {
            _smaFast = Indicators.SimpleMovingAverage(Bars.ClosePrices, 9);
            _smaSlow = Indicators.SimpleMovingAverage(Bars.ClosePrices, 20);
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;

            if (_smaFast.Result.HasCrossedAbove(_smaSlow.Result, 1))
                Print("Fast MA crossed above slow MA");

            if (_smaFast.Result.HasCrossedBelow(_smaSlow.Result, 1))
                Print("Fast MA crossed below slow MA");

            if (_smaFast.Result.Maximum(10) > _smaSlow.Result.Maximum(10))
                Print("Fast MA last 10 values maximum is larger than slow MA last 10 values");

            if (_smaFast.Result.Minimum(10) < _smaSlow.Result.Minimum(10))
                Print("Fast MA last 10 values minimum is smaller than slow MA last 10 values");

            // IsFalling and IsRising compare the last two values of the data series
            if (_smaFast.Result.IsFalling() && _smaSlow.Result.IsRising())
                Print("Fast MA is falling and slow MA is rising");

            if (_smaFast.Result.Sum(10) > _smaSlow.Result.Sum(10))
                Print("Fast MA last 10 values sum is larger than slow MA last 10 values sum");
        }
    }
}
```

Python:

```python
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class DataSeriesFunctionsSample():
    def initialize(self):
        self.fastSma = api.Indicators.SimpleMovingAverage(api.Bars.ClosePrices, 9)
        self.slowSma = api.Indicators.SimpleMovingAverage(api.Bars.ClosePrices, 20)

    def calculate(self, index):
        if not api.IsLastBar:
            return

        if Functions.HasCrossedAbove(self.fastSma.Result, self.slowSma.Result, 1):
            api.Print("Fast MA crossed above slow MA")

        if Functions.HasCrossedBelow(self.fastSma.Result, self.slowSma.Result, 1):
            api.Print("Fast MA crossed below slow MA")

        if Functions.Maximum(self.fastSma.Result, 10) > Functions.Maximum(self.slowSma.Result, 10):
            api.Print("Fast MA last 10 values maximum is larger than slow MA last 10 values")

        if Functions.Minimum(self.fastSma.Result, 10) < Functions.Minimum(self.slowSma.Result, 10):
            api.Print("Fast MA last 10 values minimum is smaller than slow MA last 10 values")

        # IsFalling and IsRising compare the last two values of the data series
        if Functions.IsFalling(self.fastSma.Result) and Functions.IsRising(self.slowSma.Result):
            api.Print("Fast MA is falling and slow MA is rising")

        if Functions.Sum(self.fastSma.Result, 10) > Functions.Sum(self.slowSma.Result, 10):
            api.Print("Fast MA last 10 values sum is larger than slow MA last 10 values sum")
```

config.json:

```json
{
  "AccessRights": "None",
  "TimeZone": "UTC",
  "IsOverlay": true
}
```

## Methods

- `public static bool HasCrossedAbove(DataSeries crossingSeries, DataSeries crossedSeries, int period)` — Returns true, if crossingSeries has crossed above crossedSeries, over the specified Period. [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/HasCrossedAbove/index.md)
- `public static bool HasCrossedAbove(DataSeries crossingSeries, double value, int period)` — Checks if crossingSeries has crossed above value, sometime within the specified period. [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/HasCrossedAbove/index.md)
- `public static bool HasCrossedBelow(DataSeries crossingSeries, DataSeries crossedSeries, int period)` — Returns true, if crossingSeries has crossed below crossedSeries, over the specified Period. [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/HasCrossedBelow/index.md)
- `public static bool HasCrossedBelow(DataSeries crossingSeries, double value, int period)` — Checks if crossingSeries has crossed below the value, sometime within the specified period. [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/HasCrossedBelow/index.md)
- `public static bool IsFalling(DataSeries series)` — Checks if the last value in a data series is less than the previous [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/IsFalling/index.md)
- `public static bool IsRising(DataSeries series)` — Checks if the last value in a data series is greater than the previous. [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/IsRising/index.md)
- `public static double Maximum(DataSeries series, int period)` — Finds the maximum value in a data series for a given period. [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/Maximum/index.md)
- `public static double Minimum(DataSeries series, int period)` — Finds the minimum of a data series for a given period. [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/Minimum/index.md)
- `public static double Sum(DataSeries series, int period)` — Calculates the sum of a data series, over the specified period. [details](https://help.ctrader.com/ctrader-algo/references/Collections/DataSeries/Functions/Sum/index.md)

