Skip to main content
Glama

ta_rsi

Calculate the Relative Strength Index (RSI) for crypto market analysis using historical price data and customizable period settings within the CG Alpha MCP server, aiding in identifying overbought or oversold conditions.

Instructions

Compute RSI (Wilder). Inputs: values:number[] (oldest→newest), period?:number(14). Returns latest RSI.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
periodNo
valuesYes

Implementation Reference

  • MCP tool handler for 'ta_rsi': validates input array of values and period, calls taRSI helper, returns result 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 }) }; },
  • Core implementation of RSI (Wilder's method): normalizes input, seeds initial averages, applies exponential smoothing, computes final RSI value with edge case handling.
    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; }
  • Input schema for ta_rsi tool: requires 'values' as array of numbers, optional 'period' as number.
    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:328-335 (registration)
    Tool registration entry for 'ta_rsi' in the MCP tools list, including description, schema, and annotations.
    { 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 } },

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JCF0/cg-alpha-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server