c_ACSILDepthBars


c_ACSILDepthBars

The c_ACSILDepthBars C++ class provides an interface for accessing historical market depth data bars from a single chart. Use the Advanced Custom Study Interface and Language functions sc.GetDepthBars() or sc.GetDepthBarsFromChart() to get an instance of this class.

Historical market depth data is stored at multiple price increments, as determined by the tick size for the symbol, for each bar in the chart. The different price increments are identified by their price tick index, where each adjacent price tick index has a price value difference exactly equal to the tick size on the chart.

In order for there to be any data to access, historical market depth data must be collected for the chart's symbol. Refer to Market Depth Historical Graph for details.

c_ACSILDepthBars Methods

GetTickSize

float GetTickSize();

Returns the tick size that was used for storing the historical market depth data.

PriceToTickIndex

int PriceToTickIndex(float Price);

Converts the given Price value into a price tick index. This is equivalent to the price divided by the tick size. Price tick indexes are used to discretely identify price levels in the historical market depth data.

TickIndexToPrice

float TickIndexToPrice(int PriceTickIndex);

Converts the given PriceTickIndex into the original price value. This is equivalent to the price tick index multiplied by the tick size. Price tick indexes are used to discretely identify price levels in the historical market depth data.

NumBars

int NumBars();

Returns the number of historical market depth data bars. This will generally match the number of bars in the chart, but may be less if there is less market depth data available. Bar indexes in the historical market depth data will correspond to bar indexes in the chart. Not every bar may contain historical market depth data.

DepthDataExstsAt

bool DepthDataExstsAt(int BarIndex);

Returns true if any historical market depth data exists within the bar at the given BarIndex. If the given BarIndex is outside the valid range of bars, this method will return false.

GetBarHighestPriceTickIndex

int GetBarHighestPriceTickIndex(int BarIndex);

Returns the highest price, as a price tick index, that has any known depth quantity within the bar at the given BarIndex. If no depth data exists within the bar at the given BarIndex, or the given BarIndex is outside the valid range of bars, this method will return 0.

GetBarLowestPriceTickIndex

int GetBarLowestPriceTickIndex(int BarIndex);

Returns the lowest price, as a price tick index, that has any known depth quantity within the bar at the given BarIndex. If no depth data exists within the bar at the given BarIndex, or the given BarIndex is outside the valid range of bars, this method will return 0.

GetNextHigherPriceTickIndex

bool GetNextHigherPriceTickIndex(int BarIndex, int& r_PriceTickIndex);

Increments the given r_PriceTickIndex up to the next price tick index that contains any known depth quantity within the bar at the given BarIndex. If the given r_PriceTickIndex is already at or beyond the highest price, or if no depth data exists within the bar at the given BarIndex, or the given BarIndex is outside the valid range of bars, this method will return false. Otherwise the method returns true to indicate that the given r_PriceTickIndex has been set to the next valid price tick index with data. The given r_PriceTickIndex may be incremented by more than one price level if there are price levels that do not contain any depth quantities.

GetMaxDominantSide

BuySellEnum GetMaxDominantSide(int BarIndex, int PriceTickIndex);

Returns the side (BSE_BUY for bid, BSE_SELL for ask) with the greatest maximum quantity within the bar at the given BarIndex, at the given PriceTickIndex. If both sides have equal maximum quantities, or no quantities are known, this method returns BSE_UNDEFINED.

GetMaxQuantityForSide

int GetMaxQuantityForSide(int BarIndex, int PriceTickIndex, BuySellEnum Side);

Returns the maximum quantity within the bar at the given BarIndex, at the given PriceTickIndex, on the given Side (BSE_BUY for bid, BSE_SELL for ask). If the maximum bid quantity is equal to the maximum ask quantity, and BSE_UNDEFINED is given for the Side, then the maximum bid quantity will be returned, since both sides are equal. This is to assist in the case that the dominant side is requested, but there is no dominant side. Otherwise, if any of these parameters are outside the valid range of data, or there is no known quantity, this method returns 0.

GetMaxBidQuantity

int GetMaxBidQuantity(int BarIndex, int PriceTickIndex);

Returns the maximum bid quantity within the bar at the given BarIndex, at the given PriceTickIndex. If any of these parameters are outside the valid range of data, or there is no known bid quantity, this method returns 0.

GetMaxAskQuantity

int GetMaxAskQuantity(int BarIndex, int PriceTickIndex);

Returns the maximum ask quantity within the bar at the given BarIndex, at the given PriceTickIndex. If any of these parameters are outside the valid range of data, or there is no known ask quantity, this method returns 0.

GetMaxQuantity

int GetMaxQuantity(int BarIndex, int PriceTickIndex);

Returns the maximum quantity, the greater of the maximum bid quantity or the maximum ask quantity, within the bar at the given BarIndex, at the given PriceTickIndex. If any of these parameters are outside the valid range of data, or there are no known quantities, this method returns 0.

GetLastDominantSide

BuySellEnum GetLastDominantSide(int BarIndex, int PriceTickIndex);

Returns the side (BSE_BUY for bid, BSE_SELL for ask) with the greatest last quantity within the bar at the given BarIndex, at the given PriceTickIndex. If both sides have equal last quantities, or no quantities are known, this method returns BSE_UNDEFINED.

GetLastQuantityForSide

int GetLastQuantityForSide(int BarIndex, int PriceTickIndex, BuySellEnum Side);

Returns the last quantity for the bar at the given BarIndex, at the given PriceTickIndex, on the given Side (BSE_BUY for bid, BSE_SELL for ask). If the last bid quantity is equal to the last ask quantity, and BSE_UNDEFINED is given for the Side, then the last bid quantity will be returned, since both sides are equal. This is to assist in the case that the dominant side is requested, but there is no dominant side. Otherwise, if any of these parameters are outside the valid range of data, or there is no known quantity, this method returns 0.

GetLastBidQuantity

int GetLastBidQuantity(int BarIndex, int PriceTickIndex);

Returns the last bid quantity for the bar at the given BarIndex, at the given PriceTickIndex. If any of these parameters are outside the valid range of data, or there is no known bid quantity, this method returns 0.

GetLastAskQuantity

int GetLastAskQuantity(int BarIndex, int PriceTickIndex);

Returns the last ask quantity for the bar at the given BarIndex, at the given PriceTickIndex. If any of these parameters are outside the valid range of data, or there is no known ask quantity, this method returns 0.

GetLastQuantity

int GetLastQuantity(int BarIndex, int PriceTickIndex);

Returns the last quantity, the greater of the last bid quantity or the last ask quantity, for the bar at the given BarIndex, at the given PriceTickIndex. If any of these parameters are outside the valid range of data, or there are no known quantities, this method returns 0.

Examples

Iterating Through All the Prices Within a Bar

This code example demonstrates how to iterate through all of the price levels that contain depth data within a single bar.

// Get access to the depth bars in the current chart.
c_ACSILDepthBars* p_DepthBars = sc.GetDepthBars();
if (p_DepthBars == NULL)
	return;

// Do nothing if the bar at the current index has no data.
if (!p_DepthBars->DepthDataExstsAt(sc.Index))
	return;

// Iterate through each price index for the bar at the current index.
int PriceTickIndex = p_DepthBars->GetBarLowestPriceTickIndex(sc.Index);
do
{
	// TODO: Use PriceTickIndex to get the desired depth data at the current
	// price level.
	//
	// For example:
	//const int MaxBidQuantityAtPriceTick
	//	= p_DepthBars->GetMaxBidQuantity(sc.Index, PriceTickIndex);
}
while (p_DepthBars->GetNextHigherPriceTickIndex(sc.Index, PriceTickIndex));
        

GetBarLowestPriceTickIndex is used to get the first price tick index in the bar, and then GetNextHigherPriceTickIndex is used in a do-while loop to iterate through the rest of the price tick indexes in the bar. A do-while loop is used so that the first price tick index is processed before moving on to the next price tick index. Note that before attempting to get the first price tick index, the code first checks if any depth data exists in the bar using DepthDataExistsAt.

sc.GetDepthBars is used for getting access to the c_ACSILDepthBars object, and sc.Index is used for the current bar index.


*Last modified Tuesday, 30th August, 2016.