Stocks closed out the first half of the year with double-digit percentage gains, powered by an economic recovery that many investors believe is still gathering pace.

The S&P 500 is up 14% this year, closing June at a record, while the Dow Jones Industrial Average has climbed 13%. This quarter will mark both indexes’ fifth consecutive quarter of gains, their longest such streak since a nine-quarter stretch that lasted through 2017.

The mood should be ebullient. Data on everything from hiring to consumer spending to small business-owners’ confidence have bounced back and stayed above their pandemic lows.

Yet, for many money managers, the past few months have felt like anything but a straightforward win. After a 12-month period in which it seemed stocks could do nothing but go up, many say the outlook is growing increasingly opaque.

These days, “nothing really gets killed, but nothing really does that great,” said Andrew Slimmon, a managing director at Morgan Stanley Investment Management. “There’s no definable trend, [and] there’s little agreement in the market.”

Investors are heading into the second half of the year weighing whether a recent acceleration in inflation is shaping up to be transitory, or the start of a longer-term trend that might force the Federal Reserve to pick up its pace of interest-rate increases.

Yields on 10-year U.S. Treasurys, meanwhile, suggest that after snapping back from the Covid-19 shutdown, longer-term economic growth might be more muted than investors expected just a few months ago. That is in part due to dimming prospects for additional, huge stimulus from the federal government.

So even as stocks march upward, and volatility is subdued, there is growing anxiety that future gains will be harder won.

In June alone, stocks logged both their worst week since October and their best week since February. Value stocks were among the best performers for the quarter, but growth stocks held their own, too.

To some extent, the market’s seeming lack of direction is normal. Stocks are now in the second year of a bull market, after bouncing back from the pandemic-fueled selloff of 2020. Going back to World War II, it has been typical in the second year of a recovery for trading to be choppy and for stocks to log more muted gains, according to LPL Financial chief market strategist Ryan Detrick.

Underneath the surface, market moves have been unusually sharp and swift—hinting at just how undecided many traders are about the direction of the economy.

In one such example, the correlation between growth and value stocks has broken down, trading at around the lowest level since 1995, according to data provider Refinitiv. That is unusual. The two typically move in opposite directions. Investors tend to favor pricier growth stocks when they believe economic growth will be scarce and turn to more economically sensitive value stocks—like banks, energy companies and industrials—when they anticipate a pickup in the economy.

Kansas City Southern shares have risen this year, one of many economically sensitive stocks to perform well.

Kansas City Southern shares have risen this year, one of many economically sensitive stocks to perform well.

Photo: Luis Antonio Rojas/Bloomberg News

This year, stocks in both categories have performed well. Railroad Kansas City Southern has risen 39% this year, while the KBW Nasdaq Bank Index has added 28%. Technology stocks have continued to make gains, too, with Applied Materials Inc. up 65% and PayPal Holdings Inc. up 24%.

What does the lack of a coherent narrative across the market tell us?

Investors are “less certain about what is going to happen in 2022,” said Morgan Stanley’s Mr. Slimmon.

The bull case for markets goes something like this: The economy’s rebound has been undeniable. Corporate earnings have shined, too; a record number of S&P 500 companies have issued positive earnings and sales guidance for the second quarter, according to FactSet.

Warning signs still abound, though. Many investors believe much of the economy’s rebound has been priced in. Money managers also say they believe that with major indexes trading at records, markets look priced for perfection. This means it might not take much to send stocks lower.

Recently, the U.S. inflation rate reached a 13-year high, triggering a debate about whether the country is entering an inflationary period similar to the 1970s. WSJ’s Jon Hilsenrath looks at what consumers can expect next. Photo: Alexander Hotz The Wall Street Journal Interactive Edition

In a June survey, Deutsche Bank AG found that investors identified higher-than-expected inflation, new Covid-19 variants that often bypass vaccines, and a central bank policy error as the three top risks to market stability.

Inflation in particular has proved tricky for investors to make bets on.

Goldman Sachs Group Inc. is forecasting that the core consumer-price index, which excludes the often-volatile categories of food and energy, will pull back from recent highs to around 2.3% next year. The Labor Department’s reading of core inflation had come in at 3.8% in May, the biggest year-over-year increase since 1992.

But the bank’s team acknowledges it could be wrong. If so, investors could be in for a tougher trading environment. Since 1960, the median return for the S&P 500 has been 15% in low-inflation periods and 9% in high-inflation periods, Goldman’s team found.

Even seasoned investors say they have struggled to discern whether soaring prices across markets from used cars to housing to gasoline are being caused by one-time issues, or are a prelude to more long-lasting and broad inflation.

Data on hiring and consumer spending have bounced back, supporting stock prices.

Data on hiring and consumer spending have bounced back, supporting stock prices.

Photo: octavio jones/Reuters

Instead of trying to make market decisions based on where she guesses interest rates are headed, Nancy Tengler, chief investment officer at Laffer Tengler Investments, is sticking to building portfolios based on longer-term trends that she anticipates will persist regardless of how inflation pans out.

She has put money in companies such as Amazon.com Inc. and Microsoft Corp. , which have invested in cloud-computing services and technologies that are rising in popularity.

“I have one toe in the ‘this isn’t transitory camp’ and the other in the camp that thinks this is probably likely to pass,” Ms. Tengler said. “At this point, I don’t think we can really draw stark conclusions.”

Energy stocks are some of the best performers in the S&P 500 this year.

Energy stocks are some of the best performers in the S&P 500 this year.

Photo: andrew kelly/Reuters

Write to Akane Otani at akane.otani@wsj.com