US stocks log gains for fourth week in a row