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.
User-supplied function that is called once per minute (adjustable via TockTime;
DayOffset), regardless of price quotes. This function can be used for
auxiliary purposes, such as periodic input/output tasks when live trading.
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
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.
- 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,
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
algo(...) at the begin of the tick
- 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
- 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. This way tick based indicators
or indicators on time frames shorter than
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.
- Trading with different assets in a 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. To prevent this effect, use the tock
function for trading multiple assets when required, and 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
strf("\n%i.%i %2i:%2i:%2.3f => %s %4.5f",
// shift a static series in a tick function
vars MySeries; // use a global series variable
shift(MySeries,priceClose(),100); // shift the series
MySeries = series(0,-100); // generate a static series
Bars and Candles, Bar, BarPeriod, TickTime,
call, user supplied functions