Skip to main content
Glama

Candlestick Chart

render_candlestick_chart
Read-onlyIdempotent

Render interactive candlestick or OHLC charts for stock, crypto, or forex data. Customize with themes for styled visuals.

Instructions

Render an interactive candlestick or OHLC financial chart. Provide date/OHLC data for stock prices, crypto, forex, or any time-series financial data. Supports themes for styled visuals.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesChart title
dataYesArray of {date, o, h, l, c} OHLC data points
optionsNo
themeNoTheme preset: boardroom, corporate, sales-floor, golden-treasury, clinical, startup, ops-control, tokyo-midnight, zen-garden, consultant, black-tron, black-elegance, black-matrix, forest-amber, forest-earth, sky-light, sky-ocean, sky-twilight, gray-hf, gray-copilot
paletteNoOverride palette only (mix-and-match)
typographyNoOverride typography: professional, luxury, cyberpunk, editorial, mono, bold, system, techno
effectsNoOverride effects: none, subtle, shimmer, neon, energetic

Implementation Reference

  • Main handler function that renders a candlestick or OHLC chart. Accepts container element and CandlestickData payload (title, data points, options for type/volume). Builds Chart.js financial chart with themed colors, responsive sizing, custom tooltips showing O/H/L/C and change %, click-to-send interaction, export and refresh buttons.
    export function renderCandlestickChart(container: HTMLElement, payload: CandlestickData): void {
      const { title, data, options = {} } = payload;
      const chartType = options.type ?? "candlestick";
      const showVolume = options.showVolume === true && data.some((d) => d.v !== undefined);
    
      // Apply theme if specified
      const theme = resolveTheme(payload.theme, {
        palette: payload.palette,
        typography: payload.typography,
        effects: payload.effects,
      });
      if (theme) applyTheme(container, theme);
    
      const upColor = getCSSVar("--positive") || "#22C55E";
      const downColor = getCSSVar("--negative") || "#EF4444";
    
      container.innerHTML = `
        <div class="chart-view">
          <div class="card chart-card">
            <div class="chart-card__header">
              <div>
                <div class="chart-card__title${theme?.effects.shimmerTitle ? " shimmer-text" : ""}">${escapeHtml(title)}</div>
                <div class="chart-card__subtitle">${data.length} ${chartType === "ohlc" ? "OHLC" : "candlestick"} bars</div>
              </div>
            </div>
            <div class="chart-card__body">
              <canvas id="chart-canvas"></canvas>
            </div>
          </div>
        </div>
      `;
    
      const canvas = container.querySelector<HTMLCanvasElement>("#chart-canvas")!;
    
      const chartData = data.map((d) => ({
        x: new Date(d.date).getTime(),
        o: d.o,
        h: d.h,
        l: d.l,
        c: d.c,
      }));
    
      // Compute Y-axis range from data to avoid the axis starting at 0
      // (which would compress candles into flat lines)
      const allPrices = data.flatMap((d) => [d.o, d.h, d.l, d.c]);
      const yMin = Math.min(...allPrices);
      const yMax = Math.max(...allPrices);
      const yPadding = (yMax - yMin) * 0.15 || 1;
    
      const datasets: any[] = [
        {
          label: title,
          data: chartData,
          color: {
            up: upColor,
            down: downColor,
            unchanged: getCSSVar("--text-muted") || "#94A3B8",
          },
          borderColor: {
            up: upColor,
            down: downColor,
            unchanged: getCSSVar("--text-muted") || "#94A3B8",
          },
        },
      ];
    
      const chartInstance = new Chart(canvas, {
        type: chartType,
        data: { datasets },
        options: {
          responsive: true,
          maintainAspectRatio: false,
          onClick: (_event, elements) => {
            if (elements.length === 0) return;
            const idx = elements[0].index;
            const d = data[idx];
            sendClickMessage(
              `${d.date}: O${d.o} H${d.h} L${d.l} C${d.c}${d.v !== undefined ? ` Vol:${d.v.toLocaleString()}` : ""} in "${title}"`
            );
          },
          scales: {
            x: {
              type: "time",
              border: { display: false },
              grid: { display: false },
              ticks: {
                color: getCSSVar("--text-secondary"),
                font: { size: 11 },
                maxRotation: 0,
              },
              time: {
                displayFormats: {
                  day: "MMM d",
                  week: "MMM d",
                  month: "MMM yyyy",
                },
              },
            },
            y: {
              type: "linear",
              beginAtZero: false,
              min: yMin - yPadding,
              max: yMax + yPadding,
              border: { display: false },
              grid: {
                color: getCSSVar("--border"),
                drawTicks: false,
              },
              ticks: {
                color: getCSSVar("--text-secondary"),
                font: { size: 11 },
                padding: 8,
              },
            },
          },
          plugins: {
            legend: {
              display: false,
            },
            tooltip: {
              ...tooltipStyle(),
              callbacks: {
                title: (items) => {
                  if (items.length === 0) return "";
                  const raw = items[0].raw as any;
                  return new Date(raw.x).toLocaleDateString(undefined, { dateStyle: "medium" });
                },
                label: (ctx) => {
                  const raw = ctx.raw as any;
                  const change = raw.c - raw.o;
                  const pct = ((change / raw.o) * 100).toFixed(2);
                  const dir = change >= 0 ? "+" : "";
                  return [
                    ` O: ${raw.o.toLocaleString()}  H: ${raw.h.toLocaleString()}`,
                    ` L: ${raw.l.toLocaleString()}  C: ${raw.c.toLocaleString()}`,
                    ` Change: ${dir}${change.toLocaleString()} (${dir}${pct}%)`,
                  ];
                },
              },
            },
          },
        },
      } as any);
    
      deferResize(chartInstance);
      addExportButton(container, chartInstance, title);
      addRefreshButton(container, () => (window as any).__mcpRefresh?.());
    }
  • Type definitions (schemas) for CandlestickDataPoint (date, open/high/low/close, optional volume) and CandlestickData (title, data array, options for chart type and volume display, plus theme/palette/typography/effects).
    interface CandlestickDataPoint {
      date: string;
      o: number;
      h: number;
      l: number;
      c: number;
      v?: number;
    }
    
    interface CandlestickData {
      title: string;
      data: CandlestickDataPoint[];
      options: {
        type?: "candlestick" | "ohlc";
        showVolume?: boolean;
      };
      theme?: string;
      palette?: string;
      typography?: string;
      effects?: string;
    }
  • Registration of the tool with key 'candlestick', tool name 'render_candlestick_chart', and the renderCandlestickChart handler function. Called as a side-effect when app.ts imports candlestick.js.
    registerChart("candlestick", "render_candlestick_chart", renderCandlestickChart);
  • Helper function that stores chart renderers in a registry. Couples a chart type key, the MCP tool name string, and the render function together for later dispatch by app.ts.
    export function registerChart(
      type: string,
      toolName: string,
      render: (root: HTMLElement, data: any) => void,
    ): void {
      CHART_REGISTRY[type] = { toolName, render };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, destructiveHint=false, idempotentHint=true, covering safety and idempotency. The description adds interactivity and theme support but does not disclose further behavioral traits like data limits or output format beyond what annotations provide.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences that are efficient and front-loaded, covering purpose and themes. No fluff, but could be slightly more structured (e.g., separate data and options).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (7 params, nested data, no output schema), the description adequately explains the purpose, data format, and theme support. It does not explicitly state the return type (e.g., URL or HTML), but this is typical across sibling tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is high (86%), so baseline is 3. The description mentions date/OHLC data and themes, which aligns with schema, but does not add significant new meaning beyond the schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description specifically states 'Render an interactive candlestick or OHLC financial chart' and lists financial data types (stock prices, crypto, forex). This clearly distinguishes from sibling chart tools like render_line_chart or render_bar_chart.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is implied by naming and description (financial time-series data), but no explicit guidance on when to use this over alternatives or when not to use it. No exclusions or sibling comparisons are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/KyuRish/mcp-dashboards'

If you have feedback or need assistance with the MCP directory API, please join our Discord server