All three major stock indexes closed at records on Friday with the Dow Jones Industrial Average eking out gains to extend its record-setting streak to a seventh session.

With the exception of the Nasdaq Composite, the stock market had languished in negative territory most of the day but recouped losses toward the closing bell.

The Dow DJIA, -0.46% added 4.28 points to finish at 20,624.05 for a weekly gain of 1.8%. The S&P 500 index SPX, -0.84% edged up 3.94 points, or 0.2%, to close at 2,351.16, climbing 1.5% on the week. The Nasdaq Composite Index COMP, -1.26% rose 23.68 points, or 0.4%, to end at 5,838.58, up 1.8% for the week.

“Bears are waiting for the other shoe to drop but when the market held up today and Nasdaq went positive, investors covered their short positions ahead of the weekend,” said Doug Cote, chief market strategist at Voya Investment Management.

The stock and bond markets will be closed on Monday for the Presidents Day holiday.

The euphoria surrounding President Trump’s proposed economic policies—fueled by optimism around the prospect of tax cuts and increased infrastructure spending—have helped to push U.S. stocks to all-time highs even as some of the enthusiasm had faded in recent days.

“We are seeing continued momentum in the rally, despite some occasional wobbles.” Richard Hastings, a macro strategist at Seaport Global Securities LLC. “Yes, we are concerned that individual investors are slowly getting more neutral, but the bias higher seems intact.”

At Trump presser, a tale of two realities

The sentiment on Wall Street generally points to more upside for stocks once investors have a clearer picture of Trump’s plans for tax reform and the health-care overhaul even as the market goes through periodic corrections.

“I still remain optimistic on the market going forward,” said Gary Anetsberger, chief executive officer at Millennium Trust Co.

Stock movers: UnitedHealth Group UNH, -0.50% slumped 6%. The company, the country’s largest health insurer, is being sued by the Justice Department for allegedly overcharging Medicare, according to reports.

Boeing Co. BA, +0.04% shares rose 1.1%, up for a seventh session, bolstered by a visit from President Trump who reiterated his “America First” message and promise to create more jobs.

Shares of Kraft Heinz Co. KHC, -2.29% and Unilever PLC ULVR, -1.12% UN, +0.49% UL, +0.40% rocketed higher after Kraft said Unilver had rejected its initial merger offer. The company indicated that talks were still ongoing.

Shares of Deere & Co. DE, +2.10% rose 1% after earnings and sales beat forecasts. The maker of construction equipment offered up an upbeat outlook.

J.M. Smucker Co. shares SJM, -0.75% fell 1.4% after the jam maker issued a weak outlook.

Campbell Soup Co. shares CPB, +0.72% sank 6.5% after second-quarter profit and revenue missed forecasts.

General Mills Inc. shares GIS, -1.99% slid 3.8% after the company lowered its sales outlook.

Other markets: Asian stocks ADOW, +0.29% finished mostly lower and European stocks SXXP, +0.04% slipped.after U.S. stocks largely stepped back from their record run.

The U.S. Dollar Index DXY, -0.05% rose while oil prices US:CLJ7 declined, and gold US:GCJ7 was also weaker.

--Barbara Kollmeyer contributed to this article.