If the U.S. trend continues and Europe's plan doesn't fall apart, historical data point to stock gains ahead.

October's stock market surge, dubbed Rock-tober by Wall Street analysts, was sparked by a time-honored catalyst dating back to World War II: a "near-miss" bear market.

History shows the stock market shifts into rally mode after it narrowly dodges bear markets, or drops of 20% or more, data from Standard & Poor's show. Stocks also tend to rebound after mild bear markets, or "baby bears," that end with losses limited to, say, 20% to 22%.

That profitable playbook was evident in October. On the first trading day of the month, the S&P 500 index — following a two-month slide caused by political dysfunction in Washington, recession fears and uncertainty over Europe's debt crisis — nearly closed 20% below its April 29 high.

Following the past eight near-bears and baby bears since 1948, the S&P was up an average 31.7% a year later.

•False recession fears. Investors dump stocks when they think recession is imminent. But they buy again when their fears are not realized.

•Attractive stock prices. When the market falls nearly 20%, as it did from late April to early October, stock prices relative to earnings become cheaper. Near the October low, the P-E ratio of the S&P 500 got down to 11, vs. the longer-term average of 15.

•Excessive pessimism. Fear rises when stocks plunge. When the masses are done selling, stocks are primed to rally. "If everyone is bearish, who is left to sell?" Stovall observes.

Also in stocks' favor: Less than a third of stock pickers running mutual funds that invest in large-company stocks are keeping up with their benchmark indexes, Bank of American Merrill Lynch's Savita Subramanian says. Many will buy stocks to try to "catch up" in the performance race. And while she says there are risks, potential for more upside remains.

Another positive driver: Stocks are entering a season that has been a historically bullish time.