Skip to content

Functions

class cAlgo.API

DesktopCLICloud

This class contains valuable functions that apply to DataSeries.

Definition

public static class Functions

Namespace: cAlgo.API · Group: Data Series

Examples

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");
        }
    }
}
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")
{
  "AccessRights": "None",
  "TimeZone": "UTC",
  "IsOverlay": true
}

Methods

Name Description
HasCrossedAbove 2 overloadsDesktopCLICloudbool Returns true, if crossingSeries has crossed above crossedSeries, over the specified Period.
HasCrossedBelow 2 overloadsDesktopCLICloudbool Returns true, if crossingSeries has crossed below crossedSeries, over the specified Period.
IsFallingDesktopCLICloudbool Checks if the last value in a data series is less than the previous
IsRisingDesktopCLICloudbool Checks if the last value in a data series is greater than the previous.
MaximumDesktopCLIClouddouble Finds the maximum value in a data series for a given period.
MinimumDesktopCLIClouddouble Finds the minimum of a data series for a given period.
SumDesktopCLIClouddouble Calculates the sum of a data series, over the specified period.