Crossover
The Crossover node detects when series A crosses series B and emits a directional event signal: +1 when A crosses above B (bullish), −1 when A crosses below B (bearish), and 0 on all other bars. Series B can be replaced by a fixed numeric level for horizontal line crossings. The node requires at least two data points to compute.
Output Values
| Value | Meaning | Condition |
|---|---|---|
| +1 | Bullish crossover | prevA <= prevB and currA > currB |
| −1 | Bearish crossover | prevA >= prevB and currA < currB |
| 0 | No crossover | No change in relative position |
| null | Insufficient data | Either input was null at this bar, or this is the first bar (no previous value available) |
Algorithm
- ▸Arrays are aligned by timestamp; mismatched positions produce null.
- ▸For each bar i, the algorithm compares
(prevA, prevB)vs(currA, currB). - ▸A bullish cross requires A to have been at or below B on the previous bar and strictly above on the current bar.
- ▸A bearish cross requires A to have been at or above B on the previous bar and strictly below on the current bar.
- ▸
crossoverValuesrecords the current A value only on cross bars; all other positions are null. - ▸Prev values are reset to null when a null input is encountered, preventing stale-state crosses across data gaps.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| useNumericB | boolean | false | When true, series B is a fixed horizontal level defined by numericB. Useful for detecting level crossings (e.g. RSI crossing 50). |
| numericB | number | 0 | The constant level for series B when useNumericB is enabled. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input1 | (number | null)[] | Series A — the series that is crossing |
| input2 | (number | null)[] | Series B — the series being crossed (ignored when useNumericB is true) |
| Outputs | ||
| values | (number | null)[] | +1, −1, or 0 at each bar. null before enough data is available or where inputs are null. |
| crossoverValues | (number | null)[] | The price / value of series A at each crossover bar. null at non-crossover bars. Useful for chart markers. |
| lastCrossover | 1 | −1 | 0 | null | Direction of the most recent crossover event. |
| lastCrossoverValue | number | null | Series A value at the most recent crossover event. |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
Use Cases
Moving average crossover strategy
Connect EMA(9) to Input A and EMA(21) to Input B. The node fires +1 (buy) when the fast EMA crosses above the slow EMA and −1 (sell) when it crosses below. The classic Golden Cross / Death Cross setup.
Level crossing (RSI mid-line)
Connect RSI to Input A, enable useNumericB, set numericB = 50. The node fires +1 when RSI crosses above 50 (momentum turning bullish) and −1 when it crosses below.
MACD signal line cross
Connect the MACD line to Input A and the signal line to Input B. The crossover fires exactly at the bar where the MACD line changes direction relative to its signal, providing precise entry/exit timing.