TradeViora AcademyLearn. Analyze. Practice. Trade Smarter.
Menu

FREE FINANCIAL EDUCATION

Cross-checking indicator implementations

Study cross-checking indicator implementations through mechanisms, a synthetic worked case, practice, and explained assessment.

Technical Indicators

APPLIED STUDY · ORIGINAL LESSON

Learning plan and prerequisites

Before you begin: Complete SMA, EMA, ATR, RSI and warm-up lessons.

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.

Topic assessment

Choose an answer before opening each explanation. These questions test the specific mechanism in this lesson.

1. Why compare true range before a smoothed ATR?

  1. Long series always reveal errors more clearly
  2. It localises a formula mismatch before recursion obscures it
  3. ATR has no inputs
Reveal answer and explanation

B. Component fixtures make the source of disagreement easier to identify.

2. What is wrong with copying expected outputs from the tested code?

  1. It is always faster and therefore correct
  2. Expected outputs need no explanation
  3. The same defect can appear in both result and expectation
Reveal answer and explanation

C. An independent calculation is needed for a meaningful numerical check.

3. Does passing a value tolerance guarantee identical crossover events?

  1. No
  2. Yes
  3. Only with three choices
Reveal answer and explanation

A. Near a boundary, small acceptable value differences can change a discrete event.

Primary references and scope

Original explanation and synthetic calculations. Chart thresholds are explicit research conventions, not exchange rules or proof of predictive ability.