I am trying to write my own signal function in quantstrat. The logic I am struggling with is the same as is used in other R operations.
data[,colNums[1]] etc. returns a vector of values.
sigPair <- function( label, data = mktdata, columns )
{
ret_sig = FALSE
colNums <- match.names(columns, colnames(data))
ratio_minus_dn <- data[, colNums[1]] - data[, colNums[3]]
ret_sig <- do.call(">", list(data[, colNums[1]], data[, colNums[2]]))
ret_sig <- ifelse( min(tail(ratio_minus_dn, 400)) < 0, ret_sig, FALSE )
colnames(ret_sig) <- label
return(ret_sig)
}
It is this line:
ret_sig <- ifelse( min(tail(ratio_minus_dn, 400)) < 0, ret_sig, FALSE )
that is giving me problems.
The error I get is:
Error in colnames<-
(*tmp*
, value = "cross.up") :
attempt to set colnames on object with less than two dimensions
My intention is to check if ratio_minus_dn has been <0 in the last 400 elements and return true in that case.
What would be a good way to accomplish this task?
Thankful for all tips!