NEW YORK — The Dow and S&P 500 ended at record highs on Friday, and stocks posted a third consecutive week of gains as a rise in Google and other technology shares offset a slide in energy stocks.

Nasdaq led gains, boosted by a 1 percent rise in Google’s stock, which also led the S&P 500′s rise.

Indexes were flat for much of the session but managed a late-day surge. On Thursday, the S&P 500 broke a five-day streak of record closing highs.

Stocks have risen on the Federal Reserve’s accommodative monetary stance and some encouraging corporate earnings, but analysts said momentum could wane without further positive signs.

“I think it’s going to be hard to maintain these levels in the short term,” said Natalie Trunow, chief investment officer of equities at Calvert Investment Management, which has about $13 billion in assets.

“There are not a lot of positive catalysts to keep it going,” she said, noting that spending cuts by the federal government could pressure the economy in the near term.

Oil prices tumbled as the U.S. dollar hit a 4 1/2-year high against the yen and the dollar index was on track for its strongest week against other major currencies in 10 months. A strong dollar makes commodities priced in the greenback, such as gold and oil, more expensive for foreign investors, pressuring shares of energy and basic materials companies.

The Dow Jones industrial average was up 35.87 points, or 0.24 percent, at 15,118.49. The Standard & Poor’s 500 Index was up 7.03 points, or 0.43 percent, at 1,633.70. The Nasdaq Composite Index was up 27.41 points, or 0.80 percent, at 3,436.58.

The S&P 500 is up 14.6 percent for the year. For the week, the Dow rose 1 percent, the S&P 500 1.2 percent and the Nasdaq 1.7 percent.

Exxon Mobil lost 1 percent to $90.14 and helped drag on the Dow. The S&P energy index dropped 0.5 percent as Brent and U.S. crude oil prices fell.

Shares of Priceline jumped 3.9 percent to $765.41, a day after the online travel company reported a first-quarter profit that topped estimates.

It was among several stronger-than-expected profit reports this week that have helped stocks as the first-quarter earnings period draws to a close.

Shares of electric carmaker Tesla Motors jumped 10.6 percent to $76.76, adding to Thursday’s gain of 24.4 percent and making it one of the Nasdaq’s top percentage gainers.

Tesla is part of a group of companies with heavy bets against them from investors. Recent upbeat results have triggered a wave of short-covering.

In contrast, shares of Hess Corp. slid 2.3 percent to $69.30. Chief executive John Hess, son of the company’s founder, is being stripped of his duties as chairman as the oil and gas company scrambles to avoid an embarrassing defeat by an activist investor.

Volume was roughly 5.7 billion shares traded on the New York Stock Exchange, the Nasdaq and the NYSE MKT, below the average daily closing volume of about 6.4 billion this year.

Volume has been weak throughout the market’s rally, and this week has seen below-average volume on every day except Thursday when the market fell.

Advancers outpaced decliners on the NYSE by nearly 9 to 5 and the Nasdaq by a ratio of about 2 to 1.