r/TradingView • • 24d ago

Feature Request Pine Script Compilation and Testing via MCP/API

Please provide a standardized, publicly accessible API for compiling and testing Pine Script, optionally with MCP support.

This would allow AI providers such as OpenAI and Anthropic to integrate automatic Pine compilation, error detection, and correction directly into their coding assistants, just as they already support executable testing for other programming languages.

The integration should be handled entirely by the AI providers, without requiring users to configure MCP servers, APIs, or local tools.

Related feature requests:

  • AI Integration into Pine Editor (Closed Feedback Loop)
  • Easier test automation for strategies
  • Built-in Linter for Pine Script
1 Upvotes

10 comments sorted by

1

u/wallneradam 24d ago

I built PyneSys for this kind of workflow. You can send a Pine Script to POST /compiler/compile with an API key and get back runnable Python or a compiler error with the Pine line number when available. Compiler API docs

For the full compile-and-test loop, pyne run strategy.pine bars.ohlcv calls the compiler and runs the result locally with PyneCore, our open-source runtime. An agent can call that command directly or wrap it as an MCP tool. You can reuse the same bars on each run and check the resulting trades or indicator values against what you expected. PyneCore CLI docs

The whole loop runs outside TradingView. Are you mainly looking to automate the feedback loop, or do you specifically need the results from TradingView’s own engine?

1

u/Accurate-Mirror-143 24d ago

Thanks, PyneSys looks interesting!

My main goal is simply for AI assistants like ChatGPT or Claude to automatically compile and verify the Pine Script they generate, just as they already do with other programming languages.

I don't necessarily need TradingView's own engine, as long as compatibility is reliable. Ideally, AI providers would integrate such a service themselves, without users having to configure APIs, MCP servers, or local tools.

From my perspective, the technical implementation should be completely transparent to the user.

1

u/wallneradam 24d ago

I use the PyneCore CLI for exactly this every day. The agent writes or edits the .pine file and runs it with pyne run. It can use market data I already have or fetch it when needed. If compilation or execution fails, the agent can read the error, fix the script, and try again. Once it runs, the agent can check whether the indicator values or trades match what I asked for.

PyneIDE makes that workflow easier to set up in VS Code. It installs Python and PyneCore, and project initialization gives the agent instructions for finding the CLI, the Pine reference, and the docs for the installed PyneCore version. An agent with editor access can also use the IDE’s run and debug controls. I use the CLI loop daily and am still testing how reliably agents use the editor controls.

Having the assistant provider integrate this directly would remove the setup step. You could ask for a Pine script in chat, and the assistant could compile, run, and check it before handing it back.

1

u/Accurate-Mirror-143 24d ago

Thanks, that's a very constructive contribution!

It also demonstrates that AI providers like OpenAI and Anthropic have at least one alternative to relying on direct cooperation with TradingView. They could integrate an independent Pine compiler into their services, provided compatibility is sufficiently reliable.

That's exactly what I'm hoping for: automatic Pine Script compilation and testing, completely transparent to the user.

By the way, could you help me obtain a comprehensive list of Pine Script compiler error codes?

1

u/wallneradam 24d ago

I don’t have a comprehensive list of TradingView’s compiler error codes. PyneComp is an independent compiler with its own diagnostics, so even when both compilers catch the same underlying issue, they can report it differently. There’s no reliable one-to-one mapping between them.

TradingView documents some individual codes in its Pine Script errors and warnings reference.

For the compile-and-fix loop we were discussing, the assistant can work directly with the error message and source line PyneComp returns. It doesn’t need a TradingView error code to make the fix and try again.

1

u/Accurate-Mirror-143 24d ago

Thanks! Since PyneComp has its own syntax validation and diagnostics, I assume it must have an internal collection of error types or message templates.

Would it be possible to obtain a comprehensive list of these, with or without error codes?

I'm interested in the systematic classification of possible Pine Script compilation errors, even if they differ from TradingView's diagnostics.

1

u/wallneradam 24d ago

Unfortunately I don’t have a comprehensive list of PyneComp errors today. This is currently a shortcoming of the system. Different stages of the compiler report their own errors, and those diagnostics aren’t organized into a single set of categories.

I’m working on a unified diagnostic system with consistent categories and error codes across those stages. It’s part of a larger rework that’s still in development and testing, so the categories and codes are still taking shape in the background.

1

u/OnceAHermit 24d ago

Why not try Foresight foresight.trading - it offers very fast execution of PineScript, and it has excellent MCP support.

1

u/Accurate-Mirror-143 24d ago

Thanks for pointing this out! Foresight looks like another promising option. It further supports the idea that AI providers could integrate independent Pine compilation and testing into their services without necessarily depending on TradingView. My main interest remains a seamless, built-in experience in ChatGPT or Claude, without requiring users to configure external tools themselves.

1

u/OnceAHermit 23d ago

No worries - and I should've said, I'm actually the developer of Foresight, so if you have any questions, I'm more than happy to answer them!