[英]Why do Close and HLC have different methods to share data?
When I compare the 2 methods, SMA()
needs close price as first parameter in xts format and D onchianChannel()
needs HL in xts format.当我比较这两种方法时,
SMA()
需要收盘价作为 xts 格式的第一个参数,而 D onchianChannel()
需要 xts 格式的 HL。 However the usage is Cl(mktdata)
for SMA vs HLC(mktdata)[, 1:2]
for DonchianChannel()
.但是,SMA 的用法是
Cl(mktdata)
,而 DonchianChannel DonchianChannel()
) 的用法是HLC(mktdata)[, 1:2]
。
Why is this so?为什么会这样? why cannot i just use
HLC(mktdata)
?为什么我不能只使用
HLC(mktdata)
?
add.indicator(strategy = strategy.st,
name = "SMA",
arguments = list(x = quote(Cl(mktdata)),
n = 30),
label = "nSlow")
add.indicator(strategy = strategy.st,
# correct name of function:
name = "DonchianChannel",
arguments = list(HL = quote(HLC(mktdata)[, 1:2]),
n = 20),
label = "DCH"
)
HLC(mktdata)
returns a 3 column xts object (High, Low and Close columns), but in DonchianChannel(HL = )
, HL
expects 2 columns, containing the high and low prices, or just 1 column (of say close prices). HLC(mktdata)
返回 3 列 xts object(高、低和收盘列),但在DonchianChannel(HL = )
中, HL
期望 2 列,包含最高价和最低价,或者只有 1 列(比如收盘价)。 Not 3 columns.不是 3 列。
Look at the source code of the function and you'll see the # of columns guard at the start:查看 function 的源代码,您会在开头看到 # of columns guard:
DonchianChannel <- function (HL, n = 10, include.lag = FALSE)
{
HL <- try.xts(HL, error = as.matrix)
if (!(NCOL(HL) %in% c(1, 2))) {
stop("Price series must be either High-Low, or Close/univariate.")
}
.........
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.