evaluate_strategy
Assess trading strategies against current market conditions to identify optimal approaches for risk management and performance.
Instructions
Evaluate a trading strategy against current market conditions. Built-in strategies: conservative_dca, momentum_rider, macro_aligned, fear_accumulator, full_defensive. Also evaluates custom strategies created with set_custom_strategy.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| strategy | Yes | Strategy name (e.g. "conservative_dca", "momentum_rider", "full_defensive", or a custom name) |
Implementation Reference
- src/tools/evaluate-strategy.ts:12-49 (handler)The MCP tool handler for 'evaluate_strategy'. It resolves the strategy definition (builtin or custom) and calls the strategy engine to evaluate it against current values.
export async function evaluateStrategyTool(cache: CacheService, strategyName: string): Promise<StrategyEvaluation | ErrorOutput> { // Find strategy — check builtins first, then custom let strategy: StrategyDefinition | null = BUILTIN_STRATEGIES.find(s => s.name === strategyName) ?? null; if (!strategy) { const custom = getStrategy(AGENT_ID, strategyName); if (custom) { strategy = { name: custom.name, description: `Custom strategy: ${custom.name}`, conditions: custom.conditions, action_when_met: 'execute', action_when_not_met: 'wait', }; } } if (!strategy) { const available = BUILTIN_STRATEGIES.map(s => s.name).join(', '); return { error: true, error_source: 'evaluate_strategy', agent_guidance: `Strategy "${strategyName}" not found. Available built-in strategies: ${available}. You can also create custom strategies with set_custom_strategy.`, last_known_data: null, data_warnings: [`Unknown strategy: ${strategyName}`], }; } try { const reality = await getRealityCheck(cache); const currentValues = extractCurrentValues(reality as unknown as Record<string, unknown>); return evaluateStrategy(strategy, currentValues); } catch { return { error: true, error_source: 'evaluate_strategy', agent_guidance: 'Strategy evaluation temporarily unavailable. Retry shortly.', last_known_data: null, data_warnings: ['Strategy evaluation service temporarily unavailable.'], }; } } - The core engine logic that evaluates a StrategyDefinition against current values to determine if conditions are met and what action to take.
export function evaluateStrategy( strategy: StrategyDefinition, currentValues: Record<string, string | number | null>, ): StrategyEvaluation { const details: ConditionResult[] = []; let allMet = true; for (const condition of strategy.conditions) { const result = evaluateCondition(condition, currentValues); details.push(result); if (!result.met) allMet = false; } const action = allMet ? strategy.action_when_met : strategy.action_when_not_met; let guidance = `Strategy "${strategy.name}": `; if (allMet) { guidance += `ALL conditions met. Action: ${action.toUpperCase()}. `; if (action === 'execute') guidance += 'Conditions are favorable for this strategy. Proceed with position sizing appropriate to your risk tolerance.'; else if (action === 'exit') guidance += 'Exit conditions triggered. Reduce or close positions immediately.'; } else { const unmet = details.filter(d => !d.met); guidance += `${unmet.length} condition${unmet.length === 1 ? '' : 's'} not met. Action: WAIT. `; guidance += `Unmet: ${unmet.map(u => `${u.field} is ${u.current_value} (need ${u.operator} ${u.threshold})`).join('; ')}.`; } return { strategy_name: strategy.name, description: strategy.description, conditions_met: allMet, conditions_detail: details, action, agent_guidance: guidance, }; }