Multi-Symbol Analysis
Everything you have written so far has looked at one symbol at a time. AFL is built that way: the Analysis window hands your formula one symbol, the formula computes its arrays, the window moves on. That model is simple, fast and, for a great many questions, sufficient.
It is not sufficient for the question most analysts ask within a week of starting: compared with what? A stock that gained twelve per cent in a year when its market gained twenty did not have a good year. A breakout that every one of its peers made on the same morning is a fact about the sector, not about the company. A correlation you noticed between two markets last spring may already have reversed. None of those statements can be made from inside a single-symbol formula, and all of them are routine.
This part gives you the machinery to bring a second, third or fourth symbol into a formula — and, more importantly, teaches you what that machinery does behind your back while it does it.
The thing that makes this part different
Section titled “The thing that makes this part different”Almost every technique in this course fails loudly. A misspelled function name refuses to compile. A wrong argument count throws an error. A scan that matches nothing shows you an empty list, and you go looking for the reason.
Cross-symbol work fails quietly. SetForeign() given a ticker that does not exist
returns zero and leaves your arrays exactly as they were, so the rest of the formula
computes the original symbol’s indicators while carrying the benchmark’s label. A
benchmark that did not trade on a public holiday your stock did trade on is handed
to you as a flat bar at yesterday’s close with zero volume, and every range-based
and volume-based calculation downstream treats it as a genuine day. A comparison
between a share listed in 2019 and an index with fifty years of history produces a
ratio line that begins in 1974, and nothing on screen says otherwise.
Each of those produces a chart. None of them produces an error. That is why this part spends a whole lesson on data alignment and gives you an audit formula whose only job is to count the bars that were manufactured rather than traded.
What you will be able to do
Section titled “What you will be able to do”By the end of the five lessons you should be able to:
- call
Foreign(),SetForeign()andRestorePriceArrays()with the correct argument order, and explain what each argument does — including the twofixuparguments that look alike and are not; - state precisely which variables a
SetForeign()block replaces and which it leaves untouched, and say what breaks when the restore is missing; - build a rebased comparison of a stock against a benchmark, and demonstrate for yourself how much of the answer came from your choice of start date;
- read AmiBroker’s market, group, sector and industry classification from AFL, and describe the ways in which a sector ETF is not a sector;
- measure how stable a relationship between two instruments has been, rather than quoting a single correlation figure as if it were a property of the pair;
- audit any pair of symbols for calendar mismatches, listing gaps and padded bars, and produce a number that says how much of your comparison rests on data that was never printed by an exchange.
What you need first
Section titled “What you need first”Part 8 through Part 11 for the AFL itself — arrays, IIf(), ValueWhen(), user
defined functions and parameters all appear here without further explanation.
Part 12 for the Analysis window, because two of the formulas in this part are
explorations. Part 14 is not a prerequisite, but its TimeFrameSet() material
becomes relevant in one specific and easily missed way: RestorePriceArrays() and
TimeFrameRestore() are documented as essentially the same function, so a formula
that mixes multi-timeframe code and cross-symbol code needs to be read carefully.
For data you need at least two symbols that overlap in time: one instrument and one index or fund you are willing to treat as a benchmark. End-of-day data from a free source is entirely adequate. Nothing in this part needs a real-time feed or the Professional edition — cross-symbol access is available in both editions, and the only edition difference that shows up here is how fast a large scan finishes.
How this part fits the ones around it
Section titled “How this part fits the ones around it”Part 13 ranked many symbols against each other at a point in time and used static
variables to do it. This part does something different and complementary: it brings
a small number of named symbols into one formula so they can be compared directly.
When you find yourself wanting to compare hundreds of symbols, the answer is
usually Part 13’s machinery, not a hundred Foreign() calls.
Part 16 builds composites — synthetic symbols that aggregate a whole universe. Every alignment problem described in this part gets worse there, because a composite adds up contributions from symbols that may not share a single trading day. The verification habits you build here are what make that part safe.
0 / 5 lessons in this part completed
Progress tracking needs browser storage, which is unavailable here. The course works exactly the same without it.
- LessonForeign(), SetForeign() and RestorePriceArrays()30 min
- LessonBenchmarks and Relative Performance28 min
- LessonSectors and Intermarket Analysis26 min
- LessonData Alignment Pitfalls Across Symbols28 min
- ProjectProject: Relative Strength Comparison Tool50 min