public void AddExponentialMovingAverage(ChartStyle cs) { foreach (DataSeriesMA ds in DataList) { ds.EMALineSeries.Stroke = ds.EMALineColor; ds.EMALineSeries.StrokeThickness = ds.EMALineThickness; double[] data = ds.ExponentialMovingAverage(); ds.EMALineSeries.Points.Clear(); for (int i = 0; i < data.Length; i++) { ds.EMALineSeries.Points.Add(cs.NormalizePoint(new Point(i + ds.NDays - 1, data[i]))); } cs.ChartCanvas.Children.Add(ds.EMALineSeries); } }
private void AddChart() { if (dc.DataList.Count > 0) { cs = new ChartStyle(); cs.ChartCanvas = chartCanvas; cs.TextCanvas = textCanvas; cs.Xmin = -1; cs.Xmax = ds.DataString.GetLength(1); cs.XTick = 3; cs.Ymin = double.Parse(txYmin.Text); cs.Ymax = double.Parse(txYmax.Text); cs.YTick = double.Parse(txYTick.Text); cs.Title = "Stock Chart"; cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel, ds); dc.StockChartType = DataCollection.StockChartTypeEnum.HiLo; dc.AddStockChart(cs); } }
public void AddStockChart(ChartStyle cs) { foreach (DataSeries ds in DataList) { double barWidth = cs.ChartCanvas.Width / (5 * ds.DataString.GetLength(1)); double d0 = cs.DateToDouble(ds.DataString[0, 0]); double d1 = cs.DateToDouble(ds.DataString[0, 1]); double[,] stockData = new double[ds.DataString.GetLength(0), ds.DataString.GetLength(1)]; for (int i = 0; i < ds.DataString.GetLength(1); i++) { for (int j = 1; j < stockData.GetLength(0); j++) { if (d0 > d1) { stockData[j, i] = Convert.ToDouble(ds.DataString[j, ds.DataString.GetLength(1) - 1 - i]); } else { stockData[j, i] = Convert.ToDouble(ds.DataString[j, i]); } } } for (int i = 0; i < ds.DataString.GetLength(1); i++) { Point ptHigh = cs.NormalizePoint(new Point(i, stockData[2, i])); Point ptLow = cs.NormalizePoint(new Point(i, stockData[3, i])); Point ptOpen = cs.NormalizePoint(new Point(i, stockData[1, i])); Point ptClose = cs.NormalizePoint(new Point(i, stockData[4, i])); Point ptOpen1 = new Point(ptOpen.X - barWidth, ptOpen.Y); Point ptClose1 = new Point(ptClose.X + barWidth, ptClose.Y); Point ptOpen2 = new Point(ptOpen.X + barWidth, ptOpen.Y); Point ptClose2 = new Point(ptClose.X - barWidth, ptClose.Y); switch (StockChartType) { case StockChartTypeEnum.Line: // Draw Line stock chart: if (i > 0) { Point pt1 = cs.NormalizePoint(new Point(i - 1, stockData[4, i - 1])); Point pt2 = cs.NormalizePoint(new Point(i, stockData[4, i])); DrawLine(cs.ChartCanvas, pt1, pt2, ds.LineColor, ds.LineThickness); } break; case StockChartTypeEnum.HiLo: // Draw Hi-Lo stock chart: DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness); break; case StockChartTypeEnum.HiLoOpenClose: // Draw Hi-Lo-Open-Close stock chart: DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness); DrawLine(cs.ChartCanvas, ptOpen, ptOpen1, ds.LineColor, ds.LineThickness); DrawLine(cs.ChartCanvas, ptClose, ptClose1, ds.LineColor, ds.LineThickness); break; case StockChartTypeEnum.Candle: // Draw candle stock chart: DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness); Polygon plg = new Polygon(); plg.Stroke = ds.LineColor; plg.StrokeThickness = ds.LineThickness; Brush fillColor = ds.FillColor; if (stockData[1, i] < stockData[4, i]) { fillColor = Brushes.White; } plg.Fill = fillColor; plg.Points.Add(ptOpen1); plg.Points.Add(ptOpen2); plg.Points.Add(ptClose1); plg.Points.Add(ptClose2); cs.ChartCanvas.Children.Add(plg); break; } } } }