The S&P 500 and the Nasdaq have advanced to record closing highs, boosted by robust earnings and a dip in crude prices.