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.

For functions that take a PriceTickIndex index value, that can be determined from an actual float price value by using the PriceToTickIndex member function.

In order for there to be any historical market depth data to access, historical market depth data must be loaded into the chart and also should be recorded in real-time. To accomplish both of these, it is necessary to set sc.MaintainHistoricalMarketDepthData to TRUE in the study function. This normally will be done in the sc.SetDefaults code block.

It is also supported to access the most recent market depth data through the sc.SymbolData ACSIL member. This is an alternative to access the current market depth data. You will also need to access the current market depth data through this ACSIL member whenever market depth data changes after a chart bar has completed but before there is a new trade for the next bar which has not yet been displayed because there has not yet been a trade for that new upcoming bar.

GetTickSize

PriceToTickIndex

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

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

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.

GetBarHighestPriceTickIndex

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

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

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

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

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

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

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

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

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

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

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

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

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 market depth data within a single bar.

// Get access to the market depth bars in the chart the study instance is applied to.
c_ACSILDepthBars* p_DepthBars = sc.GetMarketDepthBars();
if (p_DepthBars == NULL)
return;
// Do nothing if the bar at the current index has no data.
if (!p_DepthBars->DepthDataExistsAt(sc.Index))
return;
// Iterate through each price index for the bar at the current index.
int PriceTickIndex = p_DepthBars->GetBarLowestPriceTickIndex(sc.Index);
do
{
// 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));