Skip to main content
Glama
phuihock

TA-Lib MCP Server

by phuihock

calculate_ht_trendline

Calculate Hilbert Transform Trendline for financial market analysis to identify trend direction and potential reversals in price data.

Instructions

Calculate Hilbert Transform Trendline.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kwargsYes

Implementation Reference

  • MCP tool handler for 'calculate_ht_trendline'. Fetches 'ht_trendline' indicator from registry, creates MarketData from close prices, calls indicator.calculate(), and returns success/values or error.
    @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)}
  • HTTrendlineIndicator class implementing the core logic: wraps TA-Lib's ta.HT_TRENDLINE on close prices, handles input/output as IndicatorResult with values['ht_trendline'] and metadata.
    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))
  • Input schema definition for the indicator, specifying 'close_prices' as required 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"]}
  • Registration of HTTrendlineIndicator in the IndicatorRegistry under key 'ht_trendline', which is fetched by the handler.
    registry.register("ht_trendline", HTTrendlineIndicator)

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/phuihock/mcp-talib'

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