DocsLogicCompare

Compare

BinaryLogic

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

OperatorCondition (output = 1)Note
>A > BStandard greater-than
<A < BStandard less-than
>=A >= BGreater-than or equal
<=A <= BLess-than or equal
==|A − B| < thresholdApproximate equality; set threshold to the acceptable tolerance
!=|A − B| >= thresholdValues 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: compareValues stores 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

NameTypeDefaultDescription
operatorstring>Relational operator. One of: >, <, >=, <=, ==, !=
thresholdnumber0Tolerance used only by == and !=. Must be >= 0. Example: threshold = 0.5 means "equal within 0.5 units".
useNumericBbooleanfalseWhen true, uses numericB as the constant B instead of a second port connection. Disconnects any existing Input B edge.
numericBnumber0Constant B value when useNumericB is enabled.

Inputs & Outputs

PortTypeDescription
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.
lastCompare1 | 0 | nullResult of the most recent comparison (1 = true, 0 = false, null = no data yet).
lastCompareValuenumber | nullInput A value at the most recent result transition.
timestampsnumber[]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.