To improve the forecasting accuracy of traffic flow, this paper proposes a traffic flow forecasting algorithm based on Principal Component Analysis (PCA) and Complete Ensemble Empirical Mode Decomposition with Adaptive Noise (CEEMDAN) for data processing. The Grey Wolf Optimizer (GWO) algorithm is used to optimize the weights of a combined model called the GWO-PC-CGLX model, which consists of the Convolutional Neural Network (CNN), Gated Recurrent Unit (GRU), Long Short-Term Memory (LSTM), and Extreme Gradient Boosting (XGBoost). Initially, PCA and CEEMDAN are used to reduce the dimensionality and noise in the air quality index (AQI) data and traffic flow data. The smoothed data are then input into the CNN, GRU, LSTM, and XGboost models for forecasting. To improve the forecasting accuracy, the GWO algorithm is used to find the optimal weight combination of the four single models. Taking the data from Jiayuguan and Lanzhou in Gansu Province as an example, compared with the actual data, the values of the evaluation indicator R2 (Coefficient of Determination) reached 0.9452 and 0.9769, respectively, which are superior to those of the comparison models. The research results not only improve the accuracy of traffic flow forecasting but also provide effective support for the construction of intelligent transportation systems and sustainable traffic management.