APPLIED STUDY · ORIGINAL LESSON
Learning plan and prerequisites
Before you begin: Complete SMA, EMA, ATR, RSI and warm-up lessons.
- Build small numerical fixtures
- Diagnose convention differences before declaring bugs
- Separate value tolerance from event equivalence
Mechanism and interpretation
Two charting tools can produce different indicator values because of data, indexing or conventions. Begin with identical input rows, timestamps, adjustment type and session coverage. Then compare the documented formula, window inclusion, seed, smoothing coefficient, missing-value policy and output alignment. Only after these are matched does a remaining numerical discrepancy strongly suggest an implementation defect. A name such as RSI or ATR is not a complete specification.
Use short fixtures whose expected outputs can be calculated independently. Include an ordinary sequence, a constant sequence, a gap, an equality boundary and a missing observation. Keep expected values and the reasoning alongside the fixture. Do not generate the expected output by copying the implementation under test, because that can reproduce the same error. Compare intermediate components where possible: true range before ATR smoothing, or gain/loss averages before RSI transformation.
Worked case — synthetic data
Synthetic fixtures specify a three-value SMA on[10,20,30], expected 20; EMA with alpha 0.5, previous value 20 and new input 30, expected 25; and true range with previous close 100, high 108 and low 105, expected 8. A tool returning 3 for the last fixture may be using high-low range rather than true range. That diagnostic points to a convention or implementation mismatch at the component level, before a long smoothed series obscures the cause.
For numerical comparison, suppose tolerance is absolute tolerance plus relative tolerance×max(|a|,|b|), with both tolerances 1e−8. Values 100 and 100.0000003 differ by about 3e−7 and pass the roughly 1.01e−6 bound. Values 0.0001 and 0.0001003 have the same absolute difference but fail the roughly 1.0001e−8 bound. This combined rule is explicit about scale. Its tolerances are illustrative testing choices, not universal requirements for every instrument.
Context and failure modes
A value comparison can pass while a strict crossover event differs near equality. Test event outputs as well as values. Some flat-series conventions are legitimately undefined or platform-specific; a test should expect the declared behaviour rather than forcing all tools to invent the same neutral number. Passing fixtures checks specified cases, not every possible path or predictive performance.
Practice task
Implementation A produces an EMA sequence that starts two units above implementation B but the difference shrinks by 0.8 each update under identical inputs. Identify a likely cause and calculate the difference after three updates. State one further check before concluding both formulas match.
Worked practice answer
Different initial seeds with alpha 0.2 are a likely explanation; the difference after three updates is 2×0.8³=1.024. Verify the alpha, timestamp alignment and handling of all subsequent inputs, then compare additional edge cases. A matching decay pattern is diagnostic evidence, not proof of every implementation detail.