/// <summary> /// построить проекции /// </summary> public void MakeProjections() { projections.Clear(); foreach (var span in data) { if (!span.Completed) continue; var projs = span.GetProjections(); foreach (var index in projs) { var hasProj = false; foreach (var proj in projections) { if (proj.Index == index) {// подтвердить проекцию proj.AckDegree++; proj.Color = Color.Red; hasProj = true; break; } } if (hasProj) continue; // создать новую проекцию var newProj = new FiboSpanProjection {Index = index, Color = span.Color}; if (index >= 0 && index < Chart.StockSeries.Data.Count) newProj.UpperPrice = Chart.StockSeries.Data[index].low; projections.Add(newProj); } } // отфильтровать проекции if (projections.Count > 1) { projections = projections.OrderBy(p => p.Index).ToList(); for (var i = 0; i < projections.Count; i++) { var leftDegree = i == 0 ? 0 : projections[i - 1].Index == projections[i].Index - 1 ? projections[i - 1].AckDegree : 0; var rightDegree = i == (projections.Count - 1) ? 0 : projections[i + 1].Index == projections[i].Index + 1 ? projections[i + 1].AckDegree : 0; if (projections[i].AckDegree < leftDegree || projections[i].AckDegree < rightDegree) {// отфильтровать projections[i].Filtered = true; } } for (var i = 0; i < projections.Count; i++) { if (projections[i].Filtered) { projections.RemoveAt(i); i--; } } } }
/// <summary> /// построить проекции /// </summary> public void MakeProjections() { projections.Clear(); foreach (var span in data) { if (!span.Completed) { continue; } var projs = span.GetProjections(); foreach (var index in projs) { var hasProj = false; foreach (var proj in projections) { if (proj.Index == index) {// подтвердить проекцию proj.AckDegree++; proj.Color = Color.Red; hasProj = true; break; } } if (hasProj) { continue; } // создать новую проекцию var newProj = new FiboSpanProjection { Index = index, Color = span.Color }; if (index >= 0 && index < Chart.StockSeries.Data.Count) { newProj.UpperPrice = Chart.StockSeries.Data[index].low; } projections.Add(newProj); } } // отфильтровать проекции if (projections.Count > 1) { projections = projections.OrderBy(p => p.Index).ToList(); for (var i = 0; i < projections.Count; i++) { var leftDegree = i == 0 ? 0 : projections[i - 1].Index == projections[i].Index - 1 ? projections[i - 1].AckDegree : 0; var rightDegree = i == (projections.Count - 1) ? 0 : projections[i + 1].Index == projections[i].Index + 1 ? projections[i + 1].AckDegree : 0; if (projections[i].AckDegree < leftDegree || projections[i].AckDegree < rightDegree) {// отфильтровать projections[i].Filtered = true; } } for (var i = 0; i < projections.Count; i++) { if (projections[i].Filtered) { projections.RemoveAt(i); i--; } } } }
public void DrawProjection(Graphics g, RectangleD worldRect, Rectangle canvasRect, FiboSpanProjection proj, Brush brushWhite, Font font, PenStorage penStorage, BrushesStorage brushes) { // нижняя точка var projLow = Conversion.WorldToScreen(new PointD(proj.Index, 0), worldRect, canvasRect); projLow.Y = canvasRect.Bottom; // верхняя точка PointD projHigh = proj.UpperPrice.HasValue ? Conversion.WorldToScreen(new PointD(proj.Index, proj.UpperPrice.Value), worldRect, canvasRect) : new PointD(projLow.X, canvasRect.Top); var dashStyle = proj.AckDegree == 1 ? DashStyle.Dash : DashStyle.Solid; var pen = penStorage.GetPen(proj.Color, 1, dashStyle); g.DrawLine(pen, (float)projLow.X, (float)projLow.Y, (float)projHigh.X, (float)projHigh.Y); if (proj.AckDegree > 1) {// показать степень подтверждения const int textOffset = 37; const int textSize = 18, textSize2 = 9; g.FillEllipse(brushWhite, (float)projLow.X - textSize2, (float)projLow.Y - textOffset - textSize2, textSize, textSize); g.DrawEllipse(pen, (float)projLow.X - textSize2, (float)projLow.Y - textOffset - textSize2, textSize, textSize); var text = proj.AckDegree.ToString(); var textSz = g.MeasureString(text, Chart.Font); var textLeft = (float) projLow.X - textSz.Width/2; var textTop = (float) projLow.Y - textSz.Height/2 - textOffset; var brush = brushes.GetBrush(proj.Color); g.DrawString(text, font, brush, textLeft, textTop); textTop += (textSize + 4); var timeStr = Chart.StockSeries.GetCandleOpenTimeByIndex(proj.Index).ToString("dd MMM HH:ss"); textSz = g.MeasureString(timeStr, Chart.Font); textLeft = (float) projLow.X - textSz.Width/2; g.FillRectangle(brushWhite, textLeft - 2, textTop - 2, textSz.Width + 4, textSz.Height + 3); g.DrawRectangle(pen, textLeft - 2, textTop - 2, textSz.Width + 4, textSz.Height + 3); g.DrawString(timeStr, Chart.Font, brush, textLeft, textTop); } }
public void DrawProjection(Graphics g, RectangleD worldRect, Rectangle canvasRect, FiboSpanProjection proj, Brush brushWhite, Font font, PenStorage penStorage, BrushesStorage brushes) { // нижняя точка var projLow = Conversion.WorldToScreen(new PointD(proj.Index, 0), worldRect, canvasRect); projLow.Y = canvasRect.Bottom; // верхняя точка PointD projHigh = proj.UpperPrice.HasValue ? Conversion.WorldToScreen(new PointD(proj.Index, proj.UpperPrice.Value), worldRect, canvasRect) : new PointD(projLow.X, canvasRect.Top); var dashStyle = proj.AckDegree == 1 ? DashStyle.Dash : DashStyle.Solid; var pen = penStorage.GetPen(proj.Color, 1, dashStyle); g.DrawLine(pen, (float)projLow.X, (float)projLow.Y, (float)projHigh.X, (float)projHigh.Y); if (proj.AckDegree > 1) {// показать степень подтверждения const int textOffset = 37; const int textSize = 18, textSize2 = 9; g.FillEllipse(brushWhite, (float)projLow.X - textSize2, (float)projLow.Y - textOffset - textSize2, textSize, textSize); g.DrawEllipse(pen, (float)projLow.X - textSize2, (float)projLow.Y - textOffset - textSize2, textSize, textSize); var text = proj.AckDegree.ToString(); var textSz = g.MeasureString(text, Chart.Font); var textLeft = (float)projLow.X - textSz.Width / 2; var textTop = (float)projLow.Y - textSz.Height / 2 - textOffset; var brush = brushes.GetBrush(proj.Color); g.DrawString(text, font, brush, textLeft, textTop); textTop += (textSize + 4); var timeStr = Chart.StockSeries.GetCandleOpenTimeByIndex(proj.Index).ToString("dd MMM HH:ss"); textSz = g.MeasureString(timeStr, Chart.Font); textLeft = (float)projLow.X - textSz.Width / 2; g.FillRectangle(brushWhite, textLeft - 2, textTop - 2, textSz.Width + 4, textSz.Height + 3); g.DrawRectangle(pen, textLeft - 2, textTop - 2, textSz.Width + 4, textSz.Height + 3); g.DrawString(timeStr, Chart.Font, brush, textLeft, textTop); } }