market closed with gains for fourth week