Subtract¶
Math · Arithmetic
Subtract B from A element-wise. Useful for spreads ('close − sma'), differences, and pair-trading constructions.
Subtract takes one series away from another, bar by bar — A minus B. It's the arithmetic block behind spreads and differences: the gap between price and a moving average, the spread between two instruments, the distance between two indicators.
How it works¶
Each bar the block outputs A − B. Either input can be Bars (uses close) or a series. Missing values produce NaN.
When to use it¶
Use Subtract to measure a gap. The classic case is close − SMA to build your own oscillator that swings around zero (price relative to its average). It's also the heart of pair-trading constructions (the spread between two correlated instruments) and any "how far apart are these two lines?" measurement. Pair the result with a Greater Than against zero to turn a spread into a directional condition.
Example¶
A price-vs-average oscillator: Subtract an SMA (B) from price (A) to get a zero-centred line — positive means price is above its average, negative below. Feed it into a Greater Than against 0 for a simple trend condition, and backtest in the Tester.
Tips & gotchas¶
- Order matters — A − B, not B − A. Swap the inputs and the sign flips.
- Either input can be bars or series — bars use close.
- Great for spreads — pair trading, price-minus-MA oscillators, line distances.
- For subtracting a fixed number, use Scalar Math.
Related blocks¶
Inputs¶
| Socket | Type | What to wire in |
|---|---|---|
| A | series / bars |
First operand. BARS input uses close. |
| B | series / bars |
Second operand. BARS input uses close. |
Outputs¶
| Output | Type | Plots as | Description |
|---|---|---|---|
| A − B | series |
Line · sub-pane | Per-bar element-wise result. |
Reference auto-generated from the block catalog · category Math.