Chart Library
AIMachine LearningChart PatternsTechnical Analysis

AI Stock Chart Pattern Recognition: How Vector Similarity Finds Historical Analogs

Chart Library Team··7 min read

The Problem with Traditional Pattern Recognition

Most chart pattern tools work the same way: they define rigid rules for patterns like head-and-shoulders, bull flags, or double bottoms, then scan price data for sequences that match those rules. The problem? Real charts are messy. A bull flag on AAPL looks different from a bull flag on a penny stock. A breakout in low volatility looks nothing like one during earnings season.

These rule-based detectors miss patterns that are visually obvious to experienced traders but don't fit neatly into predefined templates. They also can't answer the most important question: when a chart looked like this before, what actually happened next?

A Different Approach: Similarity Search

Chart Library takes a fundamentally different approach. Instead of classifying patterns into categories, it treats every single trading day as a unique pattern and asks: which historical charts look most like this one?

The system has pre-computed embeddings — fixed-dim mathematical fingerprints — for over 25M+ historical chart patterns across 19K+ symbols and 10 years of market data. When you search for a pattern, it finds the 10 nearest neighbors in this embedding space using the similarity metric search, completing in milliseconds.

How the Embeddings Work

Chart Library uses two types of embeddings that live in the same mathematical space.

For text queries (ticker + date), the system computes numerical embeddings directly from minute-bar price data — no neural network involved. It takes the cumulative percentage change throughout the trading day and resamples it to a fixed a fixed target dimension using resampling. This is pure mathematical computation, not machine learning. It captures the shape of the price action — whether it was a steady grind up, a morning spike with afternoon fade, or a choppy range-bound session.

Queries arrive as a (symbol, date, timeframe) anchor — typed in the search bar, called via the REST API, or invoked from any agent through the MCP server. Chart Library resolves the anchor to its pre-computed embedding and runs an L2-distance nearest-neighbor search against the historical index.

Note:the vision model was chosen because its self-supervised training gives it strong understanding of visual structure and spatial relationships — exactly what you need for chart pattern recognition.

Why Vector Search Beats Rule-Based Detection

The core text search is mathematical, not AI — but that's a feature, not a limitation. Computing embeddings directly from price data means the system captures exactly what happened, with no model interpretation or hallucination. Vector similarity search doesn't need to know what a pattern is called. It doesn't care whether something is a "bull flag" or an "ascending wedge." It just finds charts that moved in a similar way.

This has several advantages over traditional detection.

  • No pattern taxonomy needed: The system finds similar charts regardless of whether the pattern has a name. Many real trading setups are unique combinations that don't fit any textbook category.
  • Scale matters: With 25M+ embeddings, the system has seen virtually every type of price action across every market condition. Rule-based systems only find the patterns they were programmed to recognize.
  • Outcome data included: Every match comes with actual forward returns — what happened 1, 3, 5, and 10 days later. You get real outcome distributions, not theoretical expectations.
  • Visual verification: Each match includes an overlay so you can visually confirm the similarity. The system finds candidates; you judge whether the context matches.

From Similarity to Outcomes

Finding similar charts is only half the story. The real value is in the follow-through analysis.

For each set of matches, Chart Library computes forward returns across multiple time horizons. If 8 of 10 similar charts gained over the next 5 days with a median return of +2.3%, that's useful context — not a prediction, but a historical base rate that helps you calibrate your expectations.

The outcome distribution shows how many matches went up vs. down, the median return, and the full range. A pattern where 7 of 10 went up with a tight range is a very different signal than one where 5 went up but the range spans -15% to +20%.

Multi-Timeframe Analysis

Markets look different at different time scales. A pattern on a 5-minute chart carries different information than the same shape on a daily chart.

Chart Library supports multiple timeframes — regular trading hours, premarket sessions, and multi-day windows (3-day, 5-day, and 10-day). Each timeframe has its own set of pre-computed embeddings, so a 5-day search matches against other 5-day windows, not single-day patterns stretched to fit.

Tip:For swing trades, try 3-day or 5-day windows. For day trades, use the regular trading hours (RTH) timeframe. The longer the window, the more context the pattern captures.

What's Next: Calibrated Retrieval

The current system optimizes for shape similarity — charts that moved in a similar way cluster together. But two charts can look identical and have completely different outcomes depending on market regime, volume, or sector rotation.

Rather than collapse that conditionality into a single predicted return, Chart Library ships calibrated quantile bands on every cohort. We measured the raw bands on 400 held-out anchors and found nominal-80% bands were actually covering 68% of outcomes — so we applied split-conformal correction and re-validated at 82.5%. The cohort endpoint now returns both the raw and calibrated bands with coverage evidence in the response.

The harder problem — combining calibrated base rates with regime filters so 'seven of ten went up' actually means a 70% conditional rate — is what ongoing research targets. Progress shows up in the cohort API as better-covered bands, not as a new point-estimate field.

Try It Yourself

Chart Library offers free searches every day — no account required. Type any ticker and date and see what history has to say about the pattern you're watching.

Search your chart now at chartlibrary.io — find the 10 most similar historical patterns and see what happened next.

Ready to try Chart Library?

Anchor any ticker + date — see what history says about your setup, with cohort statistics, feature attribution, and AI narrative.

Try it free