ta_rsi
Calculate the Relative Strength Index (RSI) for crypto market analysis using Wilder's method to identify overbought or oversold conditions in token price data.
Instructions
Compute RSI (Wilder). Inputs: values:number[] (oldest→newest), period?:number(14). Returns latest RSI.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| values | Yes | ||
| period | No |
Implementation Reference
- mcp-server.js:227-235 (handler)MCP tool handler for ta_rsi: validates input array of values and period, calls taRSI helper, returns RSI value or error."ta_rsi": async (args) => { const values = Array.isArray(args?.values) ? args.values : null; const period = Number.isFinite(Number(args?.period)) ? Number(args.period) : 14; if (!values || values.length === 0) { return { content: textContent({ error:true, message:"'values' must be a non-empty array of numbers (oldest → newest)" }), isError:true }; } const out = taRSI(values, period); return { content: textContent({ ok:true, rsi: out, period }) }; },
- mcp-server.js:328-335 (registration)Registration of ta_rsi tool in the tools list, including description, input schema, and annotations for MCP protocol.{ name:"ta_rsi", description:"Compute RSI (Wilder). Inputs: values:number[] (oldest→newest), period?:number(14). Returns latest RSI.", inputSchema:{ type:"object", properties:{ values:{ type:"array", items:{ type:"number" } }, period:{ type:"number" } }, required:["values"] }, annotations:{ title:"TA: RSI", readOnlyHint:true, openWorldHint:false } },
- mcp-server.js:330-333 (schema)Input schema definition for ta_rsi tool parameters.inputSchema:{ type:"object", properties:{ values:{ type:"array", items:{ type:"number" } }, period:{ type:"number" } }, required:["values"] },
- services/ta.js:12-47 (helper)Core implementation of RSI (Wilder's method) computation function, exported and used as taRSI by the handler.export function rsi(values, period = 14) { const arr = normalize(values); if (arr.length < period + 1) return null; // Seed averages over the first `period` deltas let gains = 0, losses = 0; for (let i = 1; i <= period; i++) { const d = arr[i] - arr[i - 1]; if (d >= 0) gains += d; else losses -= d; } let avgGain = gains / period; let avgLoss = losses / period; // Wilder smoothing for the remaining deltas for (let i = period + 1; i < arr.length; i++) { const d = arr[i] - arr[i - 1]; const gain = d > 0 ? d : 0; const loss = d < 0 ? -d : 0; avgGain = (avgGain * (period - 1) + gain) / period; avgLoss = (avgLoss * (period - 1) + loss) / period; } if (!isFiniteNum(avgGain) || !isFiniteNum(avgLoss)) return null; // Handle flat / division-by-zero cases explicitly if (avgLoss === 0) { if (avgGain === 0) return 50; // perfectly flat return 100; // only gains } const rs = avgGain / avgLoss; if (!isFiniteNum(rs)) return null; const rsi = 100 - (100 / (1 + rs)); return isFiniteNum(rsi) ? clamp(rsi, 0, 100) : null; }