Skip to content

Functions

Summary

This class contains valuable functions that apply to DataSeries.

Signature

1
public static class Functions

Namespace

cAlgo.API

Methods

Name Description
IsRising Checks if the last value in a dataseries is greater than the previous.
IsFalling Checks if the last value in a dataseries is less than the previous
Maximum Finds the maximum value in a dataseries for a given period.
Minimum Finds the minimum of a dataseries for a given period.
HasCrossedAbove Checks if dataseries1 has crossed above value, sometime within the specified period.
HasCrossedBelow Checks if dataseries1 has crossed below the value, sometime within the specified period.
Sum Calculates the sum of a dataseries, over the specified period.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 //...
 SimpleMovingAverage sma;
 protected override void Initialize()
 {
     sma = Indicators.SimpleMovingAverage(source, period);
 }
 public override void Calculate(int index)
 {
     // IsRising returns true if the current value is greater
     // than the previous value in the data series
     if (Functions.IsRising(sma.Result))
     {
         //Do something
     }
     // IsFalling returns true if the current value is less
     // than the previous value in the data series
     else if(Functions.IsFalling(sma.Result))
     {
         // Do something else
     }
     else // sma is level
     {
         Do something else
     }
     //...
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 using cAlgo.API;
 using cAlgo.API.Indicators;
 namespace cAlgo
 {
     // This sample shows how to use the data series functions
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public 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 (_smaFast.Result.HasCrossedAbove(_smaSlow.Result, 1))
             {
                 // Fast MA crossed above slow MA
             }
             if (_smaFast.Result.HasCrossedBelow(_smaSlow.Result, 1))
             {
                 // Fast MA crossed below slow MA
             }
             if (_smaFast.Result.Maximum(10) > _smaSlow.Result.Maximum(10))
             {
                 // Fast MA last 10 values maximum is larger than slow MA last 10 values
             }
             if (_smaFast.Result.Minimum(10) < _smaSlow.Result.Minimum(10))
             {
                 // Fast MA last 10 values minimum is smaller than slow MA last 10 values
             }
             if (_smaFast.Result.IsFalling() && _smaSlow.Result.IsRising())
             {
                 // Fast MA is falling and slow MA is raising
                 // IsFalling and IsRising compares last two values of the data series
             }
             if (_smaFast.Result.Sum(10) > _smaSlow.Result.Sum(10))
             {
                 // Fast MA last 10 values sum is larger than slow MA last 109 values sum
             }
         }
     }
 }

Last update: July 1, 2022

Comments