Wall Street staged a comeback Friday: U.S. stocks inched higher in the final minutes of trading after being down sharply earlier in the day.
After being down more than 150 points in the morning, the Dow Jones industrial average ended the day with a gain of 3 points. That was just enough for the index to end higher for a fifth week.
The S&P 500 added 1 point, closing just below its all-time high. For the week, however, the S&P ended basically unchanged.
The Nasdaq gained 8 points for the day, and nearly 1% for the week.
After a pullback in June, stocks hit record highs this month as Chairman Ben Bernanke and other Fed officials downplayed concerns about the central bank's $85 billion-per-month bond buying program.
This week, investors sifted through a slew of reports on corporate earnings and rewarded companies that beat expectations.
But the tone was cautious Friday as investors looked ahead to next week's meeting of top Fed officials and the government's monthly jobs report.
"Investors are taking profits now and waiting to see how next week shakes out," said J.J. Kinahan, chief derivatives strategist at TD Ameritrade. "Why take unnecessary risk heading into it?"
Click here for more on stocks, bonds, commodities and currencies
Earnings are a mixed bag: Tech shares have been the biggest drivers this week, boosted by strong earnings from Apple (AAPL) and Facebook (FB). But weak results from Amazon (AMZN) and Expedia (EXPE) put pressure on the sector Friday.
Expedia shares plunged after the online travel company plunged 24% on a worse-than-expected earnings report.
Amazon shares were lower after the online retailer posted a surprise loss. And Zynga's (ZNGA) stock sank after the online gaming company issued a weak outlook for the third quarter and said it's not going to pursue online gambling in the United States.
But the losses were offset by shares of Activision Blizzard (ATVI), which surged more than 21% after the maker of games such as World of Warcraft and Call of Duty said it was striking out on its own through an $8.2 billion deal.
Starbucks (SBUX) shares rose after the coffee merchant delivered better-than-expected quarterly earnings and sales.
Related: Fear & Greed Index, still greedy
Halliburton (HAL) stock rose nearly 4% after the Justice Department said the oilfield services firm would plead guilty to destroying computer test results that had been sought as evidence in the Deepwater Horizon disaster.
Tesla Motors (TSLA) shares gained after Deutsche Ban (DB)k upgraded the electric car maker.
Among the companies scheduled to report next week are energy giants Exxon (XOM) and Chevron (CVX).
More than half of the companies in the S&P 500 have reported results for the second quarter, with 66% of them topping analysts expectations, according to S&P Capital IQ.
Earnings growth has been strongest in the financial and consumer discretionary sectors, while materials and telecommunications companies have seen profits decline.
In economic news, the University of Michigan and Thomson Reuters said a key measure of consumer sentiment rose to 85.1 in July, the highest level in six years.
Overseas markets: European markets ended mostly lower, though shares of Pearson (PSO) and LVMH (LVMHF) rose after the companies posting better-than-expected earnings.
In Asia, Japan's benchmark Nikkei index fell by 3% as the yen strengthened. Japan's inflation turned positive for the first time in a year, a sign that Abenomics is taking hold.
The performance on Chinese indexes was more muted. Hong Kong's Hang Seng index rose by 0.2% and the Shanghai Composite index declined by 0.5%.