UNPKG

@gabriel3615/ta_analysis

Version:

stock ta analysis

41 lines (40 loc) 1.69 kB
import { TradeDirection } from '../../../types.js'; function clamp(value, min = 0, max = 100) { return Math.max(min, Math.min(max, value)); } export function createTrendlinePlugin() { return { id: 'trendline', category: 'additional', extract(input, _context) { const tl = input.analyses.trendline; let direction = TradeDirection.Neutral; let confidence = 50; if (tl.channel) { if (tl.channel.slope > 0) direction = TradeDirection.Long; else if (tl.channel.slope < 0) direction = TradeDirection.Short; confidence = 55 + Math.min(15, Math.abs(tl.channel.slope) * 1e4 * 0.5); const touches = (tl.channel.touchesUpper ?? 0) + (tl.channel.touchesLower ?? 0); confidence += Math.min(10, touches * 1.5); } if (tl.breakoutRetest) { direction = tl.breakoutRetest.direction === 'up' ? TradeDirection.Long : TradeDirection.Short; confidence = Math.max(confidence, tl.breakoutRetest.qualityScore ?? 65); if (tl.breakoutRetest.retested) confidence += 20; } return { direction, confidence: clamp(confidence), source: 'trendline' }; }, summarize(input) { const tl = input.analyses.trendline; const slope = tl.channel?.slope ?? 0; return (tl.summary || `通道斜率:${typeof slope?.toFixed === 'function' ? slope.toFixed(4) : slope}`); }, }; }