Accurate modeling of stock market information remains a core challenge in financial prediction due to its inherent nonlinearity, noise, and temporal dependencies. Here, we propose a deep learning model based on the Transformer architecture to forecast stock price trends by leveraging its self-attention mechanism for global temporal modeling. Our approach transforms raw stock price data into logarithmic returns and applies a sliding window technique to extract features. We demonstrate that the Transformer model outperforms traditional time series methods and recurrent neural networks, particularly in capturing long-term dependencies and trend inflection points across multiple equity datasets. Our results establish the Transformer as a promising architecture for complex financial time series forecasting, with potential for broader integration into intelligent trading systems.