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;
unaffected by
DayOffset), 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).
Date/time functions inside tick or tock
return the current time, not the time of the last bar. 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 normally run only once per bar,
right before the run function at the end of the bar.
When the TICKS flag is set, the tick function
runs at any new price quote
of any asset in the historical data, and the tock
function can run multiple times per bar. When a bar period is smaller than TockTime,
the tock function can run less often than once
per bar.
- The series function can not be called in any
of the above functions; this includes 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. In 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
reflect the current tick and return different values than in a run
function. priceC() is the current price at the time
of the tick.
- Trading with different assets in the same tick
function can cause backtest snooping bias.
When historical price ticks for assets A and B have the same time
stamps, the tick function will first run with asset
A, then with asset B. In the first run, asset A has the current
price, but asset B still the previous price. This can be used to
snoop the next B price especially when it strongly depends on the A
price. This is a rare and mostly theoretical issue, but to prevent it,
you can use the tock
function instead of tick for trading multiple assets.
The tock function is asynchronous to price quotes.
Set TockTime
to the tick resolution of the used historical data, or to
TickTime in live trading.
- 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