Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5632d04
:hammer: New utility functions
serkor1 Oct 3, 2025
f5140d5
:hammer: Flexible main charts
serkor1 Oct 3, 2025
1ca708b
:hammer: Updated series function
serkor1 Oct 3, 2025
5613593
:hammer: Charting Tools
serkor1 Oct 3, 2025
8a9d26b
:books: Updated README
serkor1 Oct 4, 2025
0cf1cb8
:hammer: Updated charting functions
serkor1 Oct 9, 2025
89c2e18
:hammer: Added helper-function
serkor1 Oct 9, 2025
3ea7f64
:hammer: Adapted downstream indicators
serkor1 Oct 9, 2025
1993735
:books: Initial draft of charting vignette
serkor1 Oct 9, 2025
d90e7f2
:hammer: Added agnostic-flag to pattern chart
serkor1 Oct 9, 2025
d35027b
:hammer: Updated rebuild_formula
serkor1 Oct 10, 2025
be94905
:hammer: Updated candlestick patterns
serkor1 Oct 10, 2025
3272f14
:bug:-fix in chart()
serkor1 Oct 11, 2025
eed5a1d
:hammer: Modified ACCBANDS and BBANDS
serkor1 Oct 11, 2025
7fdf8be
:hammer: Added modeBarButtons
serkor1 Oct 12, 2025
2774f5c
:hammer: Added upper + lower args
serkor1 Oct 18, 2025
a748add
:books: Documented chart() args
serkor1 Oct 18, 2025
ab638f0
:hammer: Added configs to chart-elements
serkor1 Oct 18, 2025
1d7d0ce
:hammer: adapted MACD plotly method
serkor1 Oct 18, 2025
62bc1e2
:bug:-fix in in backend
serkor1 Oct 18, 2025
a902964
:hammer: Updated README images
serkor1 Oct 18, 2025
f5cc51d
:hammer: Compatibility issues with %||% fixed
serkor1 Oct 18, 2025
95e7f74
:hammer: Chart meta-data
serkor1 Oct 18, 2025
9a8d54a
:fire: New indicator: trading_volume
serkor1 Oct 18, 2025
8f42991
:books: Updated documentation
serkor1 Oct 18, 2025
16136bf
:books: Updated documentation for trading_volume()
serkor1 Oct 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ S3method(three_white_soldiers,data.frame)
S3method(three_white_soldiers,default)
S3method(three_white_soldiers,matrix)
S3method(three_white_soldiers,plotly)
S3method(trading_volume,data.frame)
S3method(trading_volume,default)
S3method(trading_volume,matrix)
S3method(trading_volume,numeric)
S3method(trading_volume,plotly)
S3method(two_crows,data.frame)
S3method(two_crows,default)
S3method(two_crows,matrix)
Expand Down Expand Up @@ -369,9 +374,11 @@ export(three_line_strike)
export(three_outside)
export(three_stars_in_the_south)
export(three_white_soldiers)
export(trading_volume)
export(triangular_moving_average)
export(triple_exponential_moving_average)
export(two_crows)
export(ultimate_oscillator)
export(volume)
export(weighted_moving_average)
useDynLib(talib, .registration = TRUE)
77 changes: 71 additions & 6 deletions R/chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#'
#' @param x An OHLC object to be charted.
#' @param type A [character] of [length] 1. Either `candlestick` or `ohlc`.
#' @param idx A [vector] with the same [length] of `x`. If passed it will replace the x-axis labels. See `vignette("charting")` for more details.
#' @param title An optional [character] vector of [length] 1.
#' @param ... Parameters passed into [plotly::plot_ly]
#'
#' @example man/examples/charting.R
Expand All @@ -31,6 +33,8 @@
chart <- function(
x,
type = "candlestick",
idx = NULL,
title,
...
) {
## clear env if called
Expand All @@ -54,6 +58,7 @@ chart.default <- function(
x,
type = "candlestick",
idx = NULL,
title,
...
) {
## default chart function
Expand All @@ -71,6 +76,15 @@ chart.default <- function(
## 3. chart: The user-facing TA chart.
## This is empty and is constructed on the fly
## via plotly::subplot.

## extract title
if (missing(title)) {
chart_title <- input_name(
substitute(x)
)
} else {
chart_title <- title
}
.color_values <- .chart_theme()
.plotting_environment$sub <- .plotting_environment$chart <- list()

Expand All @@ -81,8 +95,27 @@ chart.default <- function(
## NOTE: it is also a hard requirement on
## {plotly} side
x <- as.data.frame(x)
x$idx <- if (is.null(idx)) 1:nrow(x) else idx
x$idx <- if (is.null(idx)) {
## check if rownames can be
## converted to integer
is_valid <- suppressWarnings(
!is.na(as.integer(rownames(x)[1]))
)
if (is_valid) {
as.integer(
rownames(x)
)
} else {
rownames(x)
}
} else {
idx
}
.plotting_environment$x <- data_frame <- x
.plotting_environment$idx <- list(
label = x$idx,
index = seq_along(x$idx)
)

## generate price chart
## based on type. can be either
Expand Down Expand Up @@ -129,18 +162,50 @@ chart.default <- function(
alpha = 1 ## This should be controlled from .chart_theme()
)
),

## remove legend
## there is no reason to display
## it in the legend.
##
## If there is demand for it we can
## implement a heuristic to determine intervals
## for 1h, 2h, etc. Similar to {cryptoQuotes}
showlegend = FALSE,
...
)

## construct chart meta data
##
## There is no relevant information in the range 1:N
## so if the rownames only contrains integers the chart will
## skip it
if (is.integer(.plotting_environment$idx$label)) {
title_text <- sprintf(
fmt = "<b>Ticker:</b> %s <br><sub><b>N:</b> %d </sub>",
chart_title,
nrow(x)
)
} else {
title_text <- sprintf(
fmt = "<b>Ticker:</b> %s <br><sub><b>N:</b> %d <b>Period:</b> %s </sub>",
chart_title,
nrow(x),
paste(
.plotting_environment$idx$label[1],
"-",
.plotting_environment$idx$label[length(
.plotting_environment$idx$label
)]
)
)
}

## store in main chart
## (see description)
.plotting_environment$main <- .chart_layout(
x = price_chart,
title_text = sprintf(
"<b>Ticker:</b> %s <br><sub><b>Period:</b> %s</sub>",
deparse(substitute(x)),
"Period Value"
)
title_text = title_text,
idx = idx
)

.plotting_environment$main
Expand Down
Loading
Loading