Wall Street edged higher on Thursday after six days of losses as a narrowed U.S. trade deficit was seen as one positive point for growth in a recent avalanche of weak economic data.

But the mood remained fragile with many analysts expecting the S&P 500 to retest its March 2010 lows after falling more than 6 percent since a peak in May, and the latest data from the labor market provided little room for optimism.

We're basically trading off technicals, said William Larkin, a portfolio manager with Cabot Money Management in Salem, Massachusetts.

We're going to be in a very active trading range, and we just need a couple of key warnings -- on consumer confidence, energy prices, whatever -- and markets could continue to weaken.

Energy shares were among the biggest gainers as crude oil rose. The S&P's energy sector <.GSPE> rose 0.7 percent. Chevron Corp added 0.5 percent to $100.44.

The Dow Jones industrial average <.DJI> gained 21.57 points, or 0.18 percent, to 12,070.51. The Standard & Poor's 500 Index <.SPX> added 2.53 points, or 0.20 percent, to 1,282.09. The Nasdaq Composite Index <.IXIC> dipped 0.28 points, or 0.01 percent, to 2,675.10.

The S&P 500 is up just 1.9 percent for the year. The index faces resistance at 1,310, around its low in late May, and has support at 1,250, its March low, according to analysts at Brown Brothers Harriman in New York.

U.S. stocks have held in a pattern recently of selling off in the second half of the day as investors look for a bottom.

The U.S. trade deficit narrowed unexpectedly in April, as U.S. exports rose to a record and imports from Japan tumbled more than 25 percent in the aftermath of the March earthquake, tsunami and nuclear disaster, a U.S. government report showed on Thursday.

The number of Americans filing new claims for unemployment benefits rose by 1,000 last week, however, according to a report on Thursday that could add to fears the labor market recovery has stalled.

(Additional reporting by Ryan Vlastelica; Editing by Padraic Cassidy)