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. |

- Series follow a similar concept as serial variables in other trading platforms such as TradeStation™. The
**n**-th element of a series is accessed by adding a**[n]**to the series name, where**n**is a positive integer number. For instance,**myseries[0]**is the latest element,**myseries[1]**is the element of one time frame ago, and so on.**n**must always be positive and smaller than the series length. - Series are created after the first run of the strategy, when the price data of the asset have been loaded. They are then filled with the given
**value**. Afterwards they are updated after every bar, so the**[0]**element becomes the**[1]**element, the**[1]**element becomes the**[2]**element and so on. The current**value**becomes the new**[0]**element. Due to this mechanism, a series contains its elements in reverse chronological order with the most recent element at the start. - For shifting a series into the past, add an offset
**+n**. This creates a pointer onto the**n**-th element of the series. For instance,**(myseries+1)**is**myseries**shifted by 1 bar offset into the past, excluding the last element**myseries[0]**. This allows to access series elements in different ways; for instance,**myseries[3]**is the same as**(myseries+2)[1]**and the same as**(myseries+3)[0]**. As the offset**+n**lets the series begin at the**n**th element, it reduces the available length of the series by**n**. When calling an indicator with a series with an offset, make sure that LookBack is always higher than the required lookback period of the function plus the unstable period plus the highest possible offset of the series. Otherwise the script will issue an error message. - Series can be synchronized to external events or to longer time frames. For this, set the TimeFrame variable accordingly before the
**series()**call, and reset it afterwards. The element**[n]**then corresponds to the**n**th event or time frame in the past. - For adding or subtracting two series, create a series of the sum or difference of the recent elements, f.i.
**vars Sum = series(Data1[0] + Data2[0]);**. - Some functions expect a single value, other functions expect a whole series as parameter. When a function expects a single value from a series, use
**myseries[n]**. When the function expects a whole series, use**myseries**or**myseries+n**. - A value returned by a function can be converted to a series by using it as the first parameter to the series function. For instance,
**series(price())**is a series that contains the**price**value;**series(SMA(series(priceClose()),30))**is a series containing the 30-bar Simple Moving Average of the**Close**value. - The rev function reverses a series so that the
**[0]**element is the earliest. - !! An internal counter determines the pointer to be returned by a
**series()**call. Therefore, series must be always created in the same number and order in every script run;**series**calls must not depend on if or other conditions that can change from bar to bar (see example below). This also applies to all functions that internally create**series**, such as some indicator or signal processing functions. If the number and order of created series change between runs, an error message will be displayed. - Since the LookBack value is automatically determined in the INITRUN, series are allocated in the FIRSTRUN. During the
**INITRUN**they are just filled with the initial value and keep their content only until the next**series**call. - When possible, do not create more series and make series not longer than needed. The longer a series, the more memory is required and the slower is script execution due to internal updating the series on every time frame.
- If you need to create extremely many series and get an Error 041, increase TradesPerBar.

// create a series with the high-low price differencesvars PriceRange = series(priceHigh()-priceLow());// compare the current range with the range from 3 bars agoif(PriceRange[0] > PriceRange[3]) ...// calculate a 20-bar Simple Moving Average containing the price differences from 5 bars agovar Average5 = SMA(PriceRange+5,20);// wrong use of conditional seriesif(priceClose() > Threshold) { vars X = series(priceClose());// error message!vars Y = series(SMA(X,100));// error message!... }// correct use of conditional seriesvars X = series(), Y = series(); if(priceClose() > Threshold) { X[0] = priceClose();// ok!Y[0] = SMA(X,100); ... }