Home S&P 500, Nasdaq gain in choppy trading as most megacaps move higher