2023 has been a momentous year for the stock market. The Dow Jones Industrial Average (^DJI 0.40%) reached new all-time highs in mid-December. The S&P 500 is within spitting distance of its own record level, and the Nasdaq Composite isn't far off.

If you've remained invested in the stock market throughout the past few years, then 2023 has provided more proof of what history has said countless times before: After bear markets and other significant market downturns, stocks have always recovered and rewarded long-term investors. But for many who lost confidence in stocks during 2022's bear market, 2023 has been frustrating, because it has shown how selling stocks at their lows can ultimately prove counterproductive.

Regardless of whether you have a stock-heavy portfolio or are just now thinking about investing in stocks, a look back at the past can reveal a lot about what the best strategy is when stocks are at all-time highs. It's not complicated, and many long-term investors will find that they don't have to change a thing about what they're doing in order to remain successful well into the future.

New York Stock Exchange.

Image source: Getty Images.

What bull market history has to say

When you look back at past bull markets, you can see that on many occasions, stocks continue to gain ground even after they've made big moves to return to all-time highs. After the financial crisis in 2008 and 2009, it took the S&P 500 until March 2013 to surpass its old high from 2007 and hit new record levels. Some investors suggested that after such an impressive recovery, it would be smart to take some money off the table.

Yet what happened after that was a nearly seven-year run of success, with the S&P continuing to rise and set records consistently on dozens of occasions between that first new all-time high and early 2020. By the end, the index had more than doubled from its record close in March 2013.

^SPX Chart

^SPX data by YCharts.

The same thing happened after the lightning bear market at the beginning of the COVID-19 pandemic. After plunging in February and March 2020, markets recovered quickly, and the S&P returned to record levels that August. Again, some felt it prudent to reduce stock exposure at that point, yet the S&P climbed another 40% between August 2020 and January 2022 before the most recent bear market began.

^SPX Chart

^SPX data by YCharts.

Admittedly, there have been occasions when stocks recovered to record levels just to fall again. After the tech bubble burst in 2000 through 2002, it took the market seven years to reach new records. Yet the S&P only rose another few percent before the financial crisis took hold.

^SPX Chart

^SPX data by YCharts.

The right strategy for right now

With history as background, there are several things to consider with markets at all-time highs. The right way to approach things right now depends a lot on your particular situation.

If you still have a long time horizon before you'll need the money that you're investing, then there's little reason to pay attention to the ups and downs of the market. Keep saving and consistently invest more into stocks, and you'll benefit from what have historically been superior returns.

If it took all your discipline to avoid selling stocks at 2022's bear market lows, then pat yourself on the back for having outlasted the downturn. However, look critically at your asset allocation. Did you overestimate your ability to weather a severe bear market? If so, consider a more conservative investing approach. That doesn't mean selling all your stocks right away, but it could mean shifting a percentage out of the market into other asset classes like bonds and cash.

Similarly, if you're retired and have been spending down your cash cushion in order to avoid having to sell stocks at lows, then now's a good time to consider replenishing your cash reserves. Again, you don't necessarily want to sell a huge amount right now, but taking steps to give yourself the balance you want is essential for the success of your long-term strategy.

On the other hand, if you've been out of the market, you might think now's the worst time to invest. Yet the smart move is still to make some stock purchases, perhaps through a dollar-cost averaging strategy that ensures all of your money won't go in at the absolute top if a market downturn is on the way.

A final thing to consider

Lastly, bear in mind that just because the Dow Jones and other indexes are at or near all-time highs, many individual stocks remain far below their record levels. Indeed, it's the very fact that many stocks are still playing catch-up at the end of a bear market that often keeps driving market indexes higher.

All-time highs are exciting, but they shouldn't have a huge impact on your investing. By keeping an even keel and not letting headlines affect you too much, you'll be in a better position to reap the true rewards that await those with a long-term investing mindset.