GAP Pattern Detection in Candlestick Charts, Run Inference π
Automating the detection of GAP UP and GAP DOWN patterns in candlestick charts using YOLO object detection.
- Project Overview
- Key Concepts
- Project Details
- Getting Started
- Try It Online
- Dataset
- Technologies Involved
- Features
- Contributing
- License
- Acknowledgments
This project focuses on detecting GAP UP and GAP DOWN patterns in candlestick charts, which are widely used in technical analysis for stock market trading. Using a YOLOv11l (You Only Look Once) object detection model, the project identifies these patterns in candlestick chart images. The model is trained on a custom dataset and can be used to analyze charts for potential market movements.
It is designed to help traders and analysts quickly identify GAP patterns, saving time and improving accuracy in technical analysis. It includes a Gradio-based web interface for easy interaction and real-time detection.
Candlestick charts are a type of financial chart used to represent the price movement of an asset (e.g., stocks, cryptocurrencies) over time. Each "candlestick" consists of:
- Body: Represents the opening and closing prices.
- Wicks (or Shadows): Represent the highest and lowest prices during the time period.
Candlestick charts are widely used in technical analysis to identify trends, reversals, and patterns.
- GAP UP: Occurs when the lowest price of the current candlestick is higher than the highest price of the previous candlestick. This indicates a strong upward momentum and is often considered a bullish signal.
- GAP DOWN: Occurs when the highest price of the current candlestick is lower than the lowest price of the previous candlestick. This indicates a strong downward momentum and is often considered a bearish signal.
These patterns are significant because they can signal potential breakouts or reversals in the market.
- Input: The user inputs a stock symbol through the Gradio interface.
- Data Acquisition: Fetches real-time stock data from Alpha Vantage.
- Chart Generation: Dynamically creates candlestick charts using Plotly.
- Pattern Detection: Applies the YOLOv11l model to identify GAP patterns.
- Output: An annotated image with detected patterns highlighted, along with counts of GAP UP and GAP DOWN patterns.
The YOLO model is trained to detect two classes:
- Class 0: GAP DOWN
- Class 1: GAP UP
- The model is trained on a custom dataset of annotated candlestick charts.
- The dataset includes images with labeled GAP UP and GAP DOWN patterns.
- The model is saved as
best.pt
and loaded for inference.
To run this project locally, you need:
- Python 3.8 or higher
- Pip (Python package manager)
- Alpha Vantage API key
- A GPU (recommended for faster inference)
- Fork the repository
- Clone the repository:
git clone https://github.com/your-username/gap-pattern-detection.git cd gap-pattern-detection
- Install the required dependencies:
pip install -r requirements.txt
- Set your Alpha Vantage API key:
# Edit the API_KEY variable in app.py API_KEY = "YOUR_API_KEY_HERE"
- Download the trained model weights (
best.pt
) from the Roboflow dataset page and place it in themodels
directory. - Launch the application:
python app.py
- Open the Gradio interface in your browser (typically at http://127.0.0.1:7860)
- Enter a stock symbol (e.g., AAPL) and click "Detect Patterns"
You can try the project without installing anything locally by using the Hugging Face Spaces deployment: π Version 1 π Version 2
The dataset used for training the model is publicly available on Roboflow. You can access it here: π Roboflow Dataset: GAP Pattern Detection
The dataset includes:
- Annotated images of candlestick charts.
- Labels for GAP UP and GAP DOWN patterns.
- YOLOv11l: For object detection.
- Gradio: For creating a user-friendly web interface.
- OpenCV (cv2): For image processing and annotation.
- Roboflow: For dataset management and annotation.
- Pandas: For data processing.
- Plotly: For data visualization.
- AlphaVantage: For real-time data source.
- Static image upload and analysis
- GAP UP and GAP DOWN pattern detection
- Annotation of detected patterns
- Pattern count statistics
v2 (Current)
- Real-time market data integration via Alpha Vantage
- Dynamic candlestick chart generation
- High-resolution 1-minute candle analysis
- Streamlined user interface
- Comprehensive error handling
- Improved processing pipeline
Stay tuned for updates as we work on bringing these exciting new features to life. The future of GAP pattern detection is just around the corner!
We welcome contributions to improve the model, dataset, or interface. Hereβs how you can contribute:
-
Fork the repository and clone it:
git clone https://github.com/your-username/gap-pattern-detection.git```
-
Create a new branch for your feature or bugfix:
git checkout -b feature/your-feature-name```
-
Make your changes and commit them:
git commit -m "Add your message here"```
-
Push your changes to your fork:
git push origin feature/your-feature-name```
-
Open a Pull Request on the main repository.
For more information, head to CONTRIBUTING file
If youβre labeling new data for the dataset, follow these guidelines:
- Use a labeling tool like LabelImg or CVAT.
- For each GAP UP or GAP DOWN pattern:
- Draw a bounding box around the two candlesticks involved in the pattern.
- Assign the correct class label (0 for GAP DOWN, 1 for GAP UP).
- Ensure the bounding boxes are tight and accurate.
This project is licensed under the MIT License. See the LICENSE file for details.
- Roboflow for providing the dataset and annotation tools.
- Ultralytics for the YOLO object detection framework.
- Gradio for the web interface framework.
- HF Spaces for the deployment platform.
- GitHub: Cipher-unhsiV
- Email: [email protected]
- LinkedIn: Vishnuvasan T S
Happy Trading and Coding! π