UNPKG

@gabriel3615/ta_analysis

Version:

stock ta analysis

50 lines (49 loc) 1.85 kB
import { TradeDirection } from '../../../types.js'; function clamp(value, min = 0, max = 100) { return Math.max(min, Math.min(max, value)); } export function createStructurePlugin() { return { id: 'structure', category: 'additional', extract(input, _context) { const s = input.analyses.structure; let direction = TradeDirection.Neutral; let confidence = 50; if (s.trend === 'up') { direction = TradeDirection.Long; confidence = 65; } else if (s.trend === 'down') { direction = TradeDirection.Short; confidence = 65; } const evt = s.lastEvent; if (evt) { if (evt.type === 'CHOCH') { confidence += 25; if (evt.direction === 'bullish') direction = TradeDirection.Long; else if (evt.direction === 'bearish') direction = TradeDirection.Short; } else if (evt.type === 'BOS') { confidence += 15; if (evt.direction === 'bullish') direction = TradeDirection.Long; else if (evt.direction === 'bearish') direction = TradeDirection.Short; } else confidence -= 10; if (evt.timeframe === 'daily') confidence += 5; } return { direction, confidence: clamp(confidence), source: 'structure' }; }, summarize(input) { const s = input.analyses.structure; return `结构趋势:${s.trend} 关键位数:${s.keyLevels?.length ?? 0}`; }, }; }