Megacap tech stocks and positive corporate earnings helped drive main U.S. indexes up again. Yields on U.S. Treasuries were also up, as was the dollar, with investors eyeing next week's Federal Reserve meeting for hints on the U.S. economic recovery from the COVID-19 pandemic and when the central bank will pull back support for the economy.

"It's certainly been a really strong run. For now it looks justified based on the strong earnings results. We got interest rate stability, which was helpful. As the economic recovery continues, as long as people are continuing to get out there despite the Delta variant, we think stocks can go higher," said Jeff Buchbinder, equity strategist for LPL Financial. "We think the ride will get bumpier in the second half, but we think the bull market continues."

The Dow Jones Industrial Average rose 238.2 points, or 0.68%, to close the week at 35,061.55, while the S&P 500 gained 44.31 points, or 1.01%, to 4,411.79. The Nasdaq Composite added 152.39 points, or 1.04%, to close at 14,836.99.

The greenback on Friday booked a second week of gains after a volatile few days as risk appetite waxed and waned.

The dollar index, which measures the greenback against a basket of six major currencies, was slightly higher on the day at 92.894. That was off a 3-1/2-month high of 93.194 hit on Wednesday.

For the week, it was up 0.1%, after rising 0.6% previously.

The yield on 10-year Treasury notes hovered around 1.3%, or almost 17 basis points higher than a five-month low set on Tuesday, but was still at the low end of a recent range. The benchmark note traded up 2.1 basis points to 1.288% after briefly rising above 1.3%.

"We're closing out the week on a very nice trade, and it's being driven by earnings primarily and earnings specifically in stocks that speak to the consumer, which is not a new story but it's a story that adds momentum to the trade in the second half of the year," said Peter Kenny, founder of Kenny & Co LLC, the parent company for Strategic Board Solutions and Kenny's Commentary, a subscriber-based political and economic newsletter.

After declining earlier in the trading session, oil was set to end the week slightly up.

Investors have been assuming "things will improve, travel will increase," said Steve Massocca, managing director at Wedbush Securities. "There are concerns about the Delta variant."

Massocca added, "If that thesis is thrown into jeopardy, it put a hitch in the 'giddy up' in the market."

Some parts of the United States are implementing mask mandates again due to new COVID-19 cases, while others have not, leading to confusion.

U.S. business activity grew at a moderate pace for a second straight month in July amid supply constraints, suggesting a cooling in economic activity, a report from data firm IHS Markit showed on Friday.

Positive corporate earnings helped the stock market. American Express Co jumped 1.7% after posting second-quarter profit that beat expectations.

Social media firms Twitter Inc and Snap Inc gained 3.8% and 24.5%, respectively, after their upbeat results.

Financial markets have swung from one direction to another this week as investors try to assess what the surging Delta variant means for the world economy.

After recording its steepest one-day drop since May on Monday, the S&P 500 stock index went on to post the biggest one-day jump since March a day later. Currency, bond and commodities markets have seen similar gyrations.

(Graphic: S&P 500 stock index vs absolute change, daily, )

(Reporting by Jessica DiNapoli; Additional reporting by Dhara Ranasinghe and Wayne Cole in Syndey; Editing by Ana Nicolaci da Costa, Will Dunham, Pravin Char, Dan Grebler and Raissa Kasolowsky)

By Jessica DiNapoli