Stock market forecasting is considered the most challenging problem to solve for analysts. In the past 2 years, Covid-19 has severely affected stock markets globally, which, in turn, created a great problem for investors. The prime objective of this study is to use a machine learning model to effectively forecast stock index prices in three time frames: the whole period, the pre-Covid-19 period, and the Covid-19 period. The model accuracy testing results of mean absolute error, root mean square error, mean absolute percentage error, and r2 suggest that the proposed machine learning models autoregressive deep neural network (AR-DNN(1, 3, 10)), autoregressive deep neural network (AR-DNN(3, 3, 10)), and autoregressive random forest (AR-RF(1)) are the best forecasting models for stock index price forecasting for the whole period, for the pre-Covid-19 period, and during the Covid-19 period, respectively, under high stock price fluctuations compared to traditional time-series forecasting models such as autoregressive moving average models. In particular, AR-DNN(1, 3, 10) is suggested when the number of observations is large, whereas AR-RF(1) is suggested for a series with a low number of observations. Our study has a practical implication as they can be used by investors and policy makers in their investment decisions and in formulating financial decisions and policies, respectively.