Stocks ended with modest gains on Thursday, shifting back and forth on incremental developments in Europe where leaders sought to reassure investors that a solution to the debt crisis would come soon.

The S&P has alternated gains and losses for seven days at the close and has kept to a tight range as markets watch for the latest news out of Europe.

Germany and France released a statement on Thursday saying leaders would now hold two summits to discuss the debt crisis, with a solution in place by Wednesday's second meeting.

The statement was enough for us to come off the lows, but there is still a long way to go, said Robert Pavlik, chief market strategist at Banyan Partners LLC in New York.

Market anxiety remained elevated. The CBOE Volatility Index VIX <.VIX>, Wall Street's fear gauge, rose more than 1 percent to near 35, extending gains after rising nearly 10 percent on Wednesday.

Supporting the market, U.S. economic data showed factory activity in the U.S. Mid-Atlantic region rebounded in October while a separate report showed U.S. jobless claims fell last week.

On the negative side, other data showed a drop in sales of existing-homes last month and only a small rise in a gauge of future growth.

Financial and materials stocks were the day's top gainers. The S&P 500 financial sector index <.GSPF> rose 1.8 percent and materials <.GSPM> climbed 1 percent.

The Dow Jones industrial average <.DJI> ended up 37.16 points, or 0.32 percent, at 11,541.78. The Standard & Poor's 500 Index <.SPX> was up 5.51 points, or 0.46 percent, at 1,215.39. The Nasdaq Composite Index <.IXIC> was down 5.42 points, or 0.21 percent, at 2,598.62.

Progress by EU leaders toward a solution is considered vital for Wall Street stocks to break out of their trading range.

The S&P 500 has struggled after reaching the top end of a two-month trading range at around the 1,230-1,250 level.

Investors are also closely watching the developing U.S. earnings season. According to Thomson Reuters data, of the 109 companies in the S&P 500 that have reported earnings, 70 percent have topped analysts' expectations.

After the closing bell, Microsoft shares fell 0.5 percent to $26.87 following quarterly results. During regular trading Microsoft finished at $27.04, down 0.3 percent.

Ingersoll Rand Plc posted lower quarterly earnings, and its fourth-quarter profit forecast fell short of some Wall Street estimates, due to depressed housing and consumer markets, sending shares down 7.9 percent to $27.38.

Polycom Inc
fell more than 25 percent to $16.33 and weighed on the Nasdaq after the videoconferencing company reported quarterly revenue well below market expectations. The NYSEArca networking index <.NWX> lost 1.8 percent.

Trading volume was about 7.8 billion shares on the New York Stock Exchange, NYSE Amex and Nasdaq, below this year's daily average of about 8 billion.

On the NYSE, advancers beat decliners by a ratio of three to two, while on the Nasdaq, decliners beat advancers by a ratio of 12 to 11.

(Reporting by Angela Moon, Editing by Kenneth Barry)