Order of the calls
1
OnSet
Called when the indicator is created from the list, with
setDefault set to true, and again before every load of the chart. Here the indicator says which calls it wants and creates its chart area and its series. The parameters already have their values.When setDefault is true the chart is not there yet and Vbk is null: set the calls and return.2
OnInit
Called once per load, before the bars. The place to ask for the aggregated trades.
3
OnLoad
Called before the first bar. Reset here everything a previous calculation left: counters, lists, annotations you keep a reference to. Create here the groups of your annotations.
4
History
For every bar of the chart, in order:
OnOpen when the bar starts, OnBook for every group of updates of the order book, OnBookClose when the book of the bar is complete. The trades follow: OnTick for every trade, OnTickClose when the trades of a bar are complete. When everything is done, OnEnd(false) is called once.5
Realtime
The same calls, with
isRt set to true, as the updates arrive. After each batch of updates, OnEnd(true): the place to update what depends on the bar still open.OnSet when it is opened, when the user changes a setting or a parameter, and as the session goes on, because the chart keeps a window of the most recent bars. Nothing you kept in fields is cleared for you: OnLoad must bring the indicator back to its initial state, and OnSet creates the area and the series every time.
Two indices
The book and the trades of a bar do not arrive at the same moment, so the chart keeps two indices:
Add the points of a series in
OnOpen with BookIndex. Read the volumes of a bar (AskVol, BidVol) in OnTickClose with TickIndex: they are complete there, not in OnBookClose. In OnEnd the bar still open is BookBars[TickIndex].
Choosing the calls
A call is made only when the indicator asks for it inOnSet, with one property of IndPrms per method:
OnEnd and OnResizeAxis are called in both phases with any value other than Off. OnInit and OnLoad are called only when the indicator asks for at least one of the other calls.
Ask only for what you use: an indicator which asks for OnTick or OnBook on the history makes every load slower.
The trades before the first bar
The chart shows the last part of the session. An indicator which needs the whole session, a cumulative delta for example, asks forOnTickCall = CallHandler.Full: before the bars it receives every trade of the session before the first bar in OnIniParallelTick.
These trades are split between the cores of the computer and given in parallel: each core gets its own range of trades, in order, and indCore says which core is calling. The rule is simple:
- keep one accumulator per core, in an array of
Vbk.NumCoreelements created inOnLoad; - never touch shared state from
OnIniParallelTick; - merge the accumulators, in the order of the cores, before using the result: at the first
OnTickorOnEnd.