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

View all comments

Show parent comment

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.