generate-asset-price-chart
Generate candlestick price charts for any asset from existing OHLC data, without handling data fetching.
What this skill does
# Generate Asset Price Chart (from OHLC data)
Render a candlestick chart image from preloaded OHLC candles. This skill focuses only on chart generation logic (no API calls).
## When to use
- You already have OHLC candles and need a visual chart
- You want to generate PNG charts in backend jobs or bots
- You need a reusable chart renderer for any asset/timeframe
## Required tools / APIs
- No external API required
- Node.js option: `canvas`
- Python option: `matplotlib`
Install:
```bash
# Node.js
npm install canvas
# Python
python -m pip install matplotlib
```
Input OHLC format expected by both examples:
- Array of rows: `[timestamp, open, high, low, close]`
- `timestamp` can be unix ms or any x-axis label value
## Skills
### generate_candlestick_chart_with_nodejs
```javascript
import { createCanvas } from "canvas";
import { writeFile } from "node:fs/promises";
function validateOhlc(data) {
if (!Array.isArray(data) || data.length === 0) {
throw new Error("OHLC data must be a non-empty array");
}
data.forEach((row, index) => {
if (!Array.isArray(row) || row.length < 5) {
throw new Error(`Invalid row at index ${index}. Expected [timestamp, open, high, low, close]`);
}
const [, open, high, low, close] = row;
[open, high, low, close].forEach((v) => {
if (!Number.isFinite(v)) {
throw new Error(`Non-numeric OHLC value at row ${index}`);
}
});
});
}
function generateCandlestickChart(ohlcData, options = {}) {
validateOhlc(ohlcData);
const width = options.width ?? 1200;
const height = options.height ?? 600;
const padding = options.padding ?? 60;
const canvas = createCanvas(width, height);
const ctx = canvas.getContext("2d");
// Background
ctx.fillStyle = "#1e1e2e";
ctx.fillRect(0, 0, width, height);
const chartWidth = width - padding * 2;
const chartHeight = height - padding * 2;
const highs = ohlcData.map((d) => d[2]);
const lows = ohlcData.map((d) => d[3]);
const minPrice = Math.min(...lows);
const maxPrice = Math.max(...highs);
const priceRange = Math.max(maxPrice - minPrice, 1e-9);
const xStep = chartWidth / Math.max(ohlcData.length, 1);
const yScale = chartHeight / priceRange;
// Grid
ctx.strokeStyle = "#333";
ctx.lineWidth = 1;
for (let i = 0; i <= 5; i++) {
const y = padding + (chartHeight / 5) * i;
ctx.beginPath();
ctx.moveTo(padding, y);
ctx.lineTo(width - padding, y);
ctx.stroke();
}
// Candles
ohlcData.forEach(([, open, high, low, close], index) => {
const x = padding + index * xStep + xStep / 2;
const highY = height - padding - (high - minPrice) * yScale;
const lowY = height - padding - (low - minPrice) * yScale;
const openY = height - padding - (open - minPrice) * yScale;
const closeY = height - padding - (close - minPrice) * yScale;
const bullish = close >= open;
ctx.strokeStyle = bullish ? "#4caf50" : "#f44336";
ctx.fillStyle = ctx.strokeStyle;
// Wick
ctx.beginPath();
ctx.moveTo(x, highY);
ctx.lineTo(x, lowY);
ctx.stroke();
// Body
const bodyTop = Math.min(openY, closeY);
const bodyHeight = Math.max(Math.abs(openY - closeY), 2); // keep flat candles visible
const bodyWidth = Math.max(xStep * 0.6, 1);
ctx.fillRect(x - bodyWidth / 2, bodyTop, bodyWidth, bodyHeight);
});
return canvas.toBuffer("image/png");
}
// Example usage with existing OHLC array
const sample = [
[1700000000000, 100, 110, 95, 108],
[1700000600000, 108, 112, 104, 106],
[1700001200000, 106, 115, 103, 113],
[1700001800000, 113, 118, 109, 111],
[1700002400000, 111, 119, 110, 117],
];
const image = generateCandlestickChart(sample, { width: 1200, height: 600 });
await writeFile("candlestick.png", image);
console.log("Saved: candlestick.png");
```
## Agent prompt
```text
You are generating a candlestick chart image from existing OHLC data only.
Do not fetch market data and do not add API logic.
Input format is an array of [timestamp, open, high, low, close].
Use either Node.js (canvas) or Python (matplotlib) to render candles with:
- dark background,
- simple horizontal grid,
- green bullish candles,
- red bearish candles,
- visible wick and body.
Return:
1) the code used,
2) output filename,
3) a short validation note (e.g., candle count rendered).
```
## Best practices
- Validate OHLC shape before rendering
- Ensure candle body has a minimum visible height for flat candles
- Keep rendering pure: chart function accepts data and returns/saves image
- Separate fetching/ETL from visualization
## Troubleshooting
- `Module not found: canvas` → run `npm install canvas`
- Python import error for matplotlib → run `python -m pip install matplotlib`
- Blank/flat chart → verify that OHLC values are numeric and vary across candles
- Inverted y-axis feeling → confirm conversion formula maps higher prices upward
## See also
- [trading-indicators-from-price-data.md](trading-indicators-from-price-data.md) — derive indicators before plotting
- [get-crypto-price.md](get-crypto-price.md) — fetch data separately, then pass OHLC into this chart skillRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.