Getting started with wickra

wickra exposes the Wickra technical-analysis library in R over its C ABI hub. Every indicator is a constructor returning a wickra_indicator; you feed it data one observation at a time with update() (an O(1) streaming step) or run a whole series at once with batch(). Both paths share the exact same Rust core, so a live feed and a historical backtest compute identical values.

library(wickra)
#> 
#> Attaching package: 'wickra'
#> The following object is masked from 'package:stats':
#> 
#>     HoltWinters

A sample series

The package ships a small synthetic OHLCV series, sample_ohlcv, for examples (a seeded random walk — not real market data).

head(sample_ohlcv)
#>         date   open   high    low  close  volume
#> 1 2023-01-02  99.67 102.11  99.03 101.69 2008760
#> 2 2023-01-03 101.70 102.07 100.25 101.04 1170273
#> 3 2023-01-04 100.68 101.52 100.54 101.52 1338059
#> 4 2023-01-05 101.58 102.39 101.51 102.33 1119735
#> 5 2023-01-06 102.73 103.17 101.79 102.87  741723
#> 6 2023-01-07 102.55 102.86 102.43 102.78  835901

Batch: a whole series at once

Scalar indicators run over a vector with batch(). Warmup positions are NA.

sma <- Sma(20)
sma_values <- batch(sma, sample_ohlcv$close)
tail(sma_values)
#> [1] 97.4500 97.6780 97.9385 98.2105 98.5645 98.7865

Streaming: one observation at a time

The same indicator fed tick-by-tick with update() returns the identical values — an equivalence the test suite enforces for every indicator.

sma_stream <- Sma(20)
streamed <- vapply(sample_ohlcv$close, function(p) update(sma_stream, p), numeric(1))

same_warmup <- all(is.na(streamed) == is.na(sma_values))
same_values <- all(streamed == sma_values, na.rm = TRUE)
c(batch_equals_streaming = same_warmup && same_values)
#> batch_equals_streaming 
#>                   TRUE

A typical streaming loop reacts to each value as it arrives:

rsi <- Rsi(14)
overbought_days <- 0L
for (price in sample_ohlcv$close) {
  v <- update(rsi, price)            # NA during warmup
  if (!is.na(v) && v > 70) overbought_days <- overbought_days + 1L
}
overbought_days
#> [1] 4

Multi-output indicators

Indicators with several outputs return a named numeric vector (NA while warming up). MACD is the classic example — line, signal, and histogram:

macd <- MacdIndicator(12, 26, 9)
last_macd <- c(macd = NA, signal = NA, histogram = NA)
for (price in sample_ohlcv$close) last_macd <- update(macd, price)
last_macd
#>      macd    signal histogram 
#> 1.2809934 0.6851743 0.5958191

Candle indicators

Indicators that need the whole bar take the OHLCV fields plus a timestamp:

atr <- Atr(14)
last_atr <- NA_real_
for (i in seq_len(nrow(sample_ohlcv))) {
  last_atr <- update(
    atr,
    sample_ohlcv$open[i], sample_ohlcv$high[i], sample_ohlcv$low[i],
    sample_ohlcv$close[i], sample_ohlcv$volume[i], i - 1
  )
}
last_atr
#> [1] 1.701354

Resetting state

reset() returns an indicator to its warmup state so the same object can be reused on a fresh series:

reset(sma)
update(sma, 100)   # NaN — warming up again
#> [1] NaN

Next steps

  • Full indicator catalogue, guides, and per-indicator reference: https://docs.wickra.org.
  • Every constructor (Sma(), Rsi(), MacdIndicator(), Atr(), …) is listed in this package’s help index.