TradingView MCP Bridge

repository·main·Indexed 26 days ago

https://github.com/tradesdontlie/tradingview-mcp

An MCP bridge for TradingView Desktop (v1.0.0) that connects LLM agents to the application via the Chrome DevTools Protocol. It provides a comprehensive toolset for AI-assisted chart analysis, Pine Script development, and workflow automation, including a `tv` CLI for data streaming, layout management, and replay mode automation.

Tokens
13.4K
Snippets
13
Records
140
Agent score
88%

What's inside tradingview-mcp

  1. Understand the TradingView MCP Tool Design Philosophy

    main

    The TradingView MCP Bridge is designed for agent-forward trading, where LLM agents assist human traders. The toolset follows several key design principles to optimize for LLM performance:

    • Granular Tooling: Instead of a single coarse tool, the project provides ~84 granular tools (e.g., separate tools for quote, OHLCV, indicator values, pine lines, pine labels, etc.). This allows agents to request precise, small payloads to save context.
    • Compact-by-Default Output: To manage context window constraints, tools return compact data by default (e.g., using summary: true and study_filter). Verbose mode is opt-in.
    • Failure Transparency: The tools surface raw data rather than pre-interpreting it, allowing the agent's reasoning trace to reveal when it has misread a chart or encountered stale data.
    • Pine Script Iteration Loop: The toolset supports a specific development loop for Pine Script: pine_set_source $\rightarrow$ pine_smart_compile $\rightarrow$ pine_get_errors to enable agents to debug and iterate on scripts.
  2. Generate a Strategy Performance Report

    main

    To generate a comprehensive performance report for a Pine Script strategy on TradingView, follow this multi-step workflow using the available MCP tools:

    1. Data Gathering

    Collect the following data points using these tools:

    • data_get_strategy_results: For overall metrics (net profit, win rate, profit factor, etc.).
    • data_get_trades: For the individual trade list (up to 20 trades).
    • data_get_equity: For equity curve data points.
    • chart_get_state: To identify the current symbol, timeframe, and active studies.
    • symbol_info: To obtain symbol metadata for context.

    2. Visual Capture

    Capture visual evidence of the strategy performance:

    • Use capture_screenshot with the region "chart" to capture the chart with the strategy overlay.
    • Use capture_screenshot with the region "strategy_tester" to capture the Strategy Tester panel.

    3. Analysis Framework

    Analyze the gathered data based on these criteria:

    • Key Metrics: Evaluate Net Profit, % return, Total Trades, Win Rate, Profit Factor (target > 1.5), Max Drawdown ($ and %), Average Trade, Sharpe Ratio, and Max Consecutive Losses.
    • Trade Analysis: Identify the largest winner/loser, reward:risk ratio (average winner vs average loser), long vs short performance, and time in market.
    • Equity Curve: Assess smoothness, upward slope, drawdown periods, and profit distribution (consistency vs front/back-loaded).

    4. Report Generation

    Format the final output into a structured report including a Summary, Key Metrics table, Strengths, Weaknesses, and actionable Recommendations.

  3. Execute the Pine Script development loop

    main

    When building or modifying a Pine Script indicator or strategy in TradingView, follow this iterative development cycle:

    1. Understand the Goal: Define the script type (indicator, strategy, or library), logic (entry/exit, oscillator, etc.), and visual requirements (overlay vs. separate pane).
    2. Pull Current Source: If modifying an existing script, use the pull command to sync the current code to your local environment.
    3. Write the Script: Save the complete code to scripts/current.pine. Ensure it includes the //@version=6 header and proper declarations.
    4. Push and Compile: Inject the code into the TradingView Pine Editor and trigger a compilation.
    5. Fix Errors: If compilation fails, edit scripts/current.pine based on the reported line numbers and descriptions, then push again.
    6. Verify: Use screenshot and data retrieval tools to confirm visual and performance accuracy.
    7. Iterate: Repeat the process for any requested changes.
  4. Integrate scans with TradingView watchlists

    main

    You can automate scanning based on your existing watchlists by following this workflow:

    1. Use watchlist_get to retrieve all symbols currently in your watchlist.
    2. Use the retrieved symbol list as the input for your scan (via batch_run or manual loops).
    3. Use watchlist_add to automatically add symbols that meet your scan criteria to your watchlist.
  5. Capture chart data and screenshots

    main

    To gather data for technical analysis, use the following tools:

    • capture_screenshot: Take a screenshot of the current annotated chart.
    • data_get_ohlcv: Pull recent price data (Open, High, Low, Close, Volume) for quantitative analysis.
    • quote_get: Retrieve the current real-time price.
    • symbol_info: Retrieve symbol metadata such as exchange, type, and session.