Skip to main content
Glama
harshil1502

tradingview-mcp

by harshil1502

chart_get_ohlcv

Retrieve the most recent OHLCV bars from the active chart. Specify the number of bars (up to 5000) to obtain the latest price data for analysis.

Instructions

Fetch recent OHLCV bars from the active chart.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of most-recent bars to return. Capped at 5000.

Implementation Reference

  • The main handler function for chart_get_ohlcv. Accepts a count parameter (default 100, max 5000), delegates to page.getOhlcv(), and returns an array of OHLCV bars. Wraps errors in ToolExecutionError.
    export async function chartGetOhlcv(
      input: z.infer<typeof chartGetOhlcvInput>,
      page: TradingViewPage,
    ): Promise<z.infer<typeof chartGetOhlcvOutput>> {
      try {
        const bars = await page.getOhlcv(input.count);
        return { bars };
      } catch (cause) {
        throw new ToolExecutionError(
          'chart_get_ohlcv',
          `Failed to fetch ${input.count} bars`,
          cause,
        );
      }
    }
  • Input schema for chart_get_ohlcv: a single optional integer `count` (1-5000, default 100) describing how many recent bars to return.
    export const chartGetOhlcvInput = z
      .object({
        count: z
          .number()
          .int()
          .min(1)
          .max(5000)
          .default(100)
          .describe('Number of most-recent bars to return. Capped at 5000.'),
      })
      .strict();
  • Output schema for chart_get_ohlcv: returns an object with a `bars` array, each bar having time (ISO string), open, high, low, close, and volume (all numbers).
    export const chartGetOhlcvOutput = z.object({
      bars: z.array(
        z.object({
          time: z.string(),
          open: z.number(),
          high: z.number(),
          low: z.number(),
          close: z.number(),
          volume: z.number(),
        }),
      ),
    });
  • Registration entry in the TOOLS array. Declares the tool with name 'chart_get_ohlcv', description 'Fetch recent OHLCV bars from the active chart.', and links the input/output schemas and handler function.
    {
      name: 'chart_get_ohlcv',
      description: 'Fetch recent OHLCV bars from the active chart.',
      input: chartGetOhlcvInput,
      output: chartGetOhlcvOutput,
      handler: chartGetOhlcv,
    },
  • The TradingViewPage.getOhlcv() helper executed via CDP. Evaluates a JS expression in the page context to slice the last N bars from tvWidget's series data, converting to ISO timestamps.
    async getOhlcv(count = 100): Promise<OhlcvBar[]> {
      const n = Math.max(1, Math.min(count, 5000));
      const expr = `
        (() => {
          const w = window.tvWidget;
          if (!w?.activeChart) return { error: 'tvWidget not available' };
          const series = w.activeChart().getSeries?.();
          if (!series?.data) return { error: 'series data unavailable' };
          const bars = series.data().slice(-${n}).map(b => ({
            time: new Date(b.time).toISOString(),
            open: b.open,
            high: b.high,
            low: b.low,
            close: b.close,
            volume: b.volume ?? 0,
          }));
          return { bars };
        })()
      `;
      const r = await this.cdp.evaluate<{
        error?: string;
        bars?: OhlcvBar[];
      }>(expr);
      if (r.error) throw new ChartStateError(r.error);
      return r.bars ?? [];
    }
Behavior2/5

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

No annotations provided; description lacks details about behavior when no chart is active, what 'recent' means, or that count parameter is capped at 5000.

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?

Single sentence, 8 words, no fluff; but could be longer to include essential details without being verbose.

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

Completeness2/5

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

Tool has one parameter and no output schema; description omits explanation of OHLCV, return format, timeframe context, and count's effect.

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 baseline is 3; description adds no extra meaning beyond the schema's parameter documentation.

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?

Description clearly states the verb 'Fetch', resource 'OHLCV bars', and context 'from the active chart', distinguishing it from sibling tools like chart_get_state or quote_get.

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?

No guidance on when to use this tool versus alternatives (e.g., quote_get for quotes) or prerequisites like having an active chart.

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/harshil1502/tradingview-mcp'

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