Skip to content

Algorithm SDK

Math.average

The mean (average) of a list of numbers. Cloud9Trader adds it to JavaScript’s built-in Math.

average(x: number[]): number;
  • x: an array of numbers, such as the result of prices().

The same as Math.mean. Math.average(prices(20)) is the 20-bar simple moving average.

Stops the run if x is not an array: “Value passed to Math.average() must be an array of numbers”.

function onIntervalClose() {
log("average", Math.average(prices(20)));
}