Subtract
systemic:core-subMathfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| First Value | floatarray | The value to subtract **from** — the left-hand side of the subtraction. |
| Second Value | floatarray | The value to subtract — the right-hand side of the subtraction. |
Outputs
| Name | Type | Description |
|---|---|---|
| Difference | floatarray | The element-wise difference of the two input series (First − Second). |
Computes element-wise subtraction of two numeric series. Fundamental for spreads, price changes, and deviations.
| First (A) | Second (B) | Difference |
|---|---|---|
| 100 | 80 | 20 |
| 80 | 100 | -20 |
| 50 | 50 | 0 |
Missing Data
If either input is missing (null) at a position — a data gap or a closed-market day — the difference at that position is null. The module never invents a value for missing data: a gap in your inputs stays a gap in the output.
| First | Second | Difference |
|---|---|---|
| 100 | null | null |
| null | 80 | null |
| null | null | null |
Separate from missing data, a result can be mathematically undefined: subtracting +∞ from +∞ (or −∞ from −∞) has no answer, so that position is also null even though both inputs exist. Any other infinite result passes through unchanged.
In live execution the module returns exactly one datapoint — the newest position — which is null when it cannot be determined.
Input Alignment
Systemic automatically aligns inputs before subtraction:
| Scenario | What Happens |
|---|---|
| Different lengths | Shorter series padded by repeating last value |
| Different frequencies | Lower-frequency upsampled to match higher |
| One constant | Constant expanded to match series length |
Example: BTC (1h) − ETH (15m) → BTC upsampled to 15m intervals first.
Order Matters
Subtraction is not commutative: A − B ≠ B − A
| Inputs | Result | Interpretation |
|---|---|---|
| Price − SMA | +20 | Price is 20 above average |
| SMA − Price | -20 | Average is 20 below price |
Choose input order based on your desired sign interpretation.
Practical Example: Price Deviation from Moving Average
Subtracting a 20-period SMA from price creates a deviation indicator:
| Use Case | Interpretation |
|---|---|
| Price − SMA > 0 | Price above average (potentially overbought) |
| Price − SMA < 0 | Price below average (potentially oversold) |
| Price − SMA → 0 | Reverting to mean |
This deviation, when plotted over time, reveals momentum shifts and potential reversal zones. Many mean-reversion strategies use this as a foundation, triggering entries when deviation exceeds historical thresholds.
Related Modules
- ADD — Element-wise addition
- DIV — Normalize difference (e.g., percentage deviation)
- ABS — Absolute deviation (unsigned distance)