Skip to contents

ledgr_ind_ttr() requires the suggested TTR package at construction time. Install TTR before creating TTR-backed indicators. For interactive debugging with ledgr_pulse_snapshot(), pass an active snapshot handle and the same TTR-backed feature declarations used by the experiment.

Usage

ledgr_ind_ttr(
  ttr_fn,
  input,
  output = NULL,
  id = NULL,
  requires_bars = NULL,
  stable_after = requires_bars,
  ...
)

Arguments

ttr_fn

TTR function name, for example "RSI", "ATR", or "MACD".

input

ledgr input shape. Supported values are "close", "hl", "hlc", "ohlc", and "hlcv".

output

Output column for multi-column TTR functions. Vector outputs use NULL. For common multi-output functions, use TTR's column names: BBands exposes dn, mavg, up, and pctB; MACD exposes macd and signal, and ledgr also supports derived histogram.

id

Optional indicator identifier. If omitted, ledgr builds a stable ID from the TTR function, explicit arguments, and output column.

requires_bars

Explicit warmup length. Required for unknown TTR functions. For known functions this is inferred from explicit arguments.

stable_after

First stable row. Defaults to requires_bars.

...

Explicit arguments forwarded to the TTR function.

Value

A ledgr_indicator object.

Articles

Indicators, feature IDs, and warmup: vignette("indicators", package = "ledgr") system.file("doc", "indicators.html", package = "ledgr")

Examples

if (requireNamespace("TTR", quietly = TRUE)) {
  rsi_14 <- ledgr_ind_ttr("RSI", input = "close", n = 14)
  rsi_14$id

  atr_20 <- ledgr_ind_ttr("ATR", input = "hlc", output = "atr", n = 20)
  atr_20$id

  bb_up <- ledgr_ind_ttr("BBands", input = "close", output = "up", n = 20)
  ledgr_feature_id(bb_up)

  macd <- ledgr_ind_ttr(
    "MACD",
    input = "close",
    output = "macd",
    nFast = 12,
    nSlow = 26,
    nSig = 9,
    percent = FALSE
  )
  macd_signal <- ledgr_ind_ttr(
    "MACD",
    input = "close",
    output = "signal",
    nFast = 12,
    nSlow = 26,
    nSig = 9,
    percent = FALSE
  )
  ledgr_feature_id(list(macd, macd_signal))
}
#> [1] "ttr_macd_12_26_9_false_macd"   "ttr_macd_12_26_9_false_signal"