Stocks gained for a fourth straight day on Thursday as equity markets rallied into the end of the quarter, boosted by a surprisingly strong report on manufacturing in the U.S. Midwest.

Business activity in the region grew more than expected this month, lifted by a jump in new orders. That helped ease recent concerns about the economy that have weighed on markets over the past two months.

The case for a weakening at the national level is now less strong, said Pierre Ellis, senior economist at Decision Economics in New York. The really good news is that orders jumped back up.

The Dow Jones industrial average <.DJI> gained 129.30 points, or 1.05 percent, to 12,390.72. The Standard & Poor's 500 Index <.SPX> rose 11.25 points, or 0.86 percent, to 1,318.66. The Nasdaq Composite Index <.IXIC> added 28.15 points, or 1.03 percent, to 2,768.64.

The S&P 500 moved above its 50-day moving average at 1,317, a level where analysts said the index would meet resistance.

The S&P 500 has gained more than 3 percent in its best three-day run in three months as the Greek parliament on Wednesday adopted austerity measures to avoid a debt default. On Thursday, lawmaker passed a law that will permit implementation of the plan that was demanded by European officials.

The S&P 500 is down less than 1 percent this quarter, while the Dow is up 0.5 percent and the Nasdaq is off 0.5 percent.

Much of the recent rally has been traced to end-of-quarter window dressing by fund managers, who typically sell losers and buy winners to make their portfolios look better.

The Federal Reserve ends its $600 billion bond-buying program, known as QE2, on Thursday and has not offered any hints of more monetary easing. Markets were volatile in May and June, partly on concerns about QE2's end.

EBay Inc rose 4.5 percent to $32.25 after both Citigroup and Bank of America-Merrill Lynch upgraded the shares to buy. They cited the Federal Reserve saying third-party networks like eBay's PayPal unit will not be regulated like payment networks.

First Solar Inc surged 9.3 percent to $141.64 after the solar panel maker won conditional loan guarantees from the U.S. Department of Energy worth $4.5 billion for three of its largest projects.

(Reporting by Edward Krudy; editing by Jeffrey Benkoe)