calculate_trima
Compute Triangular Moving Average (TRIMA) for financial price data to identify trends and smooth volatility in technical analysis.
Instructions
Calculate Triangular Moving Average (TRIMA).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"kwargs": "<kwargs>"
},
"name": "calculate_trima"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kwargs | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_talib/core/server.py:336-349 (handler)The MCP tool handler for 'calculate_trima', registered with @mcp.tool(). Delegates computation to the 'trima' indicator from the registry.
@mcp.tool() async def calculate_trima(close: List[float], timeperiod: int = 30) -> Dict[str, Any]: try: indicator = registry.get_indicator("trima") if not indicator: raise ValueError("TRIMA indicator not found") market_data = MarketData(close=close) result = await indicator.calculate(market_data, {"timeperiod": timeperiod}) if result.success: return {"success": True, "values": result.values, "metadata": result.metadata} return {"success": False, "error": result.error_message} except Exception as e: return {"success": False, "error": str(e)} - The TRIMAIndicator class containing the core implementation using TA-Lib's TRIMA function. Includes input schema definition and calculate method.
class TRIMAIndicator(BaseIndicator): def __init__(self): super().__init__(name="trima", description="Triangular Moving Average (TRIMA)") @property def input_schema(self) -> Dict[str, Any]: return {"type": "object", "properties": {"close_prices": {"type": "array", "items": {"type": "number"}}, "timeperiod": {"type": "integer", "default": 30}}, "required": ["close_prices"]} async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: if options is None: options = {} timeperiod = options.get("timeperiod", 30) close = np.asarray(market_data.close, dtype=float) try: out = ta.TRIMA(close, timeperiod=timeperiod) return IndicatorResult(indicator_name=self.name, success=True, values={"trima": out.tolist()}, metadata={"timeperiod": timeperiod, "input_points": len(close), "output_points": len(out)}) except Exception as e: return IndicatorResult(indicator_name=self.name, success=False, values={}, error_message=str(e)) - src/mcp_talib/indicators/__init__.py:42-42 (registration)Registration of the TRIMAIndicator class in the global indicator registry.
registry.register("trima", TRIMAIndicator) - Input schema definition for the TRIMA indicator, specifying close_prices array and timeperiod integer.
@property def input_schema(self) -> Dict[str, Any]: return {"type": "object", "properties": {"close_prices": {"type": "array", "items": {"type": "number"}}, "timeperiod": {"type": "integer", "default": 30}}, "required": ["close_prices"]}