Stocks closed out a fourth week of gains in quiet fashion on Friday, edging higher as the market took a breather after rallying 3 percent on Europe's deal to stem its debt crisis.

Though investors still have questions about implementing the deal, they appeared satisfied by Europe's progress as stocks ended their longest weekly winning streak of the year.

The S&P 500 rose 3.7 percent for the week. The benchmark index had a seven-week rally that ended in January, but only two of the weeks were in 2011.

October also was on track to be the best month for stocks since 1974, supported by strong earnings. Merck & Co Inc and Chevron Corp both topped expectations with financial results on Friday.

For it to not sell off is as much a positive sign as anything, said Andrew Slimmon, managing director at Global Investment Solutions of Morgan Stanley Smith Barney in Chicago.

We have had a very good earnings season and the benefit of what happened in Europe is that it allows investors to focus on the good earnings season and move the European problem from the primary worry to off the headlines.

The Dow Jones industrial average <.DJI> gained 22.56 points, or 0.18 percent, to 12,231.11. The Standard & Poor's 500 Index <.SPX><.INX> added 0.49 point, or 0.04 percent, to 1,285.08. The Nasdaq Composite Index <.IXIC> shed 1.48 points, or 0.05 percent, to 2,737.15.

Concerns that the euro zone debt crisis would spread and stifle domestic bank profits had been a huge overhang for equities, with the S&P down almost 20 percent -- defined as a bear market -- early this month.

As optimism grew about Europe's debt plan, bulls began to gain momentum and the S&P 500 is now up more than 13 percent this month, on pace for its biggest monthly gain since October 1974.

According to Thomson Reuters data, of the 315 companies in the S&P 500 that have reported quarterly results, 71 percent have posted earnings above analyst expectations.

The head of Europe's bailout fund played down hopes of a quick deal with China for that country to throw its support behind efforts to resolve the crisis but said he expects Beijing to continue to buy bonds issued by the rescue fund.

Hewlett-Packard Co gained 3.5 percent to $27.94 a day after it said it was ditching a plan to spin off its personal computers unit, a plan that was expected to have cost billions of dollars in expenses and lost business.

A pair of Dow components posted stronger-than-expected earnings. Merck rose 2.3 percent to $35.11 after its profit and sales beat analyst estimates, and Chevron's profit more than doubled. The stock advanced 0.6 percent to $109.64.

MF Global Holdings Ltd slumped 16.1 percent to $1.20. Some customers are moving money away from the futures brokerage, rivals, hedge fund officials and analysts said, though the extent of the outflows is unclear.

Economic data on Friday showed U.S. consumer sentiment improved in October for the second month in a row as consumers felt more upbeat about the economy's prospects.

Volume was about 7.71 billion shares traded on the New York Stock Exchange, NYSE Amex and Nasdaq, below the daily average of 8.03 billion.

Declining stocks outnumbered advancing ones on the NYSE by 1,505 to 1,475, while on the Nasdaq, decliners beat advancers 1,406 to 1,114.

(Reporting by Chuck Mikolajczak; Editing by Kenneth Barry)