talib.SUB
Subtracts the second array from the first, element by element (Vector Arithmetic Subtraction).
talib.SUB(inReal0, inReal1)Examples
Subtract the low price from the high price of each K-line.
javascript
function main() {
var records = exchange.GetRecords()
if (!records) return
// high price minus low price
var highs = records.map(function(r) { return r.High })
var lows = records.map(function(r) { return r.Low })
var ret = talib.SUB(highs, lows)
Log(ret)
}
python
import talib
def main():
records = exchange.GetRecords()
if not records:
return
# high price minus low price
ret = talib.SUB(records.High, records.Low)
Log(ret)Returns
| Type | Description |
numeric array | Results, the same length as the input. |
Arguments
| Name | Type | Required | Description |
inReal0 | numeric array | Yes | First series. |
inReal1 | numeric array | Yes | Second series; it must have the same length as |
See Also
Remarks
TA-Lib equivalent: SUB(Array(inReal0),Array(inReal1)) = Array(outReal).
Calculates inReal0[i] - inReal1[i] element by element.
In JavaScript, both inputs must be numeric arrays (extract a field from the K-line data with map first): if a K-line array is passed, both inputs take the close price of the same K-line data and the result is meaningless; arrays of different lengths raise an error.