![](/img/trans.png)
[英]How do I make this table into a data frame? I'm using R. Trying to get the ANOVA table for it
[英]Hello, I've been trying to create a trading signal for macd in R. I'm having difficulty generating the signal and the data frame that has the signals
首先,我使用 quantmod 將數據導入 R。
getSymbols("QQQ")
QQQ <- xts::last(QQQ, "1 year")
QQQ
然后,我使用 MACD function 得到我的 etf 的 MACD。
macd_QQQ <- MACD(QQQ[,"QQQ.Close"], nFast = 12, nSlow = 26, nSig = 9, percent = FALSE)
macd_QQQ
我也獲得了 ADX。
adx_QQQ <- ADX(QQQ, n =14)
adx_QQQ
然后我指定了我想要的整體功能的哪些值
adx <- adx_QQQ$ADX
adx
macd <- macd_QQQ$macd
macd
目前,我被困在這里
macd_indicator <- function(macd)
if (macd > 0) {
signal <- "buy"
} else {
signal <- "sell"
}
代碼運行沒有問題,但我很困惑為什么買賣信號沒有根據 macd 的值產生。
任何幫助表示贊賞
不過,我不會把錢押在這上面。
library(tidyquant) # It uses Quantmod
library(tidyverse)
library(lubridate)
tq_get("QQQ", from = today() %m-% years(1)) %>%
tq_mutate(select = close,
mutate_fun = MACD) %>%
mutate(signal = if_else(macd > 0, "BUY", "SELL")) %>%
ggplot() +
aes(x = date, y = close, col = signal) +
geom_point() +
theme_light()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.