Skip to content

Commit

Permalink
Fix RSI when user provides multiple maTypes
Browse files Browse the repository at this point in the history
The if-statement was checking the formals() of the list, not the
function. The example also needed to be amended because it threw
warnings, which have rightfully begun to be ERRORs in R CMD check.

Fixes #101.
  • Loading branch information
joshuaulrich committed Aug 27, 2020
1 parent 6b20706 commit 130006a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions R/RSI.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
#' rsiMA1 <- RSI(price, n=14, maType="WMA", wts=ttrc[,"Volume"])
#'
#' # Case of two different 'maType's for both MAs
#' rsiMA2 <- RSI(price, n=14, maType=list(maUp=list(EMA,ratio=1/5),
#' maDown=list(WMA,wts=1:10)))
#' rsiMA2 <- RSI(price, n=14, maType=list(maUp=list(EMA),maDown=list(WMA)))
#'
#'
"RSI" <-
Expand Down Expand Up @@ -114,7 +113,7 @@ function(price, n=14, maType, ...) {
# If MA function has 'n' arg, see if it's populated in maType;
# if it isn't, populate it with RSI's formal 'n'
for(i in 1:length(maType)) {
if( !is.null( formals(maType[[i]])$n ) && is.null( maType[[i]]$n ) ) {
if( !is.null( formals(maType[[i]][[1]])$n ) && is.null( maType[[i]]$n ) ) {
maType[[i]]$n <- n
}
mavgUp <- do.call( maType[[1]][[1]], c( list(up), maType[[1]][-1] ) )
Expand Down
3 changes: 1 addition & 2 deletions man/RSI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 130006a

Please sign in to comment.