Skip to content

Commit

Permalink
Research on adding new indicators.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereckmezquita committed Jul 9, 2024
1 parent 547d779 commit a3f9699
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 85 deletions.
85 changes: 0 additions & 85 deletions dev/research/fib-ichimoku.R

This file was deleted.

36 changes: 36 additions & 0 deletions dev/research/fib.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
box::use(dmplot)
box::use(dmplot[ fib ])
box::use(dt = data.table)

box::use(kucoin[ get_market_data ])

ticker <- "BTC/USDT"

data <- get_market_data(
symbols = ticker,
from = lubridate::now() - lubridate::days(100),
to = lubridate::now(),
frequency = "1 hour"
)

high_price <- max(data$high)
low_price <- min(data$low)

fib_levels <- dmplot$fib(high_price, low_price)

data.frame(fib_levels) |>
ggplot2::ggplot(ggplot2::aes(x = levels, y = prices)) +
ggplot2::geom_point()

box::use(ggplot2)

# Assuming 'data' has columns 'date' and 'close'
ggplot2$ggplot(data, ggplot2$aes(x = datetime, y = close)) +
ggplot2$geom_line() +
ggplot2$geom_hline(yintercept = fib_levels$prices, color = "blue", linetype = "dashed") +
ggplot2$scale_y_continuous(breaks = fib_levels$prices, labels = paste0(fib_levels$levels * 100, "%")) +
ggplot2$labs(
title = "Price Chart with Fibonacci Retracement Levels",
x = "Date",
y = "Price"
)
46 changes: 46 additions & 0 deletions dev/research/ichimoku.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
box::use(dmplot)
box::use(ggplot2)
box::use(dt = data.table)
box::use(kucoin[ get_market_data ])

ticker <- "BTC/USDT"

data <- get_market_data(
symbols = ticker,
from = lubridate::now() - lubridate::days(100),
to = lubridate::now(),
frequency = "1 hour"
)

tenkan_period = 9L
kijun_period = 26L
senkou_period = 52L

dmplot$ichimoku_cloud2(
data$high, data$low, data$close, tenkan_period, kijun_period, senkou_period
) |> dt$as.data.table()

data

data[,
c("tenkan_sen", "kijun_sen", "senkou_span_a", "senkou_span_b", "chikou_span") :=
dmplot$ichimoku_cloud2(
high, low, close, tenkan_period, kijun_period, senkou_period
)
]

summary(data$chikou_span)

# Create the plot
tail(na.omit(data), 250) |>
ggplot2$ggplot(ggplot2$aes(x = datetime)) +
ggplot2$geom_line(ggplot2$aes(y = close), color = "black") +
ggplot2$geom_line(ggplot2$aes(y = tenkan_sen), color = "blue") +
ggplot2$geom_line(ggplot2$aes(y = kijun_sen), color = "red") +
ggplot2$geom_ribbon(
ggplot2$aes(ymin = pmin(senkou_span_a, senkou_span_b),
ymax = pmax(senkou_span_a, senkou_span_b)),
fill = "green",
alpha = 0.2
) +
ggplot2$geom_line(ggplot2$aes(y = chikou_span), color = "purple")

0 comments on commit a3f9699

Please sign in to comment.