Recession red flags are weighing on the stock market, and if you go back a year, fourth quarter 2018 was a painful one for investors. But there is at least one historical reason to remain positive on stocks as the year’s final quarter starts: It’s been the quarter with the highest average gains over the past decade.The S&P 500 Index has averaged a 4% gain in the final three months of the year over the past decade, according to a CNBC analysis of Kensho, a market data analysis platform. The S&P 500 had traded positively 80% of the time. The Dow Jones Industrial Average had added 5% in fourth quarters over the past 10 years, trading positive 80% of the time.That excludes the fourth quarter 2018, when stocks were battered and made the biggest contribution to a year in which stocks posted their worst performance in a decade. The S&P 500 and Dow plunged 13.97% and 11.8% in Q4 2018, respectively, their worst performances since 2011. The Nasdaq plunged 17.5% in the period, its biggest quarterly fall since 2008. All three indexes posted losses of near-9% in December 2018 alone.Volatility is back, with the third quarter a bumpy three-month stretch for stocks, and October has historically been a high point for the VIX volatility index.But the market has proved to be, in the least, resilient, closing out the third quarter with a slight gain. The S&P 500 and Dow added a little over 1% each. Meanwhile, the Nasdaq slipped a bit lower, falling just short of the break-even level. And that’s in spite of the fact September has historically been a bad one for stocks.For the year, the S&P is up 19%, its best performance through the first three quarters of a calendar year since 1997.Traders work on the floor of the New York Stock Exchange.Spencer Platt | Getty ImagesThe market remains on edge, and the Dow dropped as much as 300 points on Tuesday after a manufacturing contraction. The U.S. manufacturing Purchasing Managers’ Index from the Institute for Supply Management came in at 47.8% in September, the lowest since June 2009, marking the second consecutive month of contraction.”We have now tariffed our way into a manufacturing recession in the U.S. and globally,” Peter Boockvar, chief investment officer at Bleakley Advisory Group, told CNBC on Tuesday.In fact, the Dow loss on Tuesday was just big enough to wipe out the small gain U.S. stocks had posted in the third quarter.”There is no end in sight to this slowdown; the recession risk is real,” said Torsten Slok, chief economist at Deutsche Bank in a note on Tuesday, following the ISM report.As always, past performance cannot guarantee future results, and the markets rarely move up in a straight line. So while the fourth quarter may add to this year’s gains, we will likely see some volatility along the way.The best S&P 500 sectors over the past decade in the fourth quarter have been the S&P financial sector, industrial sector and materials sector, all posting average returns above 6% and trading positive 90% of the time. Consumer discretionary is the other top performer among sectors.Materials, industrials and financial stocks were hit by the negative manufacturing report on Tuesday.The longer-term fourth-quarter track record shows strong average performance. Over the past three decades back to 1989, the Dow (4.3%), S&P (3.6%) and Nasdaq (4.7%) all show gains in the fourth quarter, according to Kensho, and trade positive 75%–80% of the time. Industrials, materials and consumer discretionary were top performers over the past 30-year Q4 periods as well.Keith Lerner, chief market strategist at SunTrust Private Wealth, wrote in a note to clients on Tuesday that while a setback before year-end is possible, he did not expect a pullback “anything in the magnitude of the 2018 sell-off” unless there is a sharp escalation in trade tensions.With the final earnings season of the year about to start, companies within the market’s leading sector of technology have been revising guidance downward. Twenty-nine information technology sector companies have lowered their guidance ahead of October earnings, the biggest number since FactSet starting tracking the data in 2006, and at least partially attributed to the ongoing trade war.But State Street Global Advisors said stocks have remained strong in 2019 because investors are looking past a single-quarter shortfall. “US stocks have rallied sharply this year because investors expect that an eventual U.S.-China trade deal combined with a more dovish Fed will lead to a noticeable bump in future earnings,” wrote Michael Arone, chief investment strategist at State Street Global Advisors, in a recent report.