With the progress of time series prediction, several recent developments in machine learning have shown that the integration of prediction methods into portfolio selection is a great opportunity to structure investment decisions in the renewable energy industry. In this paper, we propose a novel approach to portfolio formation strategy based on a hybrid machine learning model that combines a convolutional neural network (CNN) and long-term bidirectional memory (BiLSTM) with robust input characteristics obtained from Huber’s location for stock prediction and the mean-variance (MV) Markowitz model for optimal portfolio construction. Specifically, this study first applies a prediction method for stock pre-selection to ensure high-quality stock inflows for portfolio formation. Then, the predicted results are integrated into the MV model. To comprehensively demonstrate the superiority of the proposed model, we used two portfolio models, the MV model and the equal-weighted (1/N) portfolio model, with LSTM, BiLSTM and CNN-BiLSTM, and used them as references. Between January 2016 and December 2021, historical data from the Stock Exchange of Thailand 50 Index (SET50) was collected for the study. Experience shows that integrating stock pre-selection can improve VM performance, and the results of the proposed method show that they outperform comparison models in terms of Sharpe ratio, average return and risk.