S&P, Dow wrap up a losing week

NEW YORK (CNNMoney) -- U.S. stocks flip-flopped Friday but closed slightly higher as investors remained skittish about the health of the economy after the latest report on home sales signaled further trouble for housing.

Only the Nasdaq was able to eke out a gain of 0.5% for the week. Both the S&P 500 and Dow closed the week down 1.1% and 0.5% respectively

"Investors are starting to think we're getting late into the rally," said Rick Bensignor, chief market strategist at Merlin Securities.

It's been quite a rally so far. Even after several days of losses this week, the Nasdaq is up nearly 18% in 2012. Both the S&P 500 and the Dow are up 11% and 7%.

Some analysts say those high spikes are starting to encounter some resistance.

"Investors have one eye on China and are scared to death of what could happen to the economy," said Paul Powers, head of US equity trading at Raymond James. "The other eye is watching the recovery in the US which seems to be hanging in there."

Commodities helped lift the overall stock market Friday. Traders focused on reports citing the likelihood that Iranian oil exports would drop by the end of March. The fear of a decrease in supply pushed up oil prices and, in turn, oil stocks.

Homebuilders took a hit, too. KB Home (KBH) reported a sharp loss and said the quarter included a big drop in new orders. Its shares fell considerably, as did those of other major homebuilders including PulteGroup (PHM, Fortune 500), Lennar (LEN) and Toll Brothers (TOL).

The latest data follow several mediocre reports released earlier in the week on existing home sales and new home construction. Bucking the trend, a report on building permits was the strongest in more than three years.

And while mortgage rates rose this week, they are still relatively cheap. Analysts are hoping that the improved jobs picture will help lift the housing market.

Companies: Shares of Apple (AAPL, Fortune 500) were halted briefly in late morning trading after what appeared to be an erroneous trade that pushed the stock to $543 from $598. Trading quickly resumed, with shares trading back around $598. A Nasdaq spokesperson said the exchange canceled trades executed between 11:14 a.m. and 11:15 a.m ET.

Bank of America (BAC, Fortune 500) announced a pilot program that would allow delinquent homeowners to relinquish the deed to the property and transition to tenant status. Only 1,000 homeowners are eligible for the pilot.

BATS Global Markets (BATS), an equities and options exchange operator, started trading Friday at $15.25, after pricing its initial public offering at $16, the low end of its estimated range. Trading has been halted since late morning as the exchange said it was investigating system issues. By day's end, BATS announced it withdrew its IPO.