Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Generate TradingView-style dark-theme candlestick charts with RSI, MACD, Bollinger Bands, and EMA/SMA using mplfinance.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: charting3version: 1.0.04description: Generate TradingView-style candlestick charts with indicators. Use when the user wants a visual chart, price visualization, or technical analysis plot.56metadata:7starchild:8emoji: "๐"9skillKey: charting10requires:11env: [COINGECKO_API_KEY]12install:13- kind: pip14package: mplfinance15- kind: pip16package: pandas17- kind: pip18package: numpy1920user-invocable: true21disable-model-invocation: false22---2324# Charting2526## โ ๏ธ CRITICAL: DO NOT CALL DATA TOOLS2728**NEVER** call `price_chart`, `get_coin_ohlc_range_by_id`, `twelvedata_time_series`, or ANY market data tools when creating charts. Chart scripts fetch data internally. Calling these tools floods your context with 78KB+ of unnecessary data.2930**Workflow (4 steps):**311. Read template from `skills/charting/scripts/`322. Write script to `scripts/`333. Run script with `bash`344. Call `read_file` on the output PNG, then display it using markdown image syntax: ``3536---3738You generate TradingView-quality candlestick charts. Dark theme, clean layout, professional colors. Every chart is a standalone Python script โ no internal imports.3940**Additional Rules:**41- Chart scripts run in workspace and cannot import from `core`. Use `requests` library directly, NOT `proxied_get()`.42- Templates include proxy auto-configuration. If `PROXY_HOST` env var exists, scripts automatically configure `HTTP_PROXY`/`HTTPS_PROXY`.4344Tools: `write_file`, `bash`, `read_file`4546## When to Use Which Chart4748**Simple price action** โ Candlestick with no indicators. Good for "show me BTC this month."49**Trend analysis** โ Add EMA/SMA overlays. Good for "is ETH in an uptrend?"50**Momentum check** โ Add RSI or MACD as subplots. Good for "is SOL overbought?"51**Full technical view** โ Candles + Bollinger Bands + RSI + MACD. Good for "give me the full picture on BTC."52**Volume analysis** โ Requires separate fetch from market_chart endpoint (OHLC endpoint has no volume).53**Asset comparison** โ Line chart comparing two assets (BTC vs Gold, ETH vs S&P500, etc.). Use comparison template for normalized or percentage-based comparisons.5455## How to Build Charts5657Read and customize the template scripts in `skills/charting/scripts/`:58- `chart_template.py` โ Baseline candlestick chart with TradingView styling (crypto via CoinGecko)59- `chart_with_indicators.py` โ RSI, MACD, Bollinger Bands, EMA/SMA examples (crypto via CoinGecko)60- `chart_stock_template.py` โ Stock/forex chart using Twelve Data API61- `chart_comparison_template.py` โ Compare two assets (crypto vs commodity, stock vs crypto, etc.)6263Copy the relevant template to `scripts/`, customize the config section (coin, days, indicators), and run it.6465The templates handle all data fetching internally with retry logic and error handling.6667**Note:** These templates are for market data visualization (price charts, indicators). For backtest result charts (equity curves, drawdowns, performance dashboards), add matplotlib charting directly to your backtest script โ the data is already there, no need to re-fetch or create a separate file.6869## TradingView Color Palette7071| Element | Color | Hex |72|---------|-------|-----|73| Up candles | Teal | `#26a69a` |74| Down candles | Red | `#ef5350` |75| Background | Dark | `#131722` |76| Grid | Subtle dotted | `#1e222d` |77| Text / axes | Light gray | `#d1d4dc` |78| MA lines | Blue / Orange | `#2196f3` / `#ff9800` |79| RSI line | Purple | `#b39ddb` |80| MACD line | Blue | `#2196f3` |81| Signal line | Orange | `#ff9800` |8283Do not deviate from this palette unless the user asks.8485## Data Source APIs8687### CoinGecko (Crypto Only)8889**Endpoint:** `https://pro-api.coingecko.com/api/v3/coins/{coin_id}/ohlc/range`90**Auth:** Header `x-cg-pro-api-key: {COINGECKO_API_KEY}`91**Use for:** BTC, ETH, SOL, and all cryptocurrencies9293Example:94```python95url = f"https://pro-api.coingecko.com/api/v3/coins/{COIN_ID}/ohlc/range"96params = {"vs_currency": "usd", "from": from_ts, "to": now, "interval": "daily"}97headers = {"x-cg-pro-api-key": os.getenv("COINGECKO_API_KEY")}98resp = requests.get(url, params=params, headers=headers)99raw = resp.json() # [[timestamp_ms, open, high, low, close], ...]100```101102### Twelve Data (Stocks, Forex, Commodities)103104**Endpoint:** `https://api.twelvedata.com/time_series`105**Auth:** Query param `apikey={TWELVEDATA_API_KEY}`106**Use for:** Stocks (AAPL, MSFT), Forex (EUR/USD), Commodities (XAU/USD for gold)107108**Common Symbols:**109- Stocks: `AAPL`, `MSFT`, `GOOGL`, `TSLA`, `SPY`110- Forex: `EUR/USD`, `GBP/JPY`, `USD/CHF`111- Commodities: `XAU/USD` (gold), `XAG/USD` (silver), `CL/USD` (crude oil)112113**Intervals:** `1min`, `5min`, `15min`, `30min`, `1h`, `4h`, `1day`, `1week`, `1month`114115Example:116```python117url = "https://api.twelvedata.com/time_series"118params = {119"symbol": "XAU/USD", # Gold spot price120"interval": "1day",121"outputsize": 90, # Number of candles122"apikey": os.getenv("TWELVEDATA_API_KEY")123}124resp = requests.get(url, params=params)125data = resp.json()126# data["values"] = [{"datetime": "2024-01-01", "open": "2050.00", "high": "2060.00", ...}, ...]127```128129**IMPORTANT:** Twelve Data returns data in **reverse chronological order** (newest first). Always reverse the list before creating a DataFrame:130```python131values = data["values"][::-1] # Reverse to oldest-first132```133134## Interval Selection Strategy135136The templates now auto-select optimal intervals to minimize data volume while maintaining visual quality:137138| Time Range | Auto-Selected Interval | Rationale |139|------------|----------------------|-----------|140| โค31 days | Hourly | High granularity for short-term analysis |141| 32-365 days | Daily | Sufficient detail, lower data volume |142| >365 days | Daily | Daily is optimal for long-term trends |143144**Override:** Set `INTERVAL = "daily"` or `INTERVAL = "hourly"` in the config to override auto-selection.145146## Key Gotchas147148- **`savefig` facecolor**: You MUST set `facecolor='#131722'` and `edgecolor='#131722'` in `savefig`, or the saved PNG reverts to white background.149- **Title spacing**: Prefix titles with `\n` to add spacing from the top edge.150- **`returnfig=True`**: Use when you need post-plot customization (price formatting, annotations). When using it, call `fig.savefig()` manually โ don't pass `savefig` to `mpf.plot()`.151- **No volume in OHLC**: CoinGecko OHLC endpoint returns `[timestamp_ms, open, high, low, close]` only. Use `volume=False` or fetch volume separately from `coin_chart` endpoint.152- **Panel ratios**: Set `panel_ratios` when adding indicator subplots. E.g., `(4, 1, 2)` for candles + volume + one indicator, `(5, 1, 2, 2)` for two indicators.153- **Figure size**: Default `(14, 8)`. Increase to `(14, 10)` or `(14, 12)` when adding subplots.154155## Rules156157- **Paths are relative to workspace.** Write to `scripts/foo.py`, not `workspace/scripts/foo.py`. The bash CWD is already workspace.158- **Always save to `output/` directory.** Use `os.makedirs("output", exist_ok=True)`.159- **Always run the script with `bash("python3 scripts/<name>.py")`** to verify it works.160- **Always call `read_file` on the generated PNG, then use markdown image syntax to display it:** ``161- **Scripts must be standalone.** Use `requests` + `os.getenv()`. No internal imports, no dotenv.162- **CRITICAL: Do NOT use proxied_get() in chart scripts.** Chart scripts are standalone and run in the workspace - they cannot import from `core.http_client`. Always use `requests.get()` and `requests.post()` directly. This is an exception to the PLATFORM.md proxy rules because these scripts execute outside the main Star Child process. The templates demonstrate the correct pattern.163- **Env vars are inherited.** `os.getenv("COINGECKO_API_KEY")` works directly.164- **Default to dark theme** unless user asks for light.165- **Filename should describe the chart.** e.g. `btc_30d_candles.png`, `eth_7d_rsi_macd.png`.166- **Data sources:** Use CoinGecko API for crypto (BTC, ETH, etc). Use Twelve Data API for stocks, forex, and commodities (AAPL, EUR/USD, XAU/USD for gold). Never mix APIs - keep scripts focused on one data source.167- **Think about what you're measuring:** Before creating a chart, ask yourself: "What question is the user trying to answer?" A normalized chart (all start at 100) shows relative trends but hides actual gain magnitude. If the user wants to know "which gained more" or is comparing investment performance, they need the actual multipliers (e.g., 50x vs 10x), not just lines that look similar.168169## Troubleshooting170171### 401 Unauthorized Errors172173Templates auto-configure proxy from `PROXY_HOST`/`PROXY_PORT` env vars. If 401 errors occur:174175**Check environment:**176```bash177bash("env | grep -E 'PROXY|REQUESTS_CA'")178```179180**Expected vars:**181- `PROXY_HOST` / `PROXY_PORT` - Proxy address (templates use these to set HTTP_PROXY/HTTPS_PROXY)182- `REQUESTS_CA_BUNDLE` - Proxy CA cert for SSL183- `COINGECKO_API_KEY` / `TWELVEDATA_API_KEY` - Can be fake in proxied environments184185If vars are missing, this is an environment configuration issue, not a script issue.186