This project implements a deep learning model to classify common chart patterns from TradingView candlestick chart images. It's a computer vision application focused on recognizing visual trends in financial charts.
This project is for educational and experimental purposes only and should NOT be used for actual financial trading decisions. Financial markets are complex and highly unpredictable. Any use of this software for real trading is at your own risk.
The goal is to classify images of candlestick charts into predefined patterns such as "Uptrend," "Downtrend," "Sideways/Range," or specific buy/sell signals.
- Image Classification: Utilizes Convolutional Neural Networks (CNNs) for chart pattern recognition.
- Transfer Learning: Employs a pre-trained ResNet backbone for efficient feature extraction.
- PyTorch Framework: Built using the PyTorch deep learning library.
- Custom Dataset Handling: Includes a custom
ChartDatasetfor loading and transforming image data from a structured directory. - MPS Support: Configured to leverage Apple Silicon's Metal Performance Shaders (MPS) for GPU acceleration on compatible Macs.
The dataset consists of 102 manually collected screenshots of TradingView charts, categorized into various chart patterns. The dataset is organized into train, val, and test directories, with subdirectories for each pattern class.
- Clone the repository:
git clone <your-repo-url> cd trading_project
- Create and activate a virtual environment:
python -m venv venv # On Windows: .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Note for Apple Silicon (M1/M2/M3): Ensure your PyTorch installation supports MPS. The
pip install torch torchvision torchaudiocommand (when run on macOS) should typically handle this.
- Note for Apple Silicon (M1/M2/M3): Ensure your PyTorch installation supports MPS. The
-
Prepare your dataset:
- Create a
dataset/trading_chart_dataset/directory in the project root. - Inside it, create
train/,val/, andtest/folders. - Within each of these, create subfolders for your pattern classes (e.g.,
uptrend/,downtrend/,sideways/). - Place your collected chart image screenshots into the respective class folders.
- Create a
-
Run the training and evaluation script:
python main.py
The script will train the model, validate its performance, and evaluate it on the test set, displaying accuracy, F1-score, and a confusion matrix. A trained model will be saved as
trained_model.pth.