Compare
The Compare node evaluates a relational expression between two numeric arrays bar by bar, producing a 0/1 signal array. In addition to the signal, it emits transition metadata — the input A value at each point where the result changes — enabling event-driven downstream nodes. Input B can be replaced by a fixed numeric constant via useNumericB, which is useful for threshold comparisons like "RSI > 70".
Operators
| Operator | Condition (output = 1) | Note |
|---|---|---|
| > | A > B | Standard greater-than |
| < | A < B | Standard less-than |
| >= | A >= B | Greater-than or equal |
| <= | A <= B | Less-than or equal |
| == | |A − B| < threshold | Approximate equality; set threshold to the acceptable tolerance |
| != | |A − B| >= threshold | Values differ by at least threshold |
Algorithm
- ▸Arrays are aligned by timestamp before comparison. Mismatched timestamps produce null at unmatched positions.
- ▸At each bar, the selected operator is applied: result 1 (true) or 0 (false).
- ▸Boolean inputs (true/false) are coerced to 1/0 before comparison.
- ▸Transition tracking:
compareValuesstores the input A value only at bars where the result changed (0→1 or 1→0). All other positions are null. - ▸Null in either input propagates null to the output at that position.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| operator | string | > | Relational operator. One of: >, <, >=, <=, ==, != |
| threshold | number | 0 | Tolerance used only by == and !=. Must be >= 0. Example: threshold = 0.5 means "equal within 0.5 units". |
| useNumericB | boolean | false | When true, uses numericB as the constant B instead of a second port connection. Disconnects any existing Input B edge. |
| numericB | number | 0 | Constant B value when useNumericB is enabled. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input1 | (number | null)[] | Input A — left-hand side of the comparison |
| input2 | (number | null)[] | Input B — right-hand side (ignored when useNumericB is true) |
| Outputs | ||
| values | (number | null)[] | 0 or 1 at each bar — 1 when the comparison is true, 0 otherwise. null where input was null. |
| compareValues | (number | null)[] | The input A value at bars where the comparison result changed (0→1 or 1→0). null at all other bars. |
| lastCompare | 1 | 0 | null | Result of the most recent comparison (1 = true, 0 = false, null = no data yet). |
| lastCompareValue | number | null | Input A value at the most recent result transition. |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
Use Cases
Threshold gate (RSI overbought)
Connect an RSI array to Input A, enable useNumericB, set numericB = 70, operator >. Output is 1 on every bar RSI exceeds 70 — feed directly into a Boolean AND with a trend filter.
Price vs moving average
Connect close price to Input A and EMA(50) to Input B with operator >. Produces 1 while price is above the EMA — a simple trend-direction filter for long-only strategies.
Near-equality detection
Use operator == with a threshold to detect when two oscillators are trading at nearly the same level — useful for convergence / divergence detection.