When I compare the 2 methods, SMA() needs close price as first parameter in xts format and DonchianChannel() needs HL in xts format. However the usage is Cl(mktdata) for SMA vs HLC(mktdata)[, 1:2] for DonchianChannel().
Why is this so? why cannot i just use 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 inDonchianChannel(HL = ),HLexpects 2 columns, containing the high and low prices, or just 1 column (of say close prices). Not 3 columns.Look at the source code of the function and you'll see the # of columns guard at the start: