series(var value, int length) : vars

Creates a series of the given length, fills it with the given value, and returns the pointer to the series. A series is an array that contains the history of a variable. It is normally used by indicators or script functions. Every element of the array corresponds to a bar in the price chart: the [0] element to the most recent bar, the [1] element to one bar ago and so on.

Parameters:

value Optional data value of the series. When omitted, the series is filled with 0 values.
length Optional number of elements of the series; must not change once set. When omitted or 0, the series gets the length of LookBack. A negative number allocates a static series - a normal var array that is not shifted or filled.

Returns:

Pointer to the var array (the vars type is just a var* pointer).

Usage:

vars Close = series(priceClose()); returns a series that contains the close prices of the current asset.

Remarks:

Examples:

// create a series with the high-low price differences
vars PriceRange = series(priceHigh()-priceLow());
 
// compare the current range with the range from 3 bars ago
if(PriceRange[0] > PriceRange[3])
  ...
 
// calculate a 20-bar Simple Moving Average containing the price differences from 5 bars ago
var Average5 = SMA(PriceRange+5,20);


// wrong use of conditional series
if(priceClose() > Threshold) {
  vars X = series(priceClose()); // error message!
  vars Y = series(SMA(X,100)); // error message!
  ...
}

// correct use of conditional series
vars X = series(), Y = series();
if(priceClose() > Threshold) {
  X[0] = priceClose(); // ok!
  Y[0] = SMA(X,100);
  ...
}

See also:

price, sort, rev, diff

► latest version online