U.S. stocks ground higher in another lightly traded session on Friday, ending a nervous week with gains despite signs of economic weakness at home and worries about public debt in Europe.

Major indexes rose for the second straight week even though housing and labor market data raised concern about the fragility of the recovery. The S&P 500 closed above its 200-day moving average for the third straight session, which suggests resilience.

A lot of investors did get very bearish here, and that's a good sign that we had some selling. That has probably exhausted itself, so the pressures are ebbing, said Steve Goldman, market strategist, Weeden & Co. in Greenwich, Connecticut.

Energy shares helped support the Dow and S&P 500 on Friday, with some investors betting stocks beaten down due to the Gulf of Mexico oil spill had run their course. Cameron International rose 1 percent to $37.98 while Halliburton Co rose 2.2 percent to $26.98.

The Dow Jones industrial average <.DJI> gained 16.47 points, or 0.16 percent, to 10,450.64. The Standard & Poor's 500 Index <.SPX> rose 1.47 points, or 0.13 percent, to 1,117.51. The Nasdaq Composite Index <.IXIC> added 2.64 points, or 0.11 percent, to 2,309.80.

The market has struggled to make headway since Tuesday's strong run when stocks rose on positive feelings engendered from successful debt auctions in Europe.

The broad-based S&P 500 is down about 8 percent since a recent high on April 23 after having fallen around 14 percent, largely on fears on sovereign debt defaults in Europe.

For the week, the Dow and the S&P 500 gained 2.4 percent and the Nasdaq added 3 percent.

Energy shares rose with crude oil ending higher at $77.18 a barrel. Exxon Mobil Corp was up 0.8 percent at $63.10, and was among top boosts to the Dow.

BP Plc's New York-traded shares edged 0.2 percent higher a day after its chief executive underwent a bruising appearance before a U.S. congressional committee over the oil spill and the company said it would establish a $20 billion compensation and clean-up fund.

Caterpillar Inc reported an 11 percent rise in global dealer sales of its heavy machinery in the three months ended in May, driven by strong growth in the Asia-Pacific region. The company's shares rose 1.5 percent to $65.85 and were the top boost to the Dow.

Traders said the convergence of four key expirations, known as quadruple witching, had added to volatility. Stock options expire later Friday, while index futures expired earlier in the session.

The June SPDR S&P 500 fund options, an exchange-traded fund that tracks the S&P 500 benchmark, showed a light turnover volume ahead of expiration at the close later in the day, according to Jon Najarian, founder of options information website optionMonster.com.

Declining shares included Teva's U.S.-listed shares , Bayer said on Thursday Teva's U.S. unit admitted in court that some of the information included on packages of its oral contraceptive, Gianvi, was false and agreed to correct its labeling. Teva fell 1.9 percent to $53.21.

CVS Caremark Corp rose 1.9 percent to $32.43 and Walgreen Co added 2.8 percent to $30.09 after the companies patched up their fight over reimbursements for drug prescriptions, salvaging a relationship worth billions of dollars.

Although the S&P 500 held above its 200-day moving average since Tuesday, it has found resistance near 1,121, a key level that marks the halfway point between the October 2007 historic highs and the lows of March 2009.

About 8.01 billion shares traded on the New York Stock Exchange, the American Stock Exchange and Nasdaq, well below last year's estimated daily average of 9.65 billion.