Docs

ta.spread

Take the bar by bar difference of two series, such as two instruments.

itm
ta.spread(a, b)

a - b, bar by bar. It can be written as a plain subtraction. The id gives a cross-instrument spread a name the clock rule attaches to: a declared series lands on the chart's clock as of each chart bar, completed bars only, so ta.spread(close, d.close) is an as-of difference and never a peek at a forming bar.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeDefaultRangeDescription
aSeriesnumber--The series to read.
bSeriesnumber--The series to read.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
None.
Missing values
na when either series is na on this bar. Pointwise: no window, no warm-up.

Example

itm
ta.spread(close, open)
itm
spy = series(symbol="SPY")
plot(ta.spread(close, spy.close), "Spread")