Data
In this context, data is understood as information loaded from outside sources as well as data sets originating from internally generated AgenaScripts.
Bars (Candles)
Modus Operandi
A classical indicator will calculate one or multiple values using the available data series.
Data series in this sense can consist of closing prices, lows, hourly charts or 10-minute periods etc. Each period (candle) will be assigned to a specific indicator(s).
In the following examples and illustrations, we will assume an indicator value generated by something like a simple moving average.
To calculate a moving average, AgenaTrader needs a data series; for this we will use the closing prices. All closing prices for the bars (candles) within a chart will be saved in a list and numerically ordered.
The current closing price of the current bar will be displayed on the right edge of the chart and will be assigned the number 0. The bar to the left of it is assigned the number 1 and so on. The oldest displayed bar will have the number 500 (as an example).
If a new bar is added during the current trading session, then this bar will be assigned the number 0, and the previous bar – which up to that point was bar number 0 – will now be reassigned as bar 1, and the oldest bar to the very left will have the number 501.
Within a script (self-created program), the “Close" array is the list of all closing prices. The last closing price is thus Close[0] and the preceding closing price (bar to the left of the last bar) is Close[1] and so on, with the oldest candle having the value of Close[501]. The number within the square brackets here clearly denotes the index of the array. The general term used within AgenaTrader is “barsAgo".
In addition, each bar will not only have a close value, but also a High, Low, Open, Median, Typical, Weighted, Time and Volume. On a daily period timeframe, the high of the candle that occurred 10 periods ago would be High[10]; the low of the last day would be Low[1].
Important note: The examples mentioned concern calculations that are performed at the end of a period. The values for the currently running and unfinished candles are not taken into consideration.
If you want the values of the currently running and unfinished candles, you will need to set CalculateOnBarClose = false. As with the previous example, the currently running bar will receive the number 0 and so on. Close[0] will provide you with the most recent price transmitted by the data provider. All values of the bars High[0]…Low[0]… etc. are subject to change until the bar has been finalized and a new bar has begun. The only value that will definitely not change is Open[0].
Data Series
Description
AgenaTrader differentiates between data series used for your self-programmed definitions that will hold values of various types, and on the other hand, data series which are the standard integrated series containing market data and price data for the individual data. The concept of data series is followed up consistently and continuously. All price data for individual bars are organized within the data series.
The following data series are available:
Open
Description
Open is the data series in which the historical opening prices are saved.
Parameter
barsAgo Index value (see Bars)
Usage
Open
Open[int barsAgo]
More information
The outputted value depends on the property CalculateOnBarClose.
Example
// Opening price of the current period
Print(Time[0] + " " + Open[0]);
// Opening price of the bar that occurred 5 periods ago
Print(Time[5] + " " + Open[5]);
// Current value of the SMA 14 above the opening price (rounded)
Print("SMA(14) Calculated using the opening prices: " + Instrument.Round2TickSize(SMA(Open, 14)[0]));
High
Description
High is the data series in which the historical highs are saved.
Parameter
barsAgo Index value (see Bars)
usage
High
High[int barsAgo]
More information
The outputted value depends on the property CalculateOnBarClose.
Example
// High price of the current period
Print(Time[0] + " " + High[0]);
// High price of the bar 5 periods ago
Print(Time[5] + " " + High[5]);
// Current value for the SMA 14 using the high prices (rounded)
Print("SMA(14) calculated using the high values: " + Instrument.Round2TickSize(SMA(High, 14)[0]));
Low
Description
Low is the data series in which all historical lows are saved.
Parameter
barsAgo Index value (see Bars)
Usage
Low
Low[int barsAgo]
More information
The outputted value depends on the property CalculateOnBarClose.
Example
// Low prices of the current period
Print(Time[0] + " " + Low[0]);
// Low prices of the bar 5 periods ago
Print(Time[5] + " " + Low[5]);
// Current value for the SMA 14 calculated using the low prices
Print("SMA(14) calculated using the low prices: " + Instrument.Round2TickSize(SMA(Low, 14)[0]));
Close
Description
Close is the data series in which all historical closing prices are saved.
Parameter
barsAgo Index value (see Bars)
Usage
Close
Close[int barsAgo]
More information
The outputted value depends on the property CalculateOnBarClose.
Indicators are generally calculated using the closing prices. The selection of the inseries can generally be omitted (see example below).
Example
// Closing prices for the current period
Print(Time[0] + " " + Close[0]);
// Closing prices for the bar 5 periods ago
Print(Time[5] + " " + Close[5]);
// Current value for the SMA 14 using the closing prices
Print("SMA(14) calculated using the closing prices: " + Instrument.Round2TickSize(SMA(Close, 14)[0]));
// Close can be omitted since it is used by default
Print("SMA(14) calculated using the closing prices: " + Instrument.Round2TickSize(SMA(14)[0]));
Median
Description
Median is the data series in which the historical median values are saved. The median price is calculated as (high + low) / 2.
Parameter
barsAgo Index value (see Bars)
Usage
Median
Median[int barsAgo]
More information
The outputted value depends on the property CalculateOnBarClose.
Further information on median, typical and weighted: http://blog.nobletrading.com/2009/12/median-price-typical-price-weighted.html
Example
// Median price for the current period
Print(Time[0] + " " + Median[0]);
// Median price for the bar 5 periods ago
Print(Time[5] + " " + Median[5]);
// Current value for the SMA 14 calculated using the median prices
Print("SMA(14) calculated using the median prices: " + Instrument.Round2TickSize(SMA(Median, 14)\[0\]));
Typical
Description
Typical is the data series in which the historical typical values are saved.
The typical price of a bar is calculated as (high + low + close) / 3.
Parameter
barsAgo Index value (see Bars)
Usage
Typical
Typical[int barsAgo]
More information
The outputted value depends on the property CalculateOnBarClose.
Further information regarding median, typical and weighted: http://blog.nobletrading.com/2009/12/median-price-typical-price-weighted.html
Example
// Typical price of the current period
Print(Time[0] + " " + Typical[0]);
// Typical price for the bar 5 periods ago
Print(Time[5] + " " + Typical[5]);
// Current value for the SMA 14 using the typical price
Print("SMA(14)calculated using the typical prices: " + Instrument.Round2TickSize(SMA(Typical, 14)[0]));
Weighted
Description
Weighted is the data series in which all historical weighted values are saved.
The weighted price of a bar is calculated as (high + low + 2*close) / 4 and is weighted on the closing price. See Median & Typical.
Parameter
barsAgo Index value (see Bars)
Usage
Weighted
Weighted[int barsAgo]
More information
The outputted value depends on the property CalculateOnBarClose.
Further information on median, typical and weighted: http://blog.nobletrading.com/2009/12/median-price-typical-price-weighted.html
Example
// Weighted price for the current period
Print(Time[0] + " " + Weighted[0]);
// Weighted price of the bar 5 periods ago
Print(Time[5] + " " + Weighted[5]);
// Current value for the SMA(14) using the weighted price
Print("SMA(14) calculated using the weighted price: " + Instrument.Round2TickSize(SMA(Weighted, 14)[0]));
Weighteds
Description
Weighteds is an array of DataSeries[1] that contains all Weighted data series.
The array is only of value for indicators and strategies that use data from multiple timeframes.
A new entry is added to the array whenever a new timeframe is added to an indicator or strategy.
With [TimeFrameRequirements(("1 Day"), ("1 Week"))] the array will contain 3 entries:
Weighteds[0] the weighted data series of the chart timeframe Weighteds[1] the weighted data series of all bars in a daily timeframe Weighteds[2] the weighted data series of all bars in a weekly timeframe
Weighteds[0][0] is equivalent to Weighteds[0].
See MultiBars.
Parameter
barsAgo Index value of the individual bars within a data series barSeriesIndex Index value for the various timeframes
Usage
Weighteds[int barSeriesIndex]
Weighteds[int barSeriesIndex][int barsAgo]
More Information
The returned value is dependent upon the property CalculateOnBarClose.
Example
See example under Multibars.
Time
Description
Time is a DataSeries of the type DateTimeSeries, in which the timestamps of the individual bars are saved.
Parameter
barsAgo Index value (see Bars)
Usage
Time
Time[int barsAgo]
More Information
The returned value is dependent upon the property CalculateOnBarClose.
Example
// Timestamp of the current period
Print(Time[0]);
// Timestamp of the bar from 5 periods ago
Print(Time[5]);
Times
Description
Times is an array of DataSeries that contains all Time data series.
This array is only of value to indicators and strategies that make use of multiple timeframes. A new entry is added to the array whenever a new timeframe is added to an indicator or strategy.
With [TimeFrameRequirements(("1 Day"), ("1 Week"))] the array will contain 3 entries:
Times[0] the time data series of the chart timeframe Times[1] the time data series of all bars in a daily timeframe Times[2] the time data series of all bars in a weekly timeframe
Times[0][0] is equivalent to Times[0].
See MultiBars.
Parameter
barsAgo Index value for the individual bars within a data series barSeriesIndex Index value for the various timeframes
Usage
Times[int barSeriesIndex]
Times[int barSeriesIndex][int barsAgo]
More Information
The returned value is dependent upon the property CalculateOnBarClose.
Example
See example Multibars.
Volume
Description
Volume is a DataSeries of the type DataSeries, in which the historical volume information is saved.
Parameter
barsAgo Index value (see Bars)
Usage
Volume
Volume[int barsAgo]
More Information
The returned value is dependent upon the property CalculateOnBarClose.
The value returned by the VOL() indicator is identical with the volume described here; for example, Vol()[3] will have the same value as Volume[3].
Example
// Volume for the current period
Print(Time[0] + " " + Volume[0]);
// Volume of the bar from 5 periods ago
Print(Time[5] + " " + Volume[5]);
// Current value for the SMA 14 calculated using the volume
Print("SMA(14) calculated using the volume: " + Instrument.Round2TickSize(SMA(Volume, 14)[0]));
Volumes
Description
Volumes is an array of DataSeries that contains all Volume data series.
This array is only of value for indicators or strategies that use data from multiple timeframes.
A new entry is added to the array whenever a new timeframe is added to an indicator or strategy.
With [TimeFrameRequirements(("1 Day"), ("1 Week"))] the array will contain 3 entries:
Volumes[0] the volume data series of the chart timeframe Volumes[1] the volume data series of all bars in the daily timeframe Volumes[2] the volume data series of all bars in the weekly timeframe
Volumes[0][0] is equivalent to Volumes[0].
See MultiBars.
Parameter
barsAgo Index value of the individual bars within a data series
barSeriesIndex Index value of the various timeframes
Usage
Volumes[int barSeriesIndex]
Volumes[int barSeriesIndex][int barsAgo]
More Information
The returned value is dependent upon the property CalculateOnBarClose.
Example
See example Multibars.
TimeFrame
Description
TimeFrame is a timeframe object.
Usage
TimeFrame
TimeFrames
Description
TimeFrames is an array of timeframe objects that contains a timeframe object for each individual bar object.
This array is only of value for indicators or strategies that use data from multiple timeframes.
A new entry is added to the array whenever a new timeframe is added to an indicator or strategy.
With [TimeFrameRequirements(("1 Day"), ("1 Week"))] the array will contain 3 entries:
TimeFrames [0]; //Timeframe of the primary data series (chart timeframe)
TimeFrames [1];
Print(TimeFrames[1]); // returns "1 Day"
TimeFrames [2];
Print(TimeFrames[2]); // returns "1 Week"
TimeFrames [0] is equivalent to TimeFrame.
See MultiBars.
Parameter
barSeriesIndex Index value for the various timeframes
Usage
TimeFrames [int barSeriesIndex]