The gains couldn’t overcome steep losses earlier in the week, and the S&P 500 remained in negative territory. President Trump’s tariff policy kept markets on edge.