Skip to contents

Identifies where shortSeries crosses longSeries in either direction. A cross over is emitted as 1 and a cross under as -1, so the result equals the sum of cross_over() and cross_under().

Both comparisons are strict, so a series that only touches longSeries is not a crossing.

Usage

cross_series(shortSeries, longSeries, na.rm = FALSE)

Arguments

shortSeries

An integer or double vector.

longSeries

An integer or double vector of the same length as shortSeries, or of length 1 to compare against a fixed level.

na.rm

A logical of length 1. If TRUE, a crossing that involves a missing value on either bar is returned as NA. If FALSE (default), missing values are not checked and such bars are returned as 0.

Value

An integer vector of the same length as shortSeries with 1 where shortSeries crosses over longSeries, -1 where it crosses under and 0 otherwise. The first element is always NA as it has no previous bar.

See also

Other Signals: cross_over(), cross_under()

Author

Serkan Korkmaz

Examples

## short moving average crossing
## a long moving average
talib::cross_series(
  talib::SMA(talib::BTC$close, timePeriod = 10),
  talib::SMA(talib::BTC$close, timePeriod = 30)
)
#>   [1] NA  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#>  [26]  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#>  [51]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#>  [76]  0  0  0  0  0  0  0  0  0  0  0  0 -1  1  0  0  0  0  0  0  0  0  0  0  0
#> [101]  0  0  0  0  0  0 -1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [126]  0  0  0  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  0
#> [151]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 -1  0  0  0  0  0  0  0  0
#> [176]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [201]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 -1  0  0  0  0  0  0
#> [226]  0  0  0  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  0 -1  0  0
#> [251]  0  0  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  0  0
#> [276]  0  0  0  0  0  0  0 -1  0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  0
#> [301]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [326]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [351]  0  0  0  0  0  0  0  0  0  0 -1  0  0  0  0  0