Detecting Indicator Crossovers and Counting Bars Since the Cross
Summary
The document explains a function for comparing two numeric indicator series and reporting the recent duration of their current relative ordering. It scans the arrays from the latest values backward, increments a positive count while the first series remains above the second, and decrements a count while it remains below. It stops when the relationship changes, values are equal, or an invalid value is encountered. Different array ordering changes whether a positive or negative result represents a golden or death cross, so users must interpret the sign in light of which series is passed first.
A sample pair of arrays produces counts of three and negative three when the inputs are reversed, illustrating that the crossover occurred three bars earlier. The function requires equal-length arrays and numeric observations. The explanation is a code-level description with a small example, not a trading evaluation: it offers no evidence that crossovers predict returns, and it does not discuss execution, lag, or false signals.
Key ideas
- The function scans two equal-length indicator arrays backward from their latest values.
- A positive or negative output counts consecutive bars with one series above or below the other.
- Reversing the input series reverses the sign and the golden-cross or death-cross interpretation.
- The scan stops at an equality, a change in ordering, or a nonnumeric value.
- The example illustrates the count but does not establish predictive value.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.