Skip to main content
Glama

generate_candlestick_chart

Generate candlestick charts for financial data like stock or cryptocurrency prices using OHLC (Open-High-Low-Close) data. Customize chart dimensions, themes, and include volume data for detailed analysis.

Instructions

Generate a candlestick chart for financial data visualization, such as, stock prices, cryptocurrency prices, or other OHLC (Open-High-Low-Close) data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesData for candlestick chart, such as, [{ date: '2023-01-01', open: 100, high: 110, low: 95, close: 105, volume: 10000 }].
heightNoSet the height of the chart, default is 600px.
outputTypeNoThe output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option.png
showVolumeNoWhether to show volume chart below candlestick. Default is false.
themeNoSet the theme for the chart, optional, default is 'default'.default
titleNoSet the title of the chart.
widthNoSet the width of the chart, default is 800px.

Implementation Reference

  • The core handler function that processes OHLC(V) data, constructs the ECharts candlestick chart option (with optional volume bars), configures layout and styling, and generates the output image.
    run: async (params: {
      data: Array<{
        date: string;
        open: number;
        high: number;
        low: number;
        close: number;
        volume?: number;
      }>;
      height: number;
      showVolume?: boolean;
      theme?: "default" | "dark";
      title?: string;
      width: number;
      outputType?: "png" | "svg" | "option";
    }) => {
      const {
        data,
        height,
        showVolume = false,
        theme,
        title,
        width,
        outputType,
      } = params;
    
      // Sort data by date
      const sortedData = [...data].sort(
        (a, b) => new Date(a.date).getTime() - new Date(b.date).getTime(),
      );
    
      // Extract dates and OHLC data
      const dates = sortedData.map((item) => item.date);
      const ohlcData = sortedData.map((item) => [
        item.open,
        item.close,
        item.low,
        item.high,
      ]);
      const volumeData = sortedData.map((item) => item.volume || 0);
    
      const series: Array<SeriesOption> = [
        {
          name: "Candlestick",
          type: "candlestick",
          data: ohlcData,
          itemStyle: {
            color: "#ef232a",
            color0: "#14b143",
            borderColor: "#ef232a",
            borderColor0: "#14b143",
          },
          emphasis: {
            itemStyle: {
              color: "#ef232a",
              color0: "#14b143",
              borderColor: "#ef232a",
              borderColor0: "#14b143",
            },
          },
        },
      ];
    
      // Add volume series if requested
      if (showVolume && volumeData.some((v) => v > 0)) {
        series.push({
          name: "Volume",
          type: "bar",
          xAxisIndex: 1,
          yAxisIndex: 1,
          data: volumeData,
          barWidth: "60%",
          itemStyle: {
            color: (params: { dataIndex: number }) => {
              const dataIndex = params.dataIndex;
              return sortedData[dataIndex].close >= sortedData[dataIndex].open
                ? "#ef232a"
                : "#14b143";
            },
          },
        });
      }
    
      const echartsOption: EChartsOption = {
        animation: false,
        legend: {
          bottom: 10,
          left: "center",
          data: showVolume ? ["Candlestick", "Volume"] : ["Candlestick"],
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
          },
          borderWidth: 1,
          borderColor: "#ccc",
          padding: 10,
          textStyle: {
            color: "#000",
          },
        },
        xAxis: [
          {
            type: "category",
            data: dates,
            boundaryGap: true,
            axisLine: { onZero: false },
            splitLine: { show: false },
            min: -0.2,
            max: dates.length - 0.8,
          },
          ...(showVolume
            ? [
                {
                  type: "category" as const,
                  gridIndex: 1,
                  data: dates,
                  boundaryGap: true,
                  axisLine: { onZero: false },
                  axisTick: { show: false },
                  splitLine: { show: false },
                  axisLabel: { show: false },
                  min: -0.2,
                  max: dates.length - 0.8,
                },
              ]
            : []),
        ],
        yAxis: [
          {
            scale: true,
            splitArea: {
              show: true,
            },
          },
          ...(showVolume
            ? [
                {
                  scale: true,
                  gridIndex: 1,
                  splitNumber: 2,
                  axisLabel: { show: false },
                  axisLine: { show: false },
                  axisTick: { show: false },
                  splitLine: { show: false },
                  min: 0,
                },
              ]
            : []),
        ],
        grid: showVolume
          ? [
              {
                left: "12%",
                right: "10%",
                top: "15%",
                height: "50%",
              },
              {
                left: "12%",
                right: "10%",
                top: "75%",
                height: "15%",
              },
            ]
          : [
              {
                left: "12%",
                right: "10%",
                top: "15%",
                bottom: "15%",
              },
            ],
        series,
        title: {
          left: "center",
          text: title,
        },
      };
    
      return await generateChartImage(
        echartsOption,
        width,
        height,
        theme,
        outputType,
        "generate_candlestick_chart",
      );
    },
  • Zod schemas defining the structure of individual candlestick data points and the overall input parameters for the tool, including data array, dimensions, volume toggle, theme, title, and output type.
    const data = z.object({
      date: z.string().describe("Date string, such as '2023-01-01'."),
      open: z.number().describe("Opening price."),
      high: z.number().describe("Highest price."),
      low: z.number().describe("Lowest price."),
      close: z.number().describe("Closing price."),
      volume: z.number().optional().describe("Trading volume (optional)."),
    });
    
    export const generateCandlestickChartTool = {
      name: "generate_candlestick_chart",
      description:
        "Generate a candlestick chart for financial data visualization, such as, stock prices, cryptocurrency prices, or other OHLC (Open-High-Low-Close) data.",
      inputSchema: z.object({
        data: z
          .array(data)
          .describe(
            "Data for candlestick chart, such as, [{ date: '2023-01-01', open: 100, high: 110, low: 95, close: 105, volume: 10000 }].",
          )
          .nonempty({ message: "Candlestick chart data cannot be empty." }),
        height: HeightSchema,
        showVolume: z
          .boolean()
          .optional()
          .default(false)
          .describe(
            "Whether to show volume chart below candlestick. Default is false.",
          ),
        theme: ThemeSchema,
        title: TitleSchema,
        width: WidthSchema,
        outputType: OutputTypeSchema,
      }),
  • Imports the tool definition and registers it by including 'generateCandlestickChartTool' in the exported 'tools' array (at line 32), which is used to expose all MCP tools.
    import { generateCandlestickChartTool } from "./candlestick";
    import { generateEChartsTool } from "./echarts";
    import { generateFunnelChartTool } from "./funnel";
    import { generateGaugeChartTool } from "./gauge";
    import { generateGraphChartTool } from "./graph";
    import { generateHeatmapChartTool } from "./heatmap";
    import { generateLineChartTool } from "./line";
    import { generateParallelChartTool } from "./parallel";
    import { generatePieChartTool } from "./pie";
    import { generateRadarChartTool } from "./radar";
    import { generateSankeyChartTool } from "./sankey";
    import { generateScatterChartTool } from "./scatter";
    import { generateSunburstChartTool } from "./sunburst";
    import { generateTreeChartTool } from "./tree";
    import { generateTreemapChartTool } from "./treemap";
    
    export const tools = [
      generateEChartsTool,
      generateLineChartTool,
      generateBarChartTool,
      generatePieChartTool,
      generateRadarChartTool,
      generateScatterChartTool,
      generateSankeyChartTool,
      generateFunnelChartTool,
      generateGaugeChartTool,
      generateTreemapChartTool,
      generateSunburstChartTool,
      generateHeatmapChartTool,
      generateCandlestickChartTool,
      generateBoxplotChartTool,
      generateGraphChartTool,
      generateParallelChartTool,
      generateTreeChartTool,
    ];
  • Re-exports the individual tool for direct import and use.
    // Re-export individual tools for convenient use in tests and other places
    export {
      generateEChartsTool,
      generateLineChartTool,
      generateBarChartTool,
      generatePieChartTool,
      generateRadarChartTool,
      generateScatterChartTool,
      generateSankeyChartTool,
      generateFunnelChartTool,
      generateGaugeChartTool,
      generateTreemapChartTool,
      generateSunburstChartTool,
      generateHeatmapChartTool,
      generateCandlestickChartTool,
      generateBoxplotChartTool,
      generateGraphChartTool,
      generateParallelChartTool,
      generateTreeChartTool,
    };
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks behavioral details. It doesn't disclose whether this is a read-only or mutating operation, any authentication needs, rate limits, or what the output looks like (e.g., returns an image, string, or object). The mention of 'generate' implies creation but without further context.

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?

The description is a single, efficient sentence that front-loads the core purpose. It could be slightly more structured by separating usage context, but it avoids redundancy and wastes no words.

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

Completeness3/5

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

For a tool with 7 parameters, 100% schema coverage, and no output schema, the description is minimally adequate. It clarifies the tool's purpose but lacks behavioral context (e.g., output format, side effects) and usage guidelines relative to siblings, leaving gaps for an AI agent to infer correct invocation.

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 100%, so the schema fully documents all 7 parameters. The description adds no parameter-specific information beyond implying the 'data' parameter should contain OHLC data, which is already covered in the schema. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Generate a candlestick chart for financial data visualization' with specific examples like stock prices and OHLC data. It distinguishes from siblings by specifying the chart type (candlestick), though it doesn't explicitly contrast with alternatives like 'generate_line_chart' or 'generate_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 Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It mentions 'financial data visualization' and OHLC data, which implies usage for time-series financial data, but offers no explicit when/when-not instructions or references to sibling tools for different chart types.

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

Related 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/hustcc/mcp-echarts'

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