@using TradingBot.Models
@if (PriceData == null || PriceData.Count < 2) {
In attesa di dati sufficienti...
} else { @for (int i = 0; i <= 4; i++) { var y = (Height * i / 4.0); } @if (!string.IsNullOrEmpty(GetAreaPath())) { } @if (!string.IsNullOrEmpty(GetPolylinePoints())) { } @if (Indicators != null) {
RSI: @Indicators.RSI.ToString("F1")
MACD: @Indicators.MACD.ToString("F2")
} }
@code { [Parameter] public List? PriceData { get; set; } [Parameter] public string Color { get; set; } = "#6366f1"; [Parameter] public TechnicalIndicators? Indicators { get; set; } private int Width = 800; private int Height = 300; private string ColorId => Guid.NewGuid().ToString("N").Substring(0, 8); private string GetPolylinePoints() { if (PriceData == null || PriceData.Count < 2) return string.Empty; try { var max = PriceData.Max(); var min = PriceData.Min(); var range = max - min; if (range == 0) range = max * 0.01m; // 1% range if all values are same var points = new List(); var padding = Height * 0.1; // 10% padding var chartHeight = Height - (padding * 2); for (int i = 0; i < PriceData.Count; i++) { var x = (i / (double)(PriceData.Count - 1)) * Width; var normalizedValue = (double)((PriceData[i] - min) / range); var y = padding + (chartHeight * (1 - normalizedValue)); points.Add($"{x:F2},{y:F2}"); } return string.Join(" ", points); } catch { return string.Empty; } } private string GetAreaPath() { var polyline = GetPolylinePoints(); if (string.IsNullOrEmpty(polyline)) return string.Empty; try { var points = polyline.Split(' '); if (points.Length < 2) return string.Empty; var firstPoint = points[0].Split(','); var lastPoint = points[points.Length - 1].Split(','); return $"M {firstPoint[0]},{Height} L {polyline} L {lastPoint[0]},{Height} Z"; } catch { return string.Empty; } } private string GetRSIClass() { if (Indicators == null) return "rsi-neutral"; if (Indicators.RSI > 70) return "rsi-overbought"; if (Indicators.RSI < 30) return "rsi-oversold"; return "rsi-neutral"; } }