When investing in the stock market, no variable is more important than time. While picking out high-quality stocks can certainly improve your chance of building wealth on Wall Street, it's time that's consistently been investors' greatest ally.

This is a fact that can easily be lost on new and tenured investors given the emotions that often come into play during major swings higher and lower in the iconic Dow Jones Industrial Average (^DJI 0.40%), widely followed S&P 500 (^GSPC 1.02%), and growth-dominated Nasdaq Composite (^IXIC 2.02%). Over the previous two years, we've seen all three indexes scream to record-closing highs, as well as plunge into a bear market and produce their worst full-year returns in more than a decade.

But if investors were to take a step back and look at the bigger picture, they'd see why being a long-term optimist pays off handsomely.

A bull figurine placed atop a financial newspaper, and in front of multiple clippings of volatile stock charts.

Image source: Getty Images.

This is exactly how long the average bull and bear market lasts

As much as investors might dislike the idea of corrections, bear markets, and even stock market crashes, they're a perfectly normal part of the long-term investing cycle.

According to data provided by sell-side consultancy firm Yardeni Research, there have been 39 double-digit percentage declines in the benchmark S&P 500 since the start of 1950. All told, we're talking about a double-digit decline, on average, about every 1.88 years. That's more common than most people probably realize -- yet sizable drops tend to surprise or scare the investing community more often than not.

However, datasets also conclusively show that bull markets last considerably longer than bear markets, which is why it pays to be an optimist.

As you can see in the tweet above from wealth management firm Bespoke Investment Group, there have been 27 bear market declines in the S&P 500 since 1929. It should be noted that Bespoke has a very clear definition of what it believes constitutes a bull and bear market. A 20% (or greater) bounce from recent lows that was preceded by a 20% (or greater) decline represents the start of a bull market. Meanwhile, a 20%+ drop from recent highs, which was preceded by a 20%+ rally, signals the beginning of a bear market.

Data from the 27 bear markets the S&P 500 has endured over the past 94 years shows the index has averaged a 35.1% loss. More importantly, bear markets have lasted an average of just 282 calendar days (about 9.5 months).

On the other hand, the 27 bull markets the S&P 500 has enjoyed over the past 94 years have led to an average -- I repeat, average -- gain of 114.4%!

Furthermore, bull markets have gone on for an average of 1,011 calendar days, or close to three months shy of three years. Put another way, the average bull market has lasted slightly more than 3.5 times longer than the typical bear market since 1929.

A smiling person reading a financial newspaper while seated in their home.

Image source: Getty Images.

In spite of worrisome economic indicators, time is an undefeated ally for investors

To be fair, Bespoke's definition of what constitutes a bull or bear market remains up for interpretation. Some investors may not qualify a new bull market until the Dow Jones, S&P 500, and Nasdaq Composite make new highs.

Likewise, some of Bespoke's bull markets are nothing more than sizable bear market rallies. For instance, the nearly 90% decline the benchmark index endured between September 1929 and June 1932 would likely be considered a single bear market event with multiple bear market rallies by most investors. But based on Bespoke's definition of what comprises a bull and bear market, there were four "bull markets" smushed into this nearly 90% drop spanning less than three years.

The point I'm getting at is that the 2022 bear market, which lasted 282 days and saw the S&P 500 tumble 25.4%, may not be over just yet. Even though it's over by Bespoke's measure -- a 20% rally from the 2022 bear market closing low -- numerous economic indicators suggest Wall Street is far from healthy.

In recent weeks, I've examined indicators that show commercial bank lending is tightening, M2 money supply is shrinking for the first time since the Great Depression, and cardboard box usage is declining at its steepest pace since the financial crisis. In other words, there appear to be clear signs of a U.S recession on the horizon. Historically speaking, stock losses have been greatest in the months following the official declaration of a recession by the eight-economist panel of the National Bureau of Economic Research.

But even with these worrisome economic indicators hovering over Wall Street, time remains a foolproof ally for investors.

^SPX Chart

Time heals all wounds for Wall Street's major indexes. ^SPX data by YCharts.

Every year, market analytics company Crestmont Research updates what I believe is the most-powerful dataset on Wall Street. Crestmont analyzed the 20-year rolling total returns of the S&P 500, including dividends paid, all the way back to 1900. Even though the S&P 500 didn't exist until 1923, and wasn't introduced in its current form until 1957, many of the same companies were found in other major indexes prior to 1923, which allowed Crestmont to back-test its dataset to the start of the 20th century.

Starting its analysis in 1900 gave Crestmont 104 rolling 20-year periods of total-return data (1919-2022). The kicker is that all 104 ending years produced positive total returns. It hasn't mattered if an investor bought the S&P 500 at an all-time high or was lucky enough to snag the bear market low -- as long as an investor, hypothetically, held onto an S&P 500 tracking index for 20 years, they've made money, without fail, for more than a century.

While it's never a bad idea to have cash handy in the event of a stock market correction or bear market, history pretty clearly shows that being an optimist pays on Wall Street.