error with donchian channel function.

library(quantmod)
library(PerformanceAnalytics)
s <- get(getSymbols('SPY'))["2012::"]
s$sma20 <- SMA(Cl(s) , 20)
s$position <- ifelse(Cl(s) > s$sma20 , 1 , -1)
myReturn <- lag(s$position) * dailyReturn(s)
charts.PerformanceSummary(cbind(dailyReturn(s),myReturn))
s$dc <- DonchianChannel(,s$SPY.High,s$SPY.Low)

i get a error
Error in try.xts(HL, error = as.matrix) :
argument "HL" is missing, with no default

What mistake am i doing for s$dc?

See help("DonchianChannel")—the function is expecting something in the position just prior to s$SPY.High.

How do i convert the s$SPY.High,s$SPY.Low object to a matrix?

Usage
DonchianChannel(HL, n = 10, include.lag = FALSE)
Arguments
HL
Object that is coercible to xts or matrix and contains High-Low prices.

n
Number of periods for moving average.

include.lag
Should values be lagged so that today's prices are not included in the calculation? See Note.

Similar to

s <- data.frame(high = 6:10,low = 1:5)
s
#>   high low
#> 1    6   1
#> 2    7   2
#> 3    8   3
#> 4    9   4
#> 5   10   5
m <- as.matrix(s)
m
#>      high low
#> [1,]    6   1
#> [2,]    7   2
#> [3,]    8   3
#> [4,]    9   4
#> [5,]   10   5
1 Like

The Donchian channel is an indicator used in market trading developed by Richard Donchian. It is formed by taking the highest high and the lowest low of the last n periods. The area between the high and the low is the channel for the period chosen. It is commonly available on most trading platforms. TQ

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.