The S&P 500 and the Nasdaq closed higher on Wednesday while gold resumed its ascent as investors weighed upbeat earnings against mounting trade tensions between the United States and China.