tradingview-mcp-py
by CenblueOne
README.md
# J-SQUAD TradingView MCP โ Python (`tradingview-mcp-py`)
> **30 tools ยท 5 modules** โ MCP server for stock analysis (TradingView Screener API, Yahoo Finance, IDX/BEI, backtesting, news sentiment, trade math).
> **Lean edition, no CDP** โ no TradingView Desktop / Chrome required, so it's **VPS-compatible**.
Built by [CenblueOne](https://github.com/CenblueOne) as part of the **J-SQUAD** system (IDX trading bot).
> ๐ค **For AI agents / harnesses (Claude Code, Hermes, opencode, Cursor, Grok, etc.)**:
> read [`AGENTS.md`](AGENTS.md) โ architecture, how to run/test, tool inventory,
> and mandatory rules (never upgrade `mcp`, never use `"command": "python"`, etc.).
---
## โจ Highlights
- โ
**No TradingView Desktop** โ uses TradingView public Screener API + Yahoo Finance (runs headless on servers/VPS)
- โ
**IDX-ready** โ `idx_*` tools auto-append `.JK` (BBRI โ BBRI.JK)
- โ
**Graceful degradation** โ if a library is missing, only that module's tools are disabled
- โ
**Tested** โ `pytest` 13 tests passed (helpers + server import + market_cap mocked)
- โ
**Multi-agent ready** โ one shared venv across many agents; per-agent config files; stdio (no port conflicts)
---
## โ ๏ธ Agent / AI Guide โ Check FIRST Before Installing / Configuring
> Read this section every time an agent (Claude Code, Hermes, opencode, Grok, etc.)
> wants to install / configure / upgrade this server. This server can be shared by MANY
> agents on one machine โ the most common mistakes come from unnecessary re-installs
> or using `"command": "python"`.
**Mandatory checklist:**
1. **Check whether it's already installed** โ don't blindly reinstall:
```bash
# venv exists?
Test-Path "<REPO_DIR>\venv\Scripts\python.exe"
# mcp 1.x installed? (MUST be < 2.0.0)
& "<REPO_DIR>\venv\Scripts\python.exe" -c "import importlib.metadata as m; print(m.version('mcp'))"
```
If it exists and mcp is `1.x` โ **STOP, don't install anything**.
2. **NEVER upgrade / reinstall `mcp`.** The server uses the `mcp.server.fastmcp.FastMCP`
API which only exists in **mcp 1.x**. mcp 2.x completely reworked the API โ the server
fails to start. `requirements.txt` already pins `mcp>=1.2.0,<2.0.0`.
3. **NEVER use `"command": "python"` / `"command": "python3"`.** Always point to the
**venv python with an absolute path** โ PATH differs per agent (e.g. store-alias on
Windows, or `python` pointing to a different interpreter without dependencies). Venv path:
```
<REPO_DIR>\venv\Scripts\python.exe
```
4. **NEVER reinstall / upgrade while another agent is running.** The single `venv`
is shared. `pip install` / `pip upgrade` in the middle mutates the dependencies used
by all agents โ other agents break (real case: mcp bumped to 2.x removed `FastMCP`).
Install ONCE via `install.bat`.
5. **One venv + one server.py โ many separate config files.** Each agent has its own
MCP config file; paste the same entry (see `mcp-config.example.json`) into each file.
Don't overwrite another agent's config.
6. **Verify after configuring** โ test 1 tool from EACH agent before using together:
```bash
# import must succeed without errors (run from the project folder)
cd "<REPO_DIR>"
& "<REPO_DIR>\venv\Scripts\python.exe" -c "import server; print('server OK')"
```
Or call a tool directly from each agent's chat (`idx_price BBRI`). Don't continue
if any agent still errors.
---
## ๐ฆ Modules & Tools (30 total)
### Technical Analysis โ 6 tools (`tradingview-ta`)
| Tool | Description |
|------|-------------|
| `get_ta` | Full TA: RSI, MACD, BB, EMA, ADX, Stoch, CCI |
| `get_ta_bulk` | TA for many symbols (max 25, rate-limited) |
| `get_mtf` | Multi-timeframe: 1h + 4h + 1d + 1w alignment |
| `get_candlestick` | Detect 15 candlestick patterns |
| `get_bollinger` | Bollinger Band: position, bandwidth, squeeze |
| `screen_stocks` | Screen stocks by TA signal + RSI filter |
### Yahoo Finance โ 4 tools (`yfinance`)
| Tool | Description |
|------|-------------|
| `yf_price` | Realtime price (AAPL, BTC-USD, BBRI.JK, ^JKSE) |
| `get_market_cap` | Market cap + 52w high/low + TA context |
| `market_snapshot` | Global snapshot: S&P500, NASDAQ, VIX, IHSG, BTC, ETH, GOLD, OIL, DXY |
| `yf_ohlcv` | Historical OHLCV (configurable period + interval) |
### IDX / BEI โ 11 tools
| Tool | Description |
|------|-------------|
| `idx_price` | BEI stock price (auto `.JK`) |
| `idx_ta` | BEI stock TA via TradingView Screener |
| `idx_mtf` | BEI stock MTF |
| `idx_market` | IHSG snapshot + top 10 LQ45 + gainers/losers |
| `idx_screener` | Screen BEI stocks by movement & volume |
| `idx_signals` | BUY/SELL/HOLD signals for a BEI stock list |
| `idx_backtest` | Backtest strategies on BEI stocks |
| `idx_deep_analysis` | 100pt stock score (trend/momentum/volatility) |
| `morning_brief_idx` | Morning brief: scan BEI watchlist, rank TA + price |
| `combined_analysis` | TA + Price + Sentiment โ STRONG BUY/SELL |
| `financial_news` | Live headlines (Yahoo, CNBC, MarketWatch) |
### Backtesting โ 3 tools (`services/backtest_service.py`)
| Tool | Description |
|------|-------------|
| `backtest_strategy` | 1 strategy, institutional metrics |
| `compare_strategies` | Compare 9 strategies, ranked by total return |
| `walk_forward_backtest` | Walk-forward, overfitting detection |
### Trading Utilities & Sentiment โ 6 tools
| Tool | Description |
|------|-------------|
| `market_sentiment` | Sentiment from Yahoo News for a symbol |
| `position_size` | Lot size by risk management |
| `rr_calc` | Risk:Reward ratio from entry/SL/TP |
| `journal_add` | Log a trade to the local journal |
| `journal_list` | Trade journal history |
| `market_sessions` | Global trading sessions (WIB / UTC+7) |
---
## ๐ง Requirements
```
Python >= 3.11 (tested on 3.11)
mcp >= 1.2.0, < 2.0.0 (MUST be 1.x โ server uses mcp.server.fastmcp.FastMCP)
tradingview-ta >= 3.3.0
yfinance >= 0.2.40
pandas >= 2.0.0
numpy >= 1.24.0
feedparser >= 6.0.0
requests >= 2.31.0
```
> **Not needed** `websocket-client` / Chrome โ the CDP module (TradingView Desktop) was **removed** on 03 Jul 2026.
---
## ๐ Installation
> `install.bat` (Windows) or the manual commands below โ run **ONCE**.
> After installation, replace every `<REPO_DIR>` in the config examples with the
> absolute path where you cloned this repo on your machine.
### Windows
```bat
install.bat
```
### Linux / macOS (VPS-compatible)
```bash
python3 -m venv venv
venv/bin/pip install -r requirements.txt
```
### Verify (all OS)
```bash
venv/Scripts/python server.py # Windows
venv/bin/python server.py # Linux/macOS โ MCP stdio server, waits for JSON-RPC on stdin
```
> **NEVER run a bare `pip install mcp` / upgrade mcp.** `requirements.txt` pins
> `mcp>=1.2.0,<2.0.0` โ mcp 2.x completely reworked the API and is incompatible.
### Quick smoke test (no network)
```bash
venv/Scripts/pip install pytest # Windows
venv/bin/pip install pytest # Linux/macOS
venv/Scripts/python -m pytest # Windows โ 13 passed
venv/bin/python -m pytest # Linux/macOS โ 13 passed
```
---
## ๐ค Per-Agent Configuration (Universal โ stdio)
> **IMPORTANT**: each agent has its **own config file**. Don't merge multiple agents
> into one file, and don't overwrite another agent's config.
### Claude Code / Grok
`~/.claude.json` (global) or `.mcp.json` (project root) โ `mcpServers`:
```json
{
"mcpServers": {
"tradingview-mcp-py": {
"command": "<REPO_DIR>\\venv\\Scripts\\python.exe",
"args": ["<REPO_DIR>\\server.py"],
"env": {}
}
}
}
```
### Hermes Agent
`~/.hermes/config.yaml` โ `mcp_servers`:
```yaml
mcp_servers:
tradingview-mcp-py:
command: "<REPO_DIR>\\venv\\Scripts\\python.exe"
args: ["<REPO_DIR>\\server.py"]
type: stdio
```
### opencode
`opencode.json` (project root) โ `mcp`:
```json
{
"mcp": {
"tradingview-mcp-py": {
"type": "local",
"command": ["<REPO_DIR>\\venv\\Scripts\\python.exe", "<REPO_DIR>\\server.py"]
}
}
}
```
> **Absolute path is MANDATORY** for `command` (venv python) and `args` (server.py).
> Don't use `"command": "python"`. Ready-to-use example: `mcp-config.example.json`.
### Verify
After registering, call a tool from each agent's chat, e.g.:
```
get_ta BBRI exchange=IDX screener=indonesia
idx_deep_analysis TLKM
morning_brief_idx
```
---
## ๐ฅ Multi-Agent โ Several Agents on 1 Machine
Same pattern as other MCP servers in this workspace (`yfinance-mcp-final`, `invezgo-mcp`):
| Rule | Explanation |
|---|---|
| **1 venv + 1 server.py โ N separate configs** | All agents use the same venv & server, but each agent has its own config |
| **stdio** | Each agent spawns its own Python process โ **no port conflicts**, no stdout contention |
| **Absolute path** | `command` โ `venv\Scripts\python.exe`; `args` โ absolute path to `server.py` |
| **mcp pinned to 1.x** | `requirements.txt` pins `mcp>=1.2.0,<2.0.0`. Don't run bare `pip install mcp` / upgrade |
| **Install once** | Don't reinstall while another agent is running โ it mutates shared dependencies |
| **Check first** | Before installing, run the checklist at the top of this README |
**Most common error scenarios:**
1. *All tools error "unknown function" / import fails* โ venv was upgraded to mcp 2.x
or system python was used. Check: `venv\Scripts\python -c "import importlib.metadata as m; print(m.version('mcp'))"` โ must be `1.x`.
2. *"python: can't open file 'server.py'"* โ use an absolute path, not relative.
3. *Agent A works, agent B errors* โ usually agent B uses `"command": "python"` pointing
to a different Python / one without dependencies. Point all agents to the same venv.
4. *Yahoo rate limit (429)* across 4 agents at once โ expected; raise the `requests.Session`
retry in `server.py` or limit polling frequency.
---
## ๐ All AI Clients (Model-Agnostic)
This server uses **MCP stdio transport** โ usable by **any AI model / client that supports
MCP**, not just one vendor:
| Client | How to register |
|--------|-------------|
| **Claude Code / Grok** | `mcpServers` in `.mcp.json` (project) / `~/.claude.json` (global) โ absolute path to `venv\Scripts\python.exe` |
| **Claude Desktop** | Add the block to `claude_desktop_config.json` (see `mcp-config.example.json`) |
| **Hermes Agent** | `mcp_servers` in `~/.hermes/config.yaml` โ absolute path to venv python |
| **opencode** | `mcp` in `opencode.json` โ absolute path to venv python |
| **Cursor / VS Code** | Add to `mcp.json` / MCP settings โ absolute path to venv python |
| **ChatGPT / others** | If the client supports MCP stdio, point it to `venv\Scripts\python.exe server.py` |
All clients above call the **same tools** (`get_ta`, `idx_deep_analysis`,
`morning_brief_idx`, etc.). Nothing is hardcoded to a specific model.
> **Multi-agent golden rule**: one shared venv, but **separate config per agent** +
> **absolute path**. Don't merge all agents into a single config file.
---
## ๐ก Usage Examples
**Analyze BBRI:**
```
Analyze BBRI on IDX โ TA + sentiment + price
```
โ `combined_analysis(symbol="BBRI", exchange="IDX", screener="indonesia")`
**Morning scan IDX:**
```
Run morning brief for IDX
```
โ `morning_brief_idx()`
**Backtest:**
```
Backtest TLKM with supertrend strategy for 1 year
```
โ `idx_backtest(symbol="TLKM", strategy="supertrend", period="1y")`
**Position sizing:**
```
Balance 10k, risk 1%, SL 50 pips, gold
```
โ `position_size(balance=10000, risk_pct=1, sl_pips=50, instrument="gold")`
---
## ๐งฉ Module Dependency Map
```
TA tools โ tradingview-ta
YF tools โ yfinance
IDX tools โ tradingview-ta + yfinance
News/Sentiment โ feedparser + yfinance
Backtest โ services/backtest_service.py (pandas/numpy)
```
All modules **degrade gracefully** โ missing library โ only that module's tools are off.
---
## ๐งช Testing
```bash
venv\Scripts\pip install pytest
venv\Scripts\python -m pytest # 13 passed (helpers, server import, market_cap mocked)
```
Tests don't need network (mock `yfinance` / `tradingview_ta`).
---
## ๐ Part of J-SQUAD
The J-SQUAD IDX bot system:
- **ARA Hunter** โ ARA detection
- **Bandar Hunter** โ institutional accumulation detection
- **Signal Aggregator** โ signal aggregation
- **KINARA ENGINE** โ TradingView webhook โ Telegram
---
## ๐ License
See the [`LICENSE`](LICENSE) file โ **MIT**. Free to use, fork, and
develop. For security policy, see [`SECURITY.md`](SECURITY.md).This server cannot be deployed
Maintenance
ActivitySlowing
ResponsivenessNo issues