Skip to content

Data source: Historical pattern similarity from Chart Library for signal generation #105

@grahammccain

Description

@grahammccain

Summary

OpenAlice is a file-driven AI trading agent — it reads market data and generates trading signals. Historical chart pattern similarity could be a useful input signal: "when the chart looked like this before, what happened next?"

Chart Library provides this via API and MCP server. It has 24M+ pre-computed pattern embeddings across 19K US equities (10 years of minute-bar data).

How it could integrate with OpenAlice

Since OpenAlice is file-driven, the simplest integration would be a data fetcher that writes pattern similarity data to a file:

import requests
import json

def fetch_pattern_data(symbols: list[str], date: str, output_file: str):
    """Fetch pattern similarity data and write to file for OpenAlice."""
    results = {}
    for symbol in symbols:
        resp = requests.get("https://chartlibrary.io/api/v1/search", params={
            "symbol": symbol, "date": date, "timeframe": "RTH"
        }, headers={"X-API-Key": "your-key"})
        
        matches = resp.json()["matches"]
        results[symbol] = {
            "date": date,
            "top_match_distance": matches[0]["distance"],
            "avg_5d_return": sum(m["return_5d"] for m in matches) / len(matches),
            "win_rate_5d": sum(1 for m in matches if m["return_5d"] > 0) / len(matches),
            "avg_10d_return": sum(m["return_10d"] for m in matches) / len(matches),
            "matches": [{
                "symbol": m["symbol"], "date": m["date"],
                "distance": m["distance"], "return_5d": m["return_5d"]
            } for m in matches[:5]]
        }
    
    with open(output_file, "w") as f:
        json.dump(results, f, indent=2)

For AI agent mode (MCP):

pip install chartlibrary-mcp

19 MCP tools including search_pattern, get_risk_adjusted_picks, get_regime_win_rates, and get_exit_signal.

What makes this useful for trading agents

  • Base rate prior: Before making a prediction, see what historically happened after similar patterns
  • Regime awareness: API filters by market regime (VIX level, etc.)
  • Anomaly detection: /api/v1/anomaly/{symbol} flags unusual price action

Details

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions