Subtract
systemic:core-subMathInputs
| Name | Type | Description |
|---|---|---|
| First Value | Number series | The series or constant to subtract **from** (the left side of the subtraction). |
| Second Value | Number series | The series or constant to subtract (the right side of the subtraction). |
Outputs
| Name | Type | Description |
|---|---|---|
| Difference | Number series | The First Value minus the Second Value at each bar. |
Cost
0.201 + 0.00624·n credits for n bars, rounded up. The marks are each plan's limit of bars.
Subtracts the second series from the first, bar by bar. Use it 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 empty at a bar (a data gap or a closed-market day), the difference at that bar is empty. The module never fills a gap: a gap in your inputs stays a gap in the output.
| First | Second | Difference |
|---|---|---|
| 100 | empty | empty |
| empty | 80 | empty |
| empty | empty | empty |
A result can also be mathematically undefined: subtracting +∞ from +∞ (or −∞ from −∞) has no answer, so that bar is empty even though both inputs have a value. Any other infinite result is returned unchanged.
Input Alignment
Systemic aligns the two inputs before it subtracts:
| Scenario | What Happens |
|---|---|
| Different start dates | The result starts where both inputs have data |
| Different periods | The slower series is repeated on every bar of the faster one |
| One constant | The constant is used on every bar of the series |
Example: BTC (1h) − ETH (15m) → each 15m bar uses the most recent 1h BTC value.
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 the input order that gives the sign you want.
Practical Example: Price Deviation from Moving Average
Subtracting a 20-bar SMA from the 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 |
Plotted over time, this deviation shows momentum shifts and possible reversal zones. Many mean-reversion strategies build on it and raise a signal when the deviation exceeds its historical range.
Related Modules
- ADD — Adds two series bar by bar
- DIV — Normalizes a difference (for example, percentage deviation)
- ABS — Absolute deviation (distance without sign)