Package 'lightweightchartR'

Title: Pipe-First TradingView Lightweight Charts for Quantmod Workflows
Description: Wraps TradingView's lightweight-charts library as an htmlwidgets package with a pipe-first API designed around quantmod, xts, and common trading workflows.
Authors: Alex Kraieski [aut, cre]
Maintainer: Alex Kraieski <[email protected]>
License: GPL-3
Version: 0.1.1
Built: 2026-05-17 05:17:47 UTC
Source: https://github.com/arkraieski/lightweightchartR

Help Index


Add an area series from a chart column

Description

Add an area series from a chart column

Usage

add_area(chart, column = NULL, pane = "price", name = NULL, color = "#0f766e")

Arguments

chart

A lightweightchartR chart object.

column

Source column. Defaults to the close column.

pane

Target pane.

name

Optional series name.

color

Series color.

Value

The updated chart object.


Add OHLC bars from chart data

Description

Add OHLC bars from chart data

Usage

add_bars(
  chart,
  pane = "price",
  name = "Bars",
  up_col = "#26a69a",
  down_col = "#ef5350"
)

Arguments

chart

A lightweightchartR chart object.

pane

Target pane.

name

Optional series name.

up_col, down_col

Rising and falling colors.

Value

The updated chart object.


Add Bollinger Bands

Description

Add Bollinger Bands

Usage

add_bbands(
  chart,
  n = 20,
  sd = 2,
  column = NULL,
  pane = "price",
  color = "#7c3aed",
  ...
)

Arguments

chart

A lightweightchartR chart object.

n

Window size.

sd

Number of standard deviations.

column

Source column. Defaults to the close column.

pane

Target pane.

color

Series color.

...

Reserved for future extensions.

Value

The updated chart object.


Add candlesticks from chart data

Description

Add candlesticks from chart data

Usage

add_candles(
  chart,
  pane = "price",
  name = "Candles",
  up_col = "#26a69a",
  down_col = "#ef5350"
)

Arguments

chart

A lightweightchartR chart object.

pane

Target pane.

name

Optional series name.

up_col, down_col

Rising and falling colors.

Value

The updated chart object.


Add an exponential moving average

Description

Add an exponential moving average

Usage

add_ema(chart, n = 20, column = NULL, pane = "price", color = "#ea580c", ...)

Arguments

chart

A lightweightchartR chart object.

n

Window size.

column

Source column. Defaults to the close column.

pane

Target pane.

color

Series color.

...

Reserved for future extensions.

Value

The updated chart object.


Add a histogram series from a chart column

Description

Add a histogram series from a chart column

Usage

add_histogram(
  chart,
  column = NULL,
  pane = "histogram",
  name = NULL,
  color = "#7c3aed",
  pane_height = 1
)

Arguments

chart

A lightweightchartR chart object.

column

Source column. Defaults to the close column.

pane

Target pane.

name

Optional series name.

color

Series color.

pane_height

Relative pane height for the target pane.

Value

The updated chart object.


Add a line series from a chart column

Description

Add a line series from a chart column

Usage

add_line(chart, column = NULL, pane = "price", name = NULL, color = "#2563eb")

Arguments

chart

A lightweightchartR chart object.

column

Source column. Defaults to the close column.

pane

Target pane.

name

Optional series name.

color

Series color.

Value

The updated chart object.


Add MACD in a separate pane by default

Description

Add MACD in a separate pane by default

Usage

add_macd(
  chart,
  nFast = 12,
  nSlow = 26,
  nSig = 9,
  column = NULL,
  pane = "macd",
  pane_height = 1,
  ...
)

Arguments

chart

A lightweightchartR chart object.

nFast, nSlow, nSig

MACD periods.

column

Source column. Defaults to the close column.

pane

Target pane.

pane_height

Relative pane height for the RSI pane.

...

Reserved for future extensions.

Value

The updated chart object.


Add RSI in a separate pane by default

Description

Add RSI in a separate pane by default

Usage

add_rsi(
  chart,
  n = 14,
  column = NULL,
  pane = "rsi",
  color = "#dc2626",
  pane_height = 0.8,
  ...
)

Arguments

chart

A lightweightchartR chart object.

n

Window size.

column

Source column. Defaults to the close column.

pane

Target pane.

color

Series color.

pane_height

Relative pane height for the RSI pane.

...

Reserved for future extensions.

Value

The updated chart object.


Add a simple moving average

Description

Add a simple moving average

Usage

add_sma(chart, n = 20, column = NULL, pane = "price", color = "#2563eb", ...)

Arguments

chart

A lightweightchartR chart object.

n

Window size.

column

Source column. Defaults to the close column.

pane

Target pane.

color

Series color.

...

Reserved for future extensions.

Value

The updated chart object.


Add a generic indicator or comparison series

Description

Add a generic indicator or comparison series

Usage

add_ta(
  chart,
  values,
  type = c("line", "area", "histogram"),
  pane = "price",
  name = NULL,
  color = "#2563eb",
  pane_height = NULL,
  overlay = identical(pane, "price")
)

Arguments

chart

A lightweightchartR chart object.

values

An xts, zoo, or data frame object with a time column.

type

One of "line", "area", or "histogram".

pane

Target pane. Defaults to "price".

name

Optional display name.

color

Optional series color.

pane_height

Relative pane height for new panes.

overlay

Whether to overlay on the existing price scale.

Value

The updated chart object.


Add volume bars

Description

Add volume bars

Usage

add_volume(
  chart,
  pane = "price",
  color_up = "#26a69a",
  color_down = "#ef5350",
  pane_height = 0.6
)

Arguments

chart

A lightweightchartR chart object.

pane

Target pane. Defaults to "volume".

color_up, color_down

Colors for rising/falling volume bars.

pane_height

Relative pane height for the volume pane.

Value

The updated chart object.


Compatibility wrapper for quantmod users

Description

chart_series_lwc() offers a quantmod-flavored bridge into the pipe-first chart API. It recognizes a small subset of common chartSeries() and addTA() workflows.

Usage

chart_series_lwc(
  x,
  type = c("auto", "candles", "bars", "line", "area"),
  subset = NULL,
  show.grid = TRUE,
  name = NULL,
  log.scale = FALSE,
  TA = NULL,
  theme = c("light", "dark"),
  up.col = "#26a69a",
  dn.col = "#ef5350",
  ...
)

Arguments

x

Market data. Usually an xts object with OHLC or OHLCV columns.

type

Base series type. "auto" chooses candlesticks when OHLC data is available and a line chart otherwise.

subset

Optional quantmod-style subset string, passed through xts.

show.grid

Included for API familiarity. Currently ignored.

name

Optional display name for the chart.

log.scale

Included for API familiarity. Currently ignored.

TA

Optional semicolon-delimited TA expressions like "addVo();addSMA(n = 20)".

theme

"light" or "dark".

up.col, dn.col

Rising and falling colors for price series.

...

Reserved for future compatibility arguments.

Value

A lightweightchartR chart widget.


Shiny bindings for lightweightchartR

Description

Shiny bindings for lightweightchartR

Usage

lightweightchartROutput(outputId, width = "100%", height = "480px")

renderLightweightchartR(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

Output variable to read from.

width, height

CSS dimensions for the widget container.

expr

An expression that generates a chart.

env

The environment in which to evaluate expr.

quoted

Is expr already quoted?


Create a lightweight chart

Description

lwc_chart() creates a TradingView lightweight chart widget from xts, zoo, or data frame inputs. The result is a pipeable chart object that can be extended with ⁠add_*()⁠ helpers.

Usage

lwc_chart(
  data,
  type = c("auto", "candles", "bars", "line", "area"),
  subset = NULL,
  name = NULL,
  theme = c("light", "dark"),
  width = NULL,
  height = NULL,
  elementId = NULL,
  up_col = "#26a69a",
  down_col = "#ef5350",
  ta_tooltip = TRUE,
  ta_tooltip_threshold = 14
)

Arguments

data

Market data. Usually an xts object with OHLC or OHLCV columns.

type

Base series type. "auto" chooses candlesticks when OHLC data is available and a line chart otherwise.

subset

Optional quantmod-style subset string, passed through xts.

name

Optional display name for the chart.

theme

"light" or "dark".

width, height

Widget dimensions passed to htmlwidgets.

elementId

Optional element id.

up_col, down_col

Rising/falling color defaults for price series.

ta_tooltip

Whether to show hover tooltips for price-pane technical analysis overlays.

ta_tooltip_threshold

Pixel distance used to match the pointer to the nearest overlay line for the TA tooltip.

Value

An htmlwidget object that also supports pipe-based layer helpers.


Reconfigure an existing chart

Description

rechart_lwc() updates global display options on an existing chart.

Usage

rechart_lwc(chart, theme = NULL, ...)

Arguments

chart

A lightweightchartR chart object.

theme

Optional replacement theme.

...

Additional lightweight-charts chart options merged into the existing top-level options.

Value

The updated chart object.