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. For multi-column TTR functions where you want several outputs, prefer ledgr_ind_ttr_outputs().

Usage

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

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.

history_class

Optional history class for a TTR form that is not a registered package catalogue row. Registered forms take their class from the catalogue; a contradicting declaration refuses. An undeclared unregistered form is disclosed as "history_dependent".

tolerance

Optional comparison tolerance for an unregistered form declared "bounded"; see ledgr_indicator(). Registered rows have no runtime tolerance.

input_carry

Optional input-carry declaration for an unregistered form; see ledgr_indicator(). Registered rows take it from the catalogue and refuse a declaration.

...

Explicit arguments forwarded to the TTR function.

Value

A ledgr_indicator object.

Details

Registered TTR forms are catalogued per function, selected output and algorithm-changing argument (for example maType or wilder). Each row declares its history class, required bar fields and dependency width and is certified by package tests. Any other argument combination, or a requires_bars that differs from the catalogue width, is an unregistered form that follows the custom-definition rules of ledgr_indicator().

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"