Skip to content

Cipher-unhsiV/gap-pattern-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

43 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GAP Pattern Detection in Candlestick Charts, Run Inference πŸš€

Project Banner
Automating the detection of GAP UP and GAP DOWN patterns in candlestick charts using YOLO object detection.


Table of Contents

  1. Project Overview
  2. Key Concepts
  3. Project Details
  4. Getting Started
  5. Try It Online
  6. Dataset
  7. Technologies Involved
  8. Features
  9. Contributing
  10. License
  11. Acknowledgments

Project Overview

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.


Key Concepts

Candlestick Charts

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 and GAP DOWN

  • 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.


Project Details

How It Works

  1. Input: The user inputs a stock symbol through the Gradio interface.
  2. Data Acquisition: Fetches real-time stock data from Alpha Vantage.
  3. Chart Generation: Dynamically creates candlestick charts using Plotly.
  4. Pattern Detection: Applies the YOLOv11l model to identify GAP patterns.
  5. Output: An annotated image with detected patterns highlighted, along with counts of GAP UP and GAP DOWN patterns.

Class Types

The YOLO model is trained to detect two classes:

  • Class 0: GAP DOWN
  • Class 1: GAP UP

Model Training

  • 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.

Getting Started

Prerequisites

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)

Installation

  1. Fork the repository
  2. Clone the repository:
    git clone https://github.com/your-username/gap-pattern-detection.git
    cd gap-pattern-detection
  3. Install the required dependencies:
    pip install -r requirements.txt

Running the Project

  1. Set your Alpha Vantage API key:
    # Edit the API_KEY variable in app.py
    API_KEY = "YOUR_API_KEY_HERE"
  2. Download the trained model weights (best.pt) from the Roboflow dataset page and place it in the models directory.
  3. Launch the application:
    python app.py
  4. Open the Gradio interface in your browser (typically at http://127.0.0.1:7860)
  5. Enter a stock symbol (e.g., AAPL) and click "Detect Patterns"

Try It Online

You can try the project without installing anything locally by using the Hugging Face Spaces deployment: πŸ‘‰ Version 1 πŸ‘‰ Version 2

Dataset

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.

Technologies Involved

  • 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.

Features

  • 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!

Contributing

We welcome contributions to improve the model, dataset, or interface. Here’s how you can contribute:

  1. Fork the repository and clone it:

    git clone https://github.com/your-username/gap-pattern-detection.git```
    
  2. Create a new branch for your feature or bugfix:

    git checkout -b feature/your-feature-name```
    
  3. Make your changes and commit them:

    git commit -m "Add your message here"```
    
  4. Push your changes to your fork:

    git push origin feature/your-feature-name```
    
  5. Open a Pull Request on the main repository.

For more information, head to CONTRIBUTING file

Labeling Guidelines

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.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • 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.

Connect

πŸ’» Live Demo

Happy Trading and Coding! πŸš€