Many investors think about getting out of the stock market when it gets bumpy. But history shows that staying invested over the long term has resulted in positive gains.