In order to make more informed investment decisions, it becomes increasingly critical to forecast stock prices. Given the abnormality of financial markets, predicting the stock market with high accuracy is challenging, necessitating the selection of a reliable method. This paper aims to predict oil and gas stocks in both Islamic and conventional markets before and during COVID-19 using a model based on recurrent long short-term memory (LSTM) networks. The study employs an LSTM network combined with maximum overlap discrete wavelet transformation (MODWT) to predict the Islamic oil and gas stocks (IOG) index as well as the conventional oil and gas stocks (COG) index. Data spanning from 2018.06.27 to 2021.11.23 is divided into two periods: pre-COVID-19 and COVID-19. Prediction accuracy is assessed using root mean square error (RMSE). The study reveals that the network forecasts both indices better during the crisis period than in normal conditions. Additionally, the model generates more accurate forecasts of COG than IOG in both periods across most scales. LSTM predicts COG more accurately at the long-term horizon of the pre-crisis period, whereas it only forecasts IOC at a medium-term horizon in the same market state. In the COVID-19 era, LSTM performs best at predicting both stock markets in the medium-term, but the longest-term forecast is the least accurate. These findings have important implications for investors trading in oil and gas stocks across different market conditions, as well as policymakers regulating oil and gas-related markets.