calculate_ht_trendline
Calculate Hilbert Transform Trendline for financial market analysis to identify trend direction and strength in price data.
Instructions
Calculate Hilbert Transform Trendline.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kwargs | Yes |
Implementation Reference
- src/mcp_talib/core/server.py:180-192 (handler)MCP tool handler function for 'calculate_ht_trendline'. Delegates computation to the registered HTTrendlineIndicator instance.@mcp.tool() async def calculate_ht_trendline(close: List[float]) -> Dict[str, Any]: try: indicator = registry.get_indicator("ht_trendline") if not indicator: raise ValueError("HT_TRENDLINE indicator not found") market_data = MarketData(close=close) result = await indicator.calculate(market_data, {}) 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)}
- Core helper class implementing the Hilbert Transform Trendline indicator using TA-Lib's HT_TRENDLINE function on close prices.class HTTrendlineIndicator(BaseIndicator): def __init__(self): super().__init__(name="ht_trendline", description="Hilbert Transform - Instantaneous Trendline") @property def input_schema(self) -> Dict[str, Any]: return {"type": "object", "properties": {"close_prices": {"type": "array", "items": {"type": "number"}}}, "required": ["close_prices"]} async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: close = np.asarray(market_data.close, dtype=float) try: out = ta.HT_TRENDLINE(close) return IndicatorResult( indicator_name=self.name, success=True, values={"ht_trendline": out.tolist()}, metadata={"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:31-31 (registration)Registers the HTTrendlineIndicator class in the indicator registry under the key 'ht_trendline', enabling its use by the tool handler.registry.register("ht_trendline", HTTrendlineIndicator)
- Defines the input schema for the indicator, expecting 'close_prices' as an array of numbers.@property def input_schema(self) -> Dict[str, Any]: return {"type": "object", "properties": {"close_prices": {"type": "array", "items": {"type": "number"}}}, "required": ["close_prices"]}