I am plotting the donchian high and low using tidy packages. the low value does not look correct. I am probably not calling the donchian function properly as the donchian_100_low is the highest value of the row. I dont know how to fix it.
library(tidyverse)
library(tidyquant)
library(ggthemes)
startdt <- "2021-02-01"
AMC <- tq_get(
"AMC",
get = "stock.prices",
from = startdt
)
AMC_values <- AMC %>%
mutate(
# EMA_20 = EMA(close, n = 20),
# EMA_50 = EMA(close, n = 50),
Don_100=DonchianChannel(high,low)
) %>%
na.omit()
head(AMC_values)
results:
head(AMC_values)
# A tibble: 6 x 9
symbol date open high low close volume adjusted Don_100[,"high"] [,"mid"] [,"low"]
<chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 AMC 2021-02-17 5.58 5.62 5.32 5.55 38849000 5.55 17.2 11.4 5.62
2 AMC 2021-02-18 5.84 6.25 5.46 5.51 130540800 5.51 10.1 7.86 5.62
3 AMC 2021-02-19 5.54 5.77 5.51 5.7 40249100 5.7 9.77 7.70 5.62
4 AMC 2021-02-22 5.93 6.68 5.75 6.55 173409000 6.55 8.74 7.18 5.62
5 AMC 2021-02-23 6.97 7.86 6.01 7.7 264876400 7.7 8.27 6.94 5.62
6 AMC 2021-02-24 7.23 9.83 6.99 9.09 376881800 9.09 9.83 7.72 5.62
The problem is the input into
DonchianChannel
. The input needs to be a matrix of 2 columns, not 2 separate columns. If you check the help it says:But it is a bit unclear. The example with it shows it a bit better, either a data.frame, matrix or xts object is fine.
Note that if you want a donchian channel with
n = 100
, you need to specify then
, default is:n = 10
.To get it to work in your case, with tidyquant:
which matches when you would do this via quantmod: