You work hard to earn your money, and you do your best to invest it well so you can afford a comfortable retirement when you're older. But investing always carries risks. Many fear a recession could hurt the growth of their savings and force them to change their plans.

While I can't predict the future, I know of a strategy that can help you to better weather the ups and downs of the stock market through good times and bad. It sounds deceptively simple, but it can make a significant long-term difference to your portfolio.

Smiling person looking at smartphone.

Image source: Getty Images.

Dollar-cost averaging is your friend

When you're worried about a recession or you see your portfolio dropping in value, it's natural to look for a way to avoid losses. This leads some to try to time the market by selling when they think an investment is at its peak, or buying when they think it's about to rise again. It's a good idea in theory, but it's very difficult to execute.

You run the real risk of selling at the wrong time and locking in your losses. If you'd just waited it out, there's a good chance your portfolio would have eventually recovered.

You're much better off using a method called dollar-cost averaging, where you contribute a regular amount of money on a schedule, like depositing $100 per pay period or $500 per month into your retirement account. This has two advantages.

First, you can automate it. This way, you don't have to worry about forgetting to make your deposits, and you don't have to look at how your portfolio is doing all the time if daily fluctuations give you too much anxiety. You can set it up and then come back to check on it months later without worrying about short-term ups and downs.

Dollar-cost averaging also helps you pay an average amount for your shares over time. Sometimes you'll buy when prices are higher, and you'll get fewer shares. But other times, you'll buy when prices are down, so you'll get a greater number of shares. Eventually, this evens out, and it helps you avoid the guessing game of trying to time the market.

Don't forget to do these things too

Dollar-cost averaging can be a smart strategy whether you're young or older. But there are situations where you might want to make bigger changes to your portfolio, especially if you think there's a recession around the corner.

Make sure you have a diversified portfolio, so no single stock's performance affects you too much. If you don't own at least 25 stocks (or various indexes and ETFs) spread across several industries, then it's probably worth rethinking your investments so you can minimize your risk of loss.

If you're nearing retirement, you may also want to keep a year or two years' worth of expenses in cash. This way, if a recession does hit, you won't have to worry about selling your investments when they're down to cover your living expenses.

It's best to take these steps as soon as possible if you're worried about a recession. Once you've done that, you can fall back on your dollar-cost averaging to carry you through until retirement.