Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tradingview-pine-agent

An agent engine that writes Pine Script v6 which compiles on the first chart push — zero compile errors and zero runtime errors — then proves it works on a live TradingView chart.

LLMs are good at writing plausible Pine Script. Plausible Pine fails two ways: it doesn't compile, or — worse — it compiles clean and then silently throws at runtime (a stray { in str.format, an array read on a live bar, a repainting request.security). This repo is the loop that kills both, plus the accumulated scar tissue (a v6 gotchas KB, a house-style checklist, and 7 compiler-verified templates) that lets an agent get it right the first time instead of the fifth.

It's a prompt-and-knowledge engine, not a library. You drop it into an MCP-capable coding agent (Claude Code, etc.), point it at a live TradingView Desktop chart via the TradingView MCP, and ask for an indicator or strategy. It comes back compiled, attached, and verified.


The zero-error loop

The whole idea in one picture. Steps 1–2 are offline — no chart, fast, free — and catch ~95% of errors before TradingView is ever touched. Steps 3–6 confirm the rest on a real chart.

   OFFLINE  (iterate here, not on the chart)          ON A LIVE CHART
 ┌──────────────┐   ┌────────────────────┐     ┌──────────┐  ┌──────────┐  ┌──────────────┐
 │ pine_analyze │ → │ pine_check         │  →  │ inject + │→ │ runtime  │→ │ visual /data │ → done
 │  (static)    │   │ (real TV compiler, │     │ compile  │  │ console  │  │  verify      │
 │              │   │  line + column)    │     │ on chart │  │  clean?  │  │  renders?    │
 └──────────────┘   └────────────────────┘     └──────────┘  └──────────┘  └──────────────┘
  bad loops,          every compile error        does it       str.format,   lines/labels/
  array OOB,          with exact location        attach?        array OOB     trades look right?
  implicit casts                                                surface HERE

The Golden Rule: never say "done" until pine_check shows error_count: 0, the on-chart compile shows no error markers, the runtime console is clean, and a screenshot or data-read confirms it actually renders/trades.

Compile-clean ≠ runtime-clean. That's the entire reason the loop has two halves.

Full spec: SKILL.md.


What's in here

SKILL.md                      the engine — the loop, the golden rule, the workflows
templates/                    7 compiler-verified Pine v6 starting points (each passes pine_check 0/0)
  indicator-overlay.pine        EMA cross, dynamic color, markers, alerts, dashboard
  indicator-oscillator.pine     separate-pane 0–100 oscillator, bands, gradient, OB/OS alerts
  strategy-clean.pine           % equity sizing, ATR stop/target, date filter, webhook alert_message
  strategy-webhook-alerts.pine  one alert() firing valid broker JSON on confirmed fills
  mtf-nonrepaint.pine           the non-repainting multi-timeframe helper, explained
  dashboard-table.pine          themed table.new analytics dashboard
  session-filter.pine           timezone-aware sessions + date ranges, na-safe
references/
  pine-v6-gotchas.md            the knowledge base: v5→v6 breaks, compile-error → cause → fix
  house-style.md                a battle-tested Pine v6 quality checklist (steal what fits)
  mcp-tool-map.md               how the TradingView MCP works (the 78-tool inventory + internals)
  enhancement-roadmap.md        where this could go next (auto-optimizer, Monte Carlo, ...)

The two files that pay for themselves fastest: references/pine-v6-gotchas.md (so you stop re-hitting the same v6 traps) and references/house-style.md (so generated code is readable and defensive by default — RS-benchmark guards, no-volume pass-through, na gating, floor-to-lot-step epsilon…).


Quickstart

Requirements

  1. TradingView Desktop, launched with CDP enabled so an agent can drive it: --remote-debugging-port=9222 (the same standard debug interface VS Code / Slack / Discord expose — opt-in).
  2. The TradingView MCP by @LewisWJackson — the bridge that turns the CDP endpoint into ~78 callable tools (pine_check, pine_set_source, pine_smart_compile, data_get_*, …).
  3. An MCP-capable agent — e.g. Claude Code.

Use it as a Claude Code skill

git clone https://github.com/jayadevrana/tradingview-pine-agent
mkdir -p ~/.claude/skills/tradingview-pine-agent
cp -r tradingview-pine-agent/{SKILL.md,templates,references} ~/.claude/skills/tradingview-pine-agent/

Then just ask: "build me a VWAP-reversion indicator for SOL 5m" or "port this MQL5 EA to a v6 strategy" or "fix this pine error." The agent picks the closest template, writes the code, runs the loop, and hands you something that already compiles and renders.

Use it with any other agent

SKILL.md is plain Markdown — paste it as a system prompt / project instruction for any agent that can call the TradingView MCP tools. The loop is the product; the skill packaging is just convenience.


Why it works

  • Offline-first. pine_analyze (static) + pine_check (TradingView's real translate_light compiler, returning line + column) catch nearly everything with zero chart round-trips. You iterate in milliseconds, not chart reloads.
  • Two validation layers. Because compiling is not running, the loop also reads the runtime console and the actual drawn objects. "It compiled" is not "it works."
  • Templates that already survived. Every file in templates/ passed pine_check at error_count: 0 and encodes the fixes — so the agent starts from a working thing and adapts, instead of hallucinating from zero.
  • Encoded scar tissue. house-style.md and pine-v6-gotchas.md are the bugs already paid for once: the RS-benchmark-equals-symbol zero-trades trap, no-volume instruments, str.format brace runtime errors, repaint-safe HTF reads, object/security caps. The agent auto-handles them without being told.

Credits & license

  • The live-chart control comes from the TradingView MCP by @LewisWJackson. This repo is the agent-side engine that drives it — it does not vendor or replace the MCP. Go star that project.
  • Everything here is MIT licensed — see LICENSE. Built by Jayadev Rana.

Not financial advice. The strategy templates are engineering scaffolding, not trade recommendations. The alert→broker path is deliberately gated: a human confirms every live order. Trade at your own risk.

About

Agent engine for zero-error Pine Script v6 on TradingView — writes indicators/strategies that compile AND run on the first chart push, via an offline-validate then on-chart-verify loop. Drives the TradingView MCP.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors