The trend line for the S&P 500 index this year has been a rocky downhill path. The index, which includes most of the biggest and strongest public companies in the U.S., is down more than 20% year to date. That fact, combined with pundits' and experts' widely reported predictions that a recession is coming, may have you questioning whether now's the right time to invest in the stock market.

Here's a perspective you may not expect. Right now could be the best time to invest in stocks.

The advantage of a long timeline

The most basic profit formula is "buy low and sell high." And the simplest way to execute this strategy in stock investing is to stay invested for years or decades.

Person smiles while sitting on chair with laptop in outdoor patio.

Image source: Getty Images.

Over periods of 10 years or more, the stock market historically has usually had winning records. Stretch that timeline out to look at any period of 20 years, and the stock market has never recorded a loss. Look out even further, to a period that spans the past 50 years or so, and the market's total gains after inflation have averaged out to about 7% annually.

The point is, the longer you stay invested, the easier it will be "sell high." That truth applies whether you buy during a strong market or a weak one.

Your dollar buys more in bear markets

Buying in weaker markets like this one, however, can amplify your gains, as it lets you take better advantage of the "buy low" side of the equation. As previously noted, the S&P 500 is down by a bit more than 20% from where it was in January, and plenty of stocks have fallen by much greater percentages. That means your investing dollar buys a lot more today than it did 11 months ago. But at some point, if history is any guide, we can expect that the market will recover and return to growth.

No one can predict with certainty when that recovery will happen -- or how individual stocks will fare when it does. But when the market turns around, the stocks you buy today should generally deliver bigger long-term returns for your portfolio than the stocks you bought in January.

You can liken a bear market to a sale on stocks. That's the perspective of billionaire investor Warren Buffett, who said, "Whether socks or stocks, I like buying quality merchandise when it's marked down." When he says "quality," take that to mean established companies that have already survived bear markets, inflation, and weaker economies.

Why you wouldn't invest right now

You have better odds of seeing strong returns on the stocks you buy during a bear market like this one -- eventually. But you might have to wait months or years to start seeing those gains. For that reason, you don't want to tie up new money in stocks if you might need that cash within the next five years. Investing today and then finding yourself in a position where you need to liquidate while stock prices are still down would be counterproductive.

This guideline applies to your uninvested cash only. When it comes to the shares that are in your portfolio already, don't sell (unless you have no other option). Liquidating now will generate less cash than you want. You'll do better by hanging on to your stocks until share prices recover. The exception to that advice is if you own lower-quality stocks that you're certain are only headed downhill.

Buy quality now, and be patient

If you forge ahead and buy in this rocky market, keep your expectations in check. Buying stocks when they're down isn't a get-rich-quick strategy. Stocks could certainly drop further before things turn around. If anything, this is a get-rich-slow approach. 

So have patience. Invest in established companies. And don't let the pundits' dramatic predictions cause you to doubt your strategy. If you're in it for the long haul, you will come out on top.