A batch of U.S. company earnings drove stocks mostly higher on Thursday.

The major stock indexes shifted between small gains and losses ahead of their scheduled close for Good Friday. The gains kept the indexes ahead for the week, though they remained down for the month.

The market appeared set Thursday morning for its fourth-consecutive positive open this week, but immediately turned negative as investors sold shares in Google and IBM. The market heavyweights reported disappointing earnings late Wednesday. Earnings from toy maker Mattel and insurer UnitedHealth also dragged down the market.

But by midmorning, the market started to push higher as traders cheered upbeat results from Morgan Stanley, General Electric and PepsiCo.

"We were expecting this earnings season to be pretty volatile, and it's proven to be true so far, in that we're seeing some differences in the results," said Paul Mangus, head of equity research and strategy for Wells Fargo Private Bank.

All told, the S&P 500 index rose two points, or 0.1 percent, to close at 1,864.85. Seven of the 10 industry sectors in the S&P 500 increased, led by energy stocks. The Nasdaq added nine points, or 0.2 percent, to 4,095.52. The Dow, however, slipped 16 points, or 0.1 percent, to 16,408.54.