Real-Time AFL
Up to this point every AFL variable you have written has been an array: one value for every bar, computed from data that had already been stored. This part introduces the handful of functions that do not work that way at all — functions that report a single number describing this instant, functions that decide how often your formula runs, and functions that tell your formula which part of AmiBroker is currently asking it for an answer.
That is a small vocabulary. GetRTData(), GetRTDataForeign(), RequestTimedRefresh()
and Status() are most of it. The difficulty is not the syntax. It is that these
functions break assumptions the rest of AFL let you keep: that a value has a history, that
a formula runs once, that the answer is the same no matter who asked.
What is actually here
Section titled “What is actually here”Four pages. The first is the field list and the contract around it — what GetRTData()
returns, what it returns when nothing is streaming, and why the answer is one number and
not an array. The second is Status(), which is how one formula behaves sensibly in a
chart, a scan, an Exploration and a backtest without pretending they are the same thing.
The third is RequestTimedRefresh() and the cost of asking a formula to run itself every
second. The fourth is a project that puts all three together into a quote panel.
The honest position on data
Section titled “The honest position on data”GetRTData() and GetRTDataForeign() are documented as Professional-edition functions
that work only when the database is fed by a real-time data plugin. On any other setup
they report nothing. That is not a problem this course can code around, and it would be
dishonest to pretend otherwise.
It is also not a reason to skip the part. Two of the four pages need no feed at all:
Status() works identically on an end-of-day database, and RequestTimedRefresh() is
documented to refresh a pane “regardless of data source used or connection state”. The
project ships an offline mode that is a designed feature rather than a fallback — it is
how anyone without a subscription runs the dashboard, and it labels itself as not live in
larger type than anything else on the panel.
The thing you cannot get without a feed is live bid and ask. The thing you can get, and
which matters more for the quality of your code, is the discipline of writing formulas
that behave correctly when a value is absent. Most of the real-time formulas circulating
on forums fail precisely there: they call Nz() on a missing quote, turn it into a zero,
and compute a spread of several thousand per cent without complaining.
What you should already have
Section titled “What you should already have”Part 17 for the architecture, Part 21 for the difference between the feed updating and the
chart refreshing, and Part 22 for the Real-Time Quote window — which is the only documented
way to check whether your vendor supplies a given field before you rely on it in AFL. From
the programming side you need Parts 8 to 11: arrays, IIf(), user functions and static
variables all appear here without further explanation.
Alerts are deliberately not in this part. AlertIf(), duplicate suppression and the alert
state machine are Part 25, and the two subjects tangle badly if taught together.
How to work through it
Section titled “How to work through it”Read the four pages in order; each one is used by the next. Run the field probe from the first lesson even if you know it will come back empty — an empty result is the contract you are coding against, and seeing it once is worth more than reading about it. Build the project panel in offline mode first, whatever your subscription status, because a panel that only works when the market is open is a panel you cannot debug.
0 / 4 lessons in this part completed
Progress tracking needs browser storage, which is unavailable here. The course works exactly the same without it.
- LessonGetRTData() and the Live Quote Fields Pro30 min
- LessonKnowing Where You Are: Status() and Execution Context28 min
- LessonRequestTimedRefresh() and Real-Time Performance28 min
- ProjectProject: Real-Time Quote Dashboard Pro55 min