price (int offset) : var

Returns the mean price of the selected asset, by averaging all price ticks of the given bar or time frame (TWAP, time-weighted average price). For indicators the mean price is normally preferable to the close price, because it is less susceptible to random fluctuations and makes systems more robust and less dependent on the data feed.

priceOpen (int offset) : var

priceClose (int offset) : var

priceHigh (int offset) : var

priceLow (int offset) : var

Returns the open, close, maximum and minimum price of the current asset and the bar period or time frame with the given offset. priceClose(0) always returns the current price.

marketVal (int offset) : var

marketVol (int offset) : var

Returns additional 'raw' market data if available, such as spread, trade volume, accumulated volume, tick rate, or quote frequency, dependent on the Broker API and on the content of fVal and fVol fields in historical data. For instance, marketVal() can be the average spread of the last bar period, and marketVol() the 1-minute trade volume averaged over the last bar period. See remarks and examples below. The market functions require Zorro S and no LEAN flag.


offset Bar or time frame number for which the prices are returned, relative to the current bar or time frame. 0 for the the current bar or time frame. Negative offsets return prices of future bars or time frames when the PEEK flag is set; otherwise they give an error message.


Price or market data.

seriesO(): vars

seriesH(): vars

seriesL(): vars

seriesC(): vars

Returns pointers to the temporary open, high, low, and close price series of the current asset that are internally used for the TA-Lib indicators. Can be used as a price series parameter to any function or indicator. Unlike real series, they don't consume memory and can be conditionally called. TimeFrame however is ignored, and the temporary series keep their content only until the next indicator call.

priceSet (int offset, var Open, var High, var Low, var Close)

Modifies the open, high, low, close, and mean price of the current asset for test purposes, artificial price curves, or for prices from different sources. Use offset = -1 for modifying the prices of the next bar, which is necessary for entering trades at modified prices.

priceQuote (var Timestamp, var Quote) : int

Enters a new price quote of the current asset in the system; especially for HFT simulation or when prices are not available from the broker connection. Filters outliers and updates the current best ask (AskPrice) and best bid (AskPrice - Spread). Increases Bar after every BarPeriod when no run function is used. Price quotes are also printed to the log when Verbose is at 3 or above, so be careful with Verbose for preventing awfully large log files.


offset Optional bar number for which the prices are returned, in time frames before the current time frame. If 0, the price of the current bar is returned. Negative offsets return future prices when the PEEK flag is set; otherwise they give an error message.
Timestamp The exchange timestamp of the quote in DATE format. Quotes older than the previous quote are ignored.
Quote The price. Quote > 0 indicates an ask price, Quote < 0 a bid price.


1 if the price quote was accepted, 0 if an Outlier was detected or the timestamp was outdated.

priceRecord ()

Appends the current OHLC candle and the current spread and volume of the current asset to the begin of the price history in .t1 or .t6 format (only in [Trade] mode and after the INITRUN). This allows recording live prices for re-training or other purposes.


priceOpen(10) returns the opening price of 10 bars ago. priceClose() returns the close price of the current bar, i.e. the most recent price.



BarPeriod = 60; // set up 1 hour bars (60 minutes)

TimeFrame = 4;
vars EUR4Hs = series(price(0));	// create a series of 4 hour EUR mean prices
TimeFrame = frameSync(24);
vars SPXDays = series(priceClose(0));	// create a series of daily S&P 500 close prices
TimeFrame = 1;
// Print IB trade volume at any bar

var volumeSum(var* Buffer,var Volume,int NewFrame)
// Buffer[0] = current volume, building up;
// Buffer[1] = previous volume; 
  if(NewFrame) { 
    Buffer[1] = Buffer[0];
    Buffer[0] = 0;
  return Buffer[0] += BarPeriod*Volume; // sum of 1-min volumes

var volumeDiff(var* Buffer,var Volume,int NewFrame)
// Buffer[2] = previous accumulated volume
  if(Buffer[2] == 0 || Buffer[2] > Volume)
    Buffer[2] = Volume;
  Buffer[0] = Volume-Buffer[2]; // frame volume difference
  if(NewFrame) {
    Buffer[1] = Buffer[0];
    Buffer[2] = Volume;
  return Buffer[0]; 

void run()
  BarPeriod = 1;
  LookBack = 0;
  brokerCommand(SET_PRICETYPE,2); // trade prices
  brokerCommand(SET_VOLTYPE,4); // trade volume
  vars VBuffer = series(0,-3);
  if(Live) // daily accumulated volume
  else     // average 1-min volume
  var Volume = VBuffer[1];
  printf("# Vol %.0f",Volume);

See also:

enterLong/Short, series, asset, Spread, PIP, Detrend, dayHigh/Low, History

► latest version online