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
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.
||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.
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
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.
||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.
||The exchange timestamp of the quote in DATE format. Quotes older than the previous quote are ignored.
||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.
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
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.
- At the initial run of the strategy before loading an asset,
price functions return 0.
- If not otherwise mentioned, all prices are ask prices. This way stops, entry limits, or profit targets can be calculated without a distinction between long and short trades. Zorro automatically handles conversion from Ask to Bid when entering or exiting trades,
calculating trade profit, or setting limit levels.
- The bid price is the ask price minus Spread; the
pip value of a price is the price divided by the PIP variable. The current bid/ask mean price is priceClose() - 0.5*Spread. More variants of prices - i.e. the Center Price, the Typical Price, the Haiken Ashi Price etc. - can be found on the indicators page.
Live prices can be switched between different types (f.i. quotes and trades) with
the SET_PRICETYPE command when supported by
- When connected to a broker or exchange, prices are updated at any tick;
when connected to an online price source, at any
bar. Price outliers and stock splits are detected and can be evaluated with the
PriceJump variable. Outliers are removed, splits are
- If the LEAN flag is set and M1 historical data is used, open and close prices of a bar are
not explicitely stored. They are derived from the mean prices of its first and last M1 tick.
- If LookBack is not set, it is automatically expanded to the biggest
offset is higher than the current bar number (Bar), the price of the first bar is returned.
- A series can be filled with prices by calling the
series() function with the return value of the price function (see example).
- When using
multiple time frames in the strategy (TimeFrame variable), the
offset parameter gives the number of time frames rather than the number of bars. The
function priceOpen returns the price from the begin of the time frame,
priceClose from its end, priceHigh, priceLow
the maximum and minimum price within the time frame, and price
the current average of the time frame. Synchronizing time frames (TimeFrame
= 0) to certain events or dates is not supported by price
functions; use price series for that when
- The values returned by marketVol and marketVal
depend on the broker API and are described on the specific broker page in
this manual. Historical volume is often the
sum of quote sizes or trade volumes of the current quote period or day. Live volume is
often the accumulated trade volume
of the current day or trading session. The functions
return the current value when Offset is 0, otherwise the
average of the time frame. Depending on which sort of raw volume they
return, it can be converted by script to the total volume per time
frame. For instance, to convert accumulated volume to per-minute volume,
subtract the volume from 1 bar ago from the current volume, and divide by
BarPeriod. See examples below.
- After switching to a different asset, the price functions automatically change to the prices of that asset. Artificial assets can be created by combining the prices from several real assets. An example can be found under
Tips & Tricks.
- Prices are affected by Detrend flags.
- If the PEEK flag is set, price functions can
peek into the future by using negative
offsets. This is normally used for training machine learning algorithms (see
advise) with historical price data. If
PEEK mode is not set, negative offsets will generate an error message.
- In a TMF or tick function,
priceClose() returns the last price quote, updated every tick when new price data becomes available.
price() returns the price averaged over all received ticks of the current bar so far; therefore it is more 'jaggy' at the begin of the bar when few ticks were received yet, and more smooth towards the end of the bar period.
priceHigh() and priceLow() return the highest and lowest price of the current bar so far, so their distance is small at the begin of the bar and wide towards the end.
- If .t1 data contains both ask and bid quotes,
marketVal returns the recent ask-bid spread. In
.t6 data it returns the fVal
value. Set if(is(TESTMODE)) Spread = max(0,marketVal()); in the script for backtesting with variable
spread when it is contained in the historical .t1 or .t6 data.
- An example of using the priceQuote function for simulating a HFT system can be found on
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 = current volume, building up;
// Buffer = previous volume;
Buffer = Buffer;
Buffer = 0;
return Buffer += BarPeriod*Volume; // sum of 1-min volumes
var volumeDiff(var* Buffer,var Volume,int NewFrame)
// Buffer = previous accumulated volume
if(Buffer == 0 || Buffer > Volume)
Buffer = Volume;
Buffer = Volume-Buffer; // frame volume difference
Buffer = Buffer;
Buffer = Volume;
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;
printf("# Vol %.0f",Volume);
enterLong/Short, series, asset, Spread, PIP, Detrend, dayHigh/Low,
► latest version online