The use of artificial intelligence-based models have shown that the market is predictable despite its uncertainty and unstable nature. The most important challenge of the proposed models in the stock market is the accuracy of the results and increasing the forecasting efficiency. Another challenge, which is a prerequisite for making decision and using the results of the forecast for profitability of transactions, is to forecast the trend of stock price movements in forecasting price. To overcome the mentioned challenges, this paper employs ensemble learning (EL) model using intelligence-based learners and metaheuristic optimization methods to maximize the improvement of forecasting performance. In addition, in order to consider the direction of price change in stock price forecasting, a two-stage structure is used. In the first stage, the next movement of the stock price (increase or decrease) is forecasted and its outcome is then employed to forecast the price in the second stage. In both stages, genetic algorithm (GA) and particle swarm optimization (PSO) technique are used to optimize the aggregation results of the base learners. The evaluation results of stock market dataset show that the proposed model has higher accuracy compared to other models used in the literature.