Skip to content

Commit

Permalink
Update Articles
Browse files Browse the repository at this point in the history
  • Loading branch information
serkor1 committed Nov 4, 2023
1 parent 662d909 commit b884873
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 43 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(availableTickers)
export(chart)
export(getQuote)
export(kline)
export(ohlc)
importFrom(TTR,BBands)
importFrom(curl,has_internet)
importFrom(httr,GET)
Expand Down
14 changes: 11 additions & 3 deletions R/chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param deficiency Logical. FALSE by default, if TRUE color defiency compliant
#' colors are used.
#' @param slider Logical. TRUE by default. If FALSE, no slider will be included.
#'
#' @family Charting
#' @returns NULL
#' @export

Expand Down Expand Up @@ -79,7 +79,15 @@ kline <- function(
}



#' chart quote using
#' ohlc bars
#'
#' @param quote A cryptoQuote in xts/zoo format.
#' @param deficiency Logical. FALSE by default, if TRUE color defiency compliant
#' colors are used.
#' @param slider Logical. TRUE by default. If FALSE, no slider will be included.
#' @family Charting
#' @export
ohlc <- function(
quote,
deficiency = FALSE,
Expand Down Expand Up @@ -150,7 +158,7 @@ ohlc <- function(
#' indicators
#'
#' @param slider Logical. TRUE by default.
#'
#' @family Charting
#' @export
chart <- function(
chart,
Expand Down
108 changes: 68 additions & 40 deletions R/chart_indicators.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#' @param ... See [TTR::BBands()]

#' @returns NULL
#' @family chart indicators
#' @export
addBBands <- function(
plot,
Expand Down Expand Up @@ -133,6 +134,8 @@ addBBands <- function(
#'
#' @returns NULL
#' @example man/examples/scr_charting.R
#'
#' @family chart indicators
#' @export
addVolume <- function(plot) {

Expand Down Expand Up @@ -200,9 +203,14 @@ addVolume <- function(plot) {
#' `r lifecycle::badge("experimental")`
#' @param plot A plotly object of either
#' klines or OHLC
#'

#'
#' @param ... See [TTR::MACD()]
#' @example man/examples/scr_charting.R
#'
#'
#' @family chart indicators
#' @export
addMACD <- function(
plot,
Expand All @@ -228,57 +236,70 @@ addMACD <- function(
)


plot_ <- plotly::plot_ly(
data = indicator,
showlegend = FALSE,
name = 'MACD',
x = ~Index,
y = ~(macd - signal),
color = ~direction,
type = 'bar',
colors = c(
ifelse(
test = deficiency,
yes = '#FFD700',
no = 'tomato'
),
ifelse(
test = deficiency,
yes = '#0000ff',
no = 'palegreen'
)
plot_ <- plotly::plot_ly(
data = indicator,
showlegend = FALSE,
name = 'MACD',
x = ~Index,
y = ~(macd - signal),
color = ~direction,
type = 'bar',
colors = c(
ifelse(
test = deficiency,
yes = '#FFD700',
no = 'tomato'
),
marker = list(
line = list(
color = 'rgb(8,48,107)',
width = 0.5)
)
) %>% plotly::add_lines(
data = indicator,
showlegend = FALSE,
x = ~Index,
y = ~signal,
inherit = FALSE
) %>% plotly::add_lines(
data = indicator,
showlegend = FALSE,
x = ~Index,
y = ~macd,
inherit = FALSE
) %>% plotly::layout(
yaxis = list(
title = 'MACD'
ifelse(
test = deficiency,
yes = '#0000ff',
no = 'palegreen'
)
),
marker = list(
line = list(
color = 'rgb(8,48,107)',
width = 0.5)
)
) %>% plotly::add_lines(
data = indicator,
showlegend = FALSE,
x = ~Index,
y = ~signal,
color = I('steelblue'),
inherit = FALSE
) %>% plotly::add_lines(
data = indicator,
showlegend = FALSE,
x = ~Index,
y = ~macd,
color = I('orange'),
inherit = FALSE
) %>% plotly::layout(
yaxis = list(
title = 'MACD'
)
) %>% plotly::add_annotations(
x= 0,
y= 1,
xref = "paper",
yref = "paper",
text = 'Placeholder',
showarrow = FALSE,
font = list(
size = 12
)

)



plot$macd <- plot_
attributes(plot)$quote <- attributes(plot)$quote

return(

invisible(plot)
invisible(plot)


)
Expand All @@ -304,6 +325,9 @@ addMACD <- function(
#' @param ... See [TTR::SMA()]
#'
#' @example man/examples/scr_charting.R
#'
#'
#' @family chart indicators
#' @export
addMA <- function(plot, FUN = TTR::SMA, ...) {

Expand Down Expand Up @@ -392,6 +416,9 @@ addMA <- function(plot, FUN = TTR::SMA, ...) {
#' @param ... See [TTR::RSI()]
#' @returns NULL
#' @example man/examples/scr_charting.R
#'
#'
#' @family chart indicators
#' @export
addRSI <- function(
plot,
Expand Down Expand Up @@ -462,6 +489,7 @@ addRSI <- function(
#'
#' @example man/examples/scr_addVlines.R
#'
#' @family chart indicators
#' @export
addVlines <- function(plot, object, color = 'steelblue') {

Expand Down
9 changes: 9 additions & 0 deletions man/addBBands.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions man/addMA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions man/addMACD.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions man/addRSI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions man/addVlines.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions man/addVolume.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/chart.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/kline.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions man/ohlc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b884873

Please sign in to comment.