Utility Scripts¶
The scripts/ directory contains standalone Node.js utilities for common Pine Script development tasks. These scripts connect directly to TradingView Desktop via CDP (port 9222) and do not require the MCP server to be running.
pine_pull.js -- Extract Pine Script Source¶
File: scripts/pine_pull.js
Reads the current Pine Script source from TradingView's Pine Editor and saves it to scripts/current.pine.
How It Works¶
- Fetches the CDP target list from
http://localhost:9222/json/list - Finds the first target with
tradingview.comin its URL - Connects via CDP and enables the Runtime domain
- Locates the Monaco editor instance inside the
.monaco-editor.pine-editor-monacoelement - Traverses React fiber nodes (up to 20 levels up, then 15 levels of
returnpointers) to find themonacoEnvobject - Calls
getEditors()[0].getValue()to extract the source text - Writes the source to
scripts/current.pine
Usage¶
Output:
Prerequisites¶
- TradingView Desktop running with
--remote-debugging-port=9222 - Pine Editor panel must be open with a script loaded
Error Conditions¶
- "No TradingView target" -- TradingView Desktop is not running or CDP port is wrong
- "Could not read Pine editor" -- Pine Editor panel is not open, or the Monaco editor element was not found
pine_push.js -- Inject Pine Script Source¶
File: scripts/pine_push.js
Reads Pine Script source from scripts/current.pine, injects it into TradingView's Pine Editor, clicks the compile button, waits 3 seconds, then checks for compilation errors.
How It Works¶
- Reads source from
scripts/current.pine - Connects to TradingView via CDP (same target discovery as
pine_pull.js) - Locates the Monaco editor via React fiber traversal
- Calls
editors[0].setValue(source)to replace the editor contents - Finds and clicks the compile button by scanning all
<button>elements for text matching:- "Save and add to chart"
- "Add to chart"
- "Update on chart"
- Falls back to the
.saveButtonclass - Final fallback: sends Ctrl+Enter keyboard shortcut
- Waits 3 seconds for compilation to complete
- Reads compilation errors from Monaco's model markers via
editor.getModelMarkers()
Usage¶
Output (success):
Output (errors):
Pushed 142 lines -> Pine editor
Compile: Add to chart
3 errors:
Line 12: Undeclared identifier 'ema_length'
Line 25: Cannot call 'plot' with argument 'color'=series[float]
Line 40: Mismatched input 'if' expecting 'end of line without continuation'
Error Conditions¶
- "No TradingView target" -- TradingView not running
- "Could not inject into Pine editor" -- Pine Editor not open or Monaco not found
Development Workflow¶
These scripts are designed to work together in a rapid development loop, as used by the pine-develop skill:
# 1. Pull current source to edit locally
node scripts/pine_pull.js
# 2. Edit scripts/current.pine in your editor
# 3. Push changes and compile
node scripts/pine_push.js
# 4. Fix any errors, then push again
node scripts/pine_push.js
# 5. Repeat until clean
This workflow keeps the source of truth in a local file (scripts/current.pine), which enables version control, diff review, and AI-assisted editing -- while using TradingView's built-in compiler for validation.
Launch Scripts¶
For TradingView Desktop launch scripts and platform-specific startup configuration, see the ictedge-mcp documentation. Launch scripts handle starting TradingView with the required --remote-debugging-port=9222 flag on macOS, Windows, and Linux.