US stocks close midweek mostly with gains on upbeat earnings