Functions
What is a Function?
A function executes a specific mathematical formula on a specific set of data that has been provided by you; a function can accept one or multiple parameters.
Each function must start with a '$' symbol. For function parameters that are single numeric values mathematical expressions can be used.
Abs
This function receives a numeric value and returns its absolute value:
$abs(-2)
Mathematical expressions can also be used inside it like this:
$abs(-2 - 2)
Or:
$abs(current.current.low[0] - current.current.high[1])
Avg
This is the mean or average function; it receives a vector and returns a single value which is the average value of that vector:
$avg(current.current.close[0:10])
Corr
This function returns the Pearson correlation coefficient value of two vectors; you have to provide two vectors as parameters for this function:
$corr(current.current.close[0:10], gbpusd.current.close[0:10])
Cov
This function returns the covariance value of two vectors; you have to provide two vectors as parameters for this function:
$cov(current.current.close[0:10], gbpusd.current.close[0:10])
Kurtosis
This function returns the Kurtosis value of a vector:
$kurtosis(current.current.close[0:10])
Min/Max
These two functions are used to return the minimum or maximum values on a vector; it can be used like this:
$min(current.current.close[0:20]) + $max(current.current.close[0:20])
Meanmoment
This function returns the mean moment of a vector; it receives two parameters, the first one is a vector and the second one is a numeric value which represents the moment:
$meanmoment(current.current.close[0:20], 4)
Median
This function returns the median value of a vector:
$median(current.current.close[0:10])
Percentile
This function returns the x% value inside a vector; it receives two parameters, the first one is a vector and the second one is a numeric percentage value:
$percentile(current.current.close[0:10], 50)
Pow
The power was previously missing in cFormula's supported operators. The Pow functions allows you to easily access a pow of a number. It has two numeric parameters, the first one is the number that will be raised to a power and the second one is the power number:
$pow(current.current.low[0] - current.current.high[0], 2)
Range
This function returns the range of a vector, or the maximum value - minimum value:
$range(current.current.low[0: 10])
Rank
This function returns the percentile rank of a value inside a vector. It receives two parameters, the first one is a vector and the second one is the number whose rank you wish to know:
$rank(current.current.low[0: 10], 1)
Skewness
This function returns the skewness of a vector:
$skewness(current.current.low[0: 10])
Sqrt
This function returns the square root of a number:
$sqrt(current.current.low[0])
Or
$sqrt(16)
Std
This function returns the standard deviation of a vector:
$std(current.current.close[0:10])
Sum
This function returns the sum of a vector:
$sum(current.current.close[0:10])
Var
This function returns the variance of a vector:
$var(current.current.close[0:10])
Using Functions in Formulas
You can combine multiple functions in a single formula with other mathematical expressions:
$sum(current.current.close[0:10]) + 2 / $sqrt($abs(-16))
More Formulas
If you need any other function please let us know, and we will add them in.