value |
Optional data value of the series. When omitted, the series is filled 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 used like a normal var array and is not shifted
at every time frame. |

- 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**. - Non-static series are shifted at every bar or every time
frame, 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. - Static series (defined with a negative length) are not automatically shifted, but can be manually shifted with the shift function.
- For offsetting 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**at 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. - Series can be synchronized to external events or to longer time frames. For this, set the TimeFrame variable accordingly before the
**series()**call, and set it back afterwards. The element**[n]**then corresponds to the**n**th event or time frame in the past. - For excluding certain time periods from a series - f.i. for
ignoring hours with high or low volatility - create a static
series by giving a negative
**length**parameter, and fill it manually at any but the excluded bars with the shift function. - For adding or subtracting two series, create a series of the sum or difference of the recent elements, f.i.
**vars Sums = 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 can only be created in the run function or in a function that is called from the**run**function; and they must be always created in the same order. Thus**series**calls must not depend on if or any other condition that can change from bar to bar (see example below). These requirements also apply to all functions that internally create**series**, such as some indicator or signal processing functions. Zorro detects wrong series calls and will display an error message in this case. - 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. - Every series requires memory and CPU resources. Therefore do not create more or longer series than needed. The longer a series, the more memory is required and the slower is script execution due to internal shifting the series on every time frame.
- If you need to create extremely many series and get an Error 041, increase TradesPerBar. This affects not only the maximum number of trades, but also the maximum number of series.

// 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); ... }