CLI Interface¶
The tv binary is a standalone command-line interface that exposes all 70+ tradingview-mcp tools as shell commands. It connects to TradingView Desktop via Chrome DevTools Protocol (CDP) on port 9222 and outputs JSON to stdout.
Running the CLI¶
# Via npx (if installed as a package)
npx tv <command> [subcommand] [args]
# Direct execution
node src/cli/index.js <command> [subcommand] [args]
Global help:
Output Conventions¶
| Stream | Content |
|---|---|
| stdout | JSON result data (pipe-friendly, use with jq) |
| stderr | Error messages, stream status logs |
Exit Codes¶
| Code | Meaning |
|---|---|
0 |
Success |
1 |
General error (bad arguments, tool failure) |
2 |
Connection failure (CDP unreachable, TradingView not running) |
Connection errors are detected by matching the error message against /CDP\|connection\|ECONNREFUSED\|not running/i.
Command Structure¶
Commands are registered via register(name, config) in the router. The router uses Node.js built-in parseArgs with zero external dependencies. Commands can be top-level (no subcommands) or grouped under a parent command with a subcommands Map.
Command Reference¶
Health and Connection¶
| Command | Description |
|---|---|
tv status |
Check CDP connection to TradingView |
tv launch |
Launch TradingView with CDP enabled |
tv discover |
Report available TradingView API paths |
tv ui-state |
Get current UI state (panels, buttons, dialogs) |
Options for tv launch:
-p, --port-- CDP port (default 9222)--no-kill-- Do not kill existing TradingView instances
Examples:
Chart Control¶
| Command | Description |
|---|---|
tv state |
Get full chart state (symbol, timeframe, indicators) |
tv symbol [SYM] |
Get current symbol, or set it if SYM is provided |
tv timeframe [TF] |
Get current timeframe, or set it if TF is provided |
tv type [TYPE] |
Get or set chart type (Candles, Line, Area, Renko, HeikinAshi, etc.) |
tv info |
Get detailed symbol metadata |
tv search <query> |
Search for symbols by name or keyword |
tv range |
Get or set the visible chart range |
tv scroll <date> |
Scroll chart to a specific date (ISO format) |
Options for tv range:
--from-- Start timestamp (unix seconds)--to-- End timestamp (unix seconds)
Examples:
tv symbol ES1!
tv timeframe 15
tv type HeikinAshi
tv search "crude oil"
tv scroll 2025-01-15
tv range --from 1704067200 --to 1704153600
Data Access¶
| Command | Description |
|---|---|
tv quote |
Get real-time price quote |
tv ohlcv |
Get OHLCV bar data |
tv values |
Get current indicator values from the data window |
Options for tv ohlcv:
-n, --count-- Number of bars (default 100, max 500)-s, --summary-- Return summary stats instead of all bars
tv data subcommands (advanced data access):
| Subcommand | Description |
|---|---|
tv data lines |
Get Pine Script line.new() price levels |
tv data labels |
Get Pine Script label.new() annotations |
tv data tables |
Get Pine Script table.new() data |
tv data boxes |
Get Pine Script box.new() price zones |
tv data strategy |
Get strategy performance metrics |
tv data trades |
Get strategy trade list |
tv data equity |
Get strategy equity curve |
tv data depth |
Get order book / DOM data |
tv data indicator <entity_id> |
Get indicator info and inputs by entity ID |
Common options for Pine data subcommands:
-f, --filter-- Filter by study name substring-v, --verbose-- Include raw drawing data-n, --max-- Max labels per study (forlabels)
Examples:
tv quote
tv ohlcv --summary
tv ohlcv -n 50
tv data lines -f "Session Hunt"
tv data labels -f "Bias AI" --max 20
tv data strategy
tv data indicator eFu1Ot
Pine Script¶
| Subcommand | Description |
|---|---|
tv pine get |
Get current Pine Script source from editor |
tv pine set |
Set Pine Script source (reads stdin or --file) |
tv pine compile |
Smart compile: detect button, compile, check errors |
tv pine raw-compile |
Click compile/add button without smart detection |
tv pine analyze |
Offline static analysis (no TradingView needed) |
tv pine check |
Server-side compile check (no chart needed) |
tv pine save |
Save the current Pine Script (Ctrl+S equivalent) |
tv pine new [type] |
Create a new blank script (indicator, strategy, library) |
tv pine open <name> |
Open a saved Pine Script by name |
tv pine list |
List saved Pine Scripts |
tv pine errors |
Get Pine Script compilation errors |
tv pine console |
Get Pine Script console/log output |
Source input: tv pine set and tv pine analyze and tv pine check accept source via stdin pipe or --file:
cat my_script.pine | tv pine set
tv pine set --file scripts/current.pine
cat my_script.pine | tv pine check
Examples:
tv pine get > backup.pine
tv pine set -f scripts/current.pine
tv pine compile
tv pine errors
tv pine console
tv pine new strategy
tv pine open "My Custom RSI"
tv pine list
Screenshots¶
| Command | Description |
|---|---|
tv screenshot |
Take a screenshot of the chart |
Options:
-r, --region-- Region:full,chart,strategy_tester-o, --output-- Custom filename (without.png)
Replay Mode¶
| Subcommand | Description |
|---|---|
tv replay start |
Start replay mode |
tv replay step |
Advance one bar |
tv replay stop |
Stop replay, return to realtime |
tv replay status |
Get current replay state (position, P&L, date) |
tv replay autoplay |
Toggle autoplay |
tv replay trade <action> |
Execute a trade: buy, sell, or close |
Options:
tv replay start -d, --date-- Start date (YYYY-MM-DD)tv replay autoplay -s, --speed-- Autoplay delay in ms (lower = faster)
tv replay start --date 2025-03-01
tv replay step
tv replay trade buy
tv replay status
tv replay trade close
tv replay stop
Drawings¶
| Subcommand | Description |
|---|---|
tv draw shape |
Draw a shape on the chart |
tv draw list |
List all drawings |
tv draw get <id> |
Get properties of a drawing |
tv draw remove <id> |
Remove a drawing by entity ID |
tv draw clear |
Remove all drawings |
Options for tv draw shape:
-t, --type-- Shape type:horizontal_line,trend_line,rectangle,text-p, --price-- Price level--time-- Unix timestamp--price2-- Second point price (for trend_line, rectangle)--time2-- Second point time (for trend_line, rectangle)--text-- Text content (for text shapes)--overrides-- JSON style overrides
Alerts¶
| Subcommand | Description |
|---|---|
tv alert list |
List active alerts |
tv alert create |
Create a price alert |
tv alert delete |
Delete alerts |
Options for tv alert create:
-p, --price-- Price level-c, --condition-- Condition:crossing,greater_than,less_than-m, --message-- Alert message
Watchlist¶
| Subcommand | Description |
|---|---|
tv watchlist get |
Get watchlist symbols (with last price and change) |
tv watchlist add <symbol> |
Add a symbol to the watchlist |
Indicators¶
| Subcommand | Description |
|---|---|
tv indicator add <name> |
Add an indicator (use full name, e.g., "Volume") |
tv indicator remove <entity_id> |
Remove an indicator by entity ID |
tv indicator toggle <entity_id> |
Show or hide an indicator |
tv indicator set <entity_id> |
Change indicator input values |
tv indicator get <entity_id> |
Get indicator info and inputs |
Options:
tv indicator add -i, --inputs-- JSON input overridestv indicator toggle --visible/--hidden-- Explicit visibility controltv indicator set -i, --inputs-- JSON input overrides (e.g.,'{"length": 50}')
tv indicator add "Relative Strength Index"
tv indicator set eFu1Ot -i '{"in_3": 20}'
tv indicator toggle eFu1Ot --hidden
tv indicator remove eFu1Ot
Pane / Layout Management¶
| Subcommand | Description |
|---|---|
tv pane list |
List all panes in the current layout |
tv pane layout <code> |
Set chart grid layout |
tv pane focus <index> |
Focus a specific pane by index |
tv pane symbol <index> <symbol> |
Set the symbol on a specific pane |
See the Tool Reference for the full list of layout codes.
Tab Management¶
| Subcommand | Description |
|---|---|
tv tab list |
List all open chart tabs |
tv tab new |
Open a new chart tab |
tv tab close |
Close the current tab |
tv tab switch <index> |
Switch to a tab by index |
Saved Layouts¶
| Subcommand | Description |
|---|---|
tv layout list |
List saved chart layouts |
tv layout switch <name> |
Switch to a saved layout by name or ID |
UI Automation¶
| Subcommand | Description |
|---|---|
tv ui click |
Click a UI element by selector |
tv ui keyboard <key> |
Press a keyboard key or shortcut |
tv ui hover |
Hover over a UI element |
tv ui scroll [direction] |
Scroll the chart (up/down) |
tv ui find <query> |
Find UI elements by text, aria-label, or CSS |
tv ui eval <expression> |
Execute JavaScript in TradingView page context |
tv ui type <text> |
Type text into focused input |
tv ui panel <name> [action] |
Open/close/toggle a panel (pine-editor, strategy-tester, etc.) |
tv ui fullscreen |
Toggle fullscreen mode |
tv ui mouse <x> <y> |
Click at coordinates |
Examples:
tv ui panel pine-editor open
tv ui click -b aria-label -v "Indicators"
tv ui keyboard Escape
tv ui keyboard s --ctrl # Ctrl+S
tv ui mouse 400 300 --double
Streaming¶
| Subcommand | Description | Default Interval |
|---|---|---|
tv stream quote |
Real-time price ticks | 300ms |
tv stream bars |
Last bar updates (emits on change) | 500ms |
tv stream values |
Indicator values (RSI, MACD, etc.) | 500ms |
tv stream lines |
Pine Script line levels | 1000ms |
tv stream labels |
Pine Script label annotations | 1000ms |
tv stream tables |
Pine Script table data | 2000ms |
tv stream all |
All panes at once (multi-symbol) | 500ms |
All stream subcommands accept -i, --interval to override the poll interval in milliseconds. Pine-specific streams also accept -f, --filter to filter by study name.
Stream commands output JSONL (one JSON object per line) to stdout and never terminate until interrupted with Ctrl+C. See Streaming for details.
tv stream quote
tv stream bars -i 1000
tv stream values | jq '.studies[] | select(.name | contains("RSI"))'
tv stream lines -f "ICT"
tv stream all > multi_pane_log.jsonl
Piping and Composition¶
Every command outputs valid JSON to stdout, making it composable with standard Unix tools:
# Get current symbol
tv state | jq -r '.symbol'
# Monitor price and log to file
tv stream quote >> price_log.jsonl
# Screenshot all symbols in a watchlist
tv watchlist get | jq -r '.symbols[].symbol' | while read sym; do
tv symbol "$sym"
tv screenshot -o "$sym"
done
# Check if RSI is oversold
tv values | jq '.studies[] | select(.name | contains("RSI")) | .values'