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 historical and live market data, such as spread, trade volume, tick rate, quote
frequency, or similar extra data dependent on the implementation in the Broker
API and on the content of fVal and fVol fields
in historical data. The market functions require
Zorro S and no LEAN flag.
Note that spread recorded in .t1 or .t6 files
can be zero or negative.
||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 additional market data.
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 omitted, 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.
- All prices used for trading or indicators are normally Ask prices - no matter if for a long or short trade. This way, stops, entry limits or profit targets can be calculated without make 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 stop loss, take profit, or entry limits.
- The Bid price is the Ask price minus Spread; the pip value 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.
Prices can be switched between different types (f.i. quotes and trades) with
the SET_PRICETYPE command when supported by
- Price outliers and stock splits are detected and can be evaluated with the
PriceJump variable. Outliers are removed.
- If the LEAN flag is set and M1 historical data is used, the open and close prices of a bar are the mean prices of its first and last M1 tick.
- At the initial run of the strategy before loading an asset, all price functions return 0 and LookBack is automatically expanded to the biggest offset value.
N bars must have passed for accessing the price of N bars ago. If
offset is higher than the current bar number (Bar), the price of the first bar is returned.
- 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
Hacks & Tricks.
- 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 Open price is taken from the begin of the time frame, the Close price from its end, and the High, Low, and mean prices are calculated from all bars belonging to the time frame.
- If Detrend is set to 2 or 3, the returned prices are detrended for removing trend bias from the simulation.
- If PEEK mode is set, price functions can peek into the future by using negative offsets. This is often required for generating the advisor AI function from 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.
- A series can be filled with prices by calling the series() function with the return value of the price function (see example).
- Historical volume is normally per minute (in T1 or M1 files) or per day
(in D1 files). Live volume is normally the current accumulated trade volume
of the day or the trading session; for converting it to per-minute volume,
subtract the volume from 1 bar ago from the current volume, and divide by
BarPeriod. Details about the returned values by
marketVal and marketVol can be found on the
specific broker page in this manual.
- 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
- Arrays containing the complete historical prices are for special purposes
accessible through AssetO, AssetH, AssetL, AssetC, AssetP.
Note that using those prices an a backtest will produce peeking bias.
BarPeriod = 60; // set up 1 hour bars (60 minutes)
TimeFrame = 4;
vars EUR4 = series(price(0)); // create a series of 4 hour EUR mean prices
TimeFrame = frameSync(24);
vars SPXDay = series(priceClose(0)); // create a series of daily S&P 500 close prices
TimeFrame = 1;
enterLong/Short, series, asset, Spread, PIP, Detrend, dayHigh/Low
► latest version online