series(var Value, int Length): vars

Creates a time series of the given Length with the given Value, and returns the pointer to the series. A series is a var array that contains the history of the variable. It is normally used by indicators in algorithmic trading. Series can be static or dynamic. Dynamic series are automatically shifted at every time frame, so that every element corresponds to a certain bar or time frame; the [0] element to the value at the current bar or time frame, the [1] element to the value from one bar or time frame ago, and so on. If a series is static by giving a negative Length, or if the NOSHIFT flag is set, the series is not shifted.

Parameters:

Value Optional data value of the series. The series is initially filled with this value, otherwise with 0.
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 that can be shifted by script with the shift function.

Returns:

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

Usage:

vars Prices = series(price()); defines a series with the length of the LookBack period that contains the mean prices of the current asset
 

ref(var Value, int Index): var

Convenience macro that generates a series and returns the Value from Index time frames ago. All macros are defined in variables.h.
 

SeriesLength

int, r/o, containing the number of elements of the date series returned by the last series() call.

SeriesBuffer

var* pointer that can be set to a memory area, and will then be returned by the next series call (lite-C only). After a series call it is set to the returned pointer. This allows to use static or pre-filled buffers for a series. For an example, see Financial Hacker: Truncated Indicators.
  

Remarks:

Examples:

// create a series with the high-low price differences
vars PriceRanges = series(priceH()-priceL());
 
// compare the current range with the range from 3 bars ago
if(PriceRanges[0] > PriceRanges[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);
  ...
}

// exclude out-of-market bars from a series
if(!market(EST,0)) set(NOSHIFT);
vars InMarketPrices = series(priceC());
set(NOSHIFT|OFF);

// use arrays of series
vars MySeriesArray[3]; // declare an array of series 
...
for(i=0; i<3; i++) 
  MySeriesArray[i] = series(); // fill the array with series 
...
(MySeriesArray[0])[0] = 123; // access the first element of the first series. Mind the parentheses!

See also:

price, sort, rev, diff, shift, sync ► latest version online