getDEMA
Calculate the Double Exponential Moving Average (DEMA) for a stock to analyze trends and identify potential buy or sell signals using historical price data.
Instructions
Calculate the Double Exponential Moving Average (DEMA) for a stock using the FMP DEMA API. This tool helps users analyze trends and identify potential buy or sell signals based on historical price data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock symbol | |
| periodLength | Yes | Period length for the indicator | |
| timeframe | Yes | Timeframe (1min, 5min, 15min, 30min, 1hour, 4hour, 1day) | |
| from_date | No | Start date (YYYY-MM-DD) | |
| to | No | End date (YYYY-MM-DD) |
Implementation Reference
- The MCP tool registration and handler for 'getDEMA'. It registers the tool with a Zod schema for input validation (symbol, periodLength, timeframe, optional from_date and to), and the async handler calls technicalIndicatorsClient.getDEMA() then returns the result as JSON.
server.tool( "getDEMA", "Calculate the Double Exponential Moving Average (DEMA) for a stock using the FMP DEMA API. This tool helps users analyze trends and identify potential buy or sell signals based on historical price data.", { symbol: z.string().describe("Stock symbol"), periodLength: z.number().describe("Period length for the indicator"), timeframe: z .string() .describe("Timeframe (1min, 5min, 15min, 30min, 1hour, 4hour, 1day)"), from_date: z.string().optional().describe("Start date (YYYY-MM-DD)"), to: z.string().optional().describe("End date (YYYY-MM-DD)"), }, async ({ symbol, periodLength, timeframe, from_date: from, to }) => { try { const results = await technicalIndicatorsClient.getDEMA({ symbol, periodLength, timeframe, from, to, }); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } } ); - The DEMAIndicator interface extending TechnicalIndicatorBase, defining the shape of the DEMA API response with an additional 'dema' field.
// Double Exponential Moving Average (DEMA) export interface DEMAIndicator extends TechnicalIndicatorBase { dema: number; } - The TechnicalIndicatorParams interface used as input parameters for the getDEMA request.
export interface TechnicalIndicatorParams { symbol: string; periodLength: number; timeframe: string; from?: string; to?: string; } - The TechnicalIndicatorsClient.getDEMA() method that makes the actual API call to /technical-indicators/dema endpoint via the base FMPClient.
/** * Get Double Exponential Moving Average (DEMA) indicator * @param params Technical indicator parameters * @param options Optional parameters including abort signal and context */ async getDEMA( params: TechnicalIndicatorParams, options?: { signal?: AbortSignal; context?: FMPContext; } ): Promise<DEMAIndicator[]> { return super.get<DEMAIndicator[]>( "/technical-indicators/dema", params, options ); } - src/tools/technical-indicators.ts:10-14 (registration)The registerTechnicalIndicatorsTools function that creates the TechnicalIndicatorsClient instance (which the getDEMA handler uses). This is the registration entry point for all technical indicator tools.
export function registerTechnicalIndicatorsTools( server: McpServer, accessToken?: string ): void { const technicalIndicatorsClient = new TechnicalIndicatorsClient(accessToken);