US stocks close higher to end 4-day losing streak