tick()
User-supplied function that is called on arrival of a new price quote of any asset used in the strategy. This function can be used when an immediate reaction on every new price quote is required.
tock()
User-supplied function that is called once per minute (adjustable via TockTime), regardless of price quotes. This function can be used for
auxiliary purposes, such as periodic input/output tasks when live trading.
callback(void* Address)
User-supplied function that is called when either the BrokerProgress function is
triggered with a pointer as argument, or when Zorro receives a WM_APP+2
window
message. This function is not in sync with other functions or I/O operations, so use
the call scheduler when modifying global variables or
accessing non-reentrant parts of the broker API.
Remarks:
- The tick function runs in irregular intervals dependent on market activity. The more assets are traded, the more quotes will trigger a tick run. The tick function normally executes
much more frequently than the run function, but can also execute less often when few quotes are received, f.i. after market hours. The minimum time between two
tick calls can be set up with TickTime. If a new quote arrives earlier, it is delayed until the
TickTime is over.
- Within a tick function the asset name, the current ask price, and the current ask-bid spread can be evaluated with the Asset string,
with priceClose(0),
and with the Spread variable. The time stamp
of the last quote is returned by seconds(0) or wdate(0).
For evaluating component specific parameters such
trade statistics, call
asset(Asset) and/or
algo(...) at the begin of the tick
function.
- The same price quote can trigger a tick function as well as a TMF. The tick functions of all assets that had quotes in the last TickTime are executed first, afterwards all triggered TMFs are executed.
- In [Test] or [Train] mode, the tick and tock
functions are normally called once per bar.
When the TICKS flag is set, the tick function is called at any new price quote
in the historical data. When a bar period is smaller than TockTime,
the tock function can be called less often than once
per bar.
- The series function cannot be called in any
of the above functions,
neither can indicators that internally create data series. However, series
in global variables can be evaluated, and static series or arrays can be shifted in a tick or tock function by calling
shift. This way tick based indicators
or indicators on time frames shorter than
BarPeriod
can be used.
- As long as the current bar is not finished, the current
candle is incomplete in any of the
above functions. Its range and height
differs to the preceding complete candles and should therefore normally not be used for
indicators and trade signals. The price functions also return different values
in a tick than in a run function because their open, high, and low prices
reflect the current incomplete candle.
- When printing inside a error function, make
sure that the printed text does not contain any of the trigger
words. Otherwise you'll get an endless loop.
Examples (see also HWnd):
// print every price quote in a file
function tick()
{
file_append("Log\\ticks.txt",
strf("\n%i.%i %2i:%2i:%2.3f => %s %4.5f",
day(),month(),hour(),minute(),second(),Asset,priceClose()));
}
// shift a static series in a tick function
vars MySeries; // use a global series variable
function tick()
{
...
shift(MySeries,priceClose(),100); // shift the series
...
}
function run()
{
...
MySeries = series(0,-100); // generate a static series
...
See also:
Bars and Candles, Bar, BarPeriod, TickTime,
manage, run,
call, user supplied functions
► latest
version online