vendredi 21 décembre 2018

How to handle multiple conditions in 1 if statement?

I am comparing a 20-day moving average against a 50-day, 100-day 200-day and 333-day. The condition is essentially just

if(20MA > 50MA > 100MA > 200MA > 333MA) { return TRUE } else{ FALSE }

Is there a way in R to handle this without multiple nested if statements?

if(tail(MA_20,n=1) > tail(MA_50,n=1) > tail(MA_100,n=1) > tail(MA_200,n=1) > tail(MA_333,n=1)) {
  score[1] <- 1
} else{
  score[1] <- -1
}

Aucun commentaire:

Enregistrer un commentaire