如何在R中添加简单移动平均线到highchart?

问题描述 投票:0回答:1

您好,我想在此烛台图表上添加简单移动平均线(使用 highchart,而不是图表系列),但我一直失败。如何将此 SMA 添加到我的图表中?有什么帮助吗? add_SMA(n = 200,on = 1,col =“红色”),add_SMA(n = 50,on = 1,col =“黑色”)

`开始<- format(as.Date("2015-01-01"), "%Y-%m-%d") end <- format(as.Date("2024-10-03"), "%Y-%m-%d")

股票代码<- "PFE"

价格<- getSymbols(ticker, auto.assign = FALSE, from = start, to = end)

头(价格)

highchart(type = "股票") %>% hc_add_series(价格) %>% hc_title(text = "价格烛台图 2015-2024")`

r quantmod ticker
1个回答
0
投票

您可以使用

SMA
功能,选择要平均的时间段。

library(highcharter)
library(TTR)

highchart(type = "stock") %>% 
  hc_add_series(price) %>% 
  hc_add_series(SMA(price$PFE.Close, n=10)) %>% 
  hc_title(text = "Price Candlestick Chart 2015-2024")

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.