private void buttonGo_Click(object sender, EventArgs e) { string[] symbols = textBoxSymbols.Text.Split(','); List <Trading.Company> list = new List <Trading.Company>(); Trading.IEXData.HistoryType ht = Trading.IEXData.HistoryType.OneYear; if (comboBoxDuration.SelectedIndex == 0) { ht = Trading.IEXData.HistoryType.OneYear; } if (comboBoxDuration.SelectedIndex == 1) { ht = Trading.IEXData.HistoryType.TwoYear; } if (comboBoxDuration.SelectedIndex == 2) { ht = Trading.IEXData.HistoryType.FiveYear; } foreach (string sym in symbols) { Trading.Company c = Trading.IEXData.DownloadSymbol(sym, ht); list.Add(c); Color[] colors = new Color[list.Count]; Random r = new Random(); for (int i = 0; i < list.Count; i++) { colors[i] = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256)); } DrawPriceChart(list, colors); DrawVolumeChart(list[0]); } }
private void DrawPriceChart(Trading.Company c, Color color) { List <Trading.Company> cList = new List <Company>(); cList.Add(c); Color[] colors = new Color[1]; colors[0] = color; DrawPriceChart(cList, colors); }
private void DrawPriceChart(List <Trading.Company> list, Color[] colors) { ChartArea area = new ChartArea("0"); for (int i = 0; i < list.Count; i++) { Trading.Company c = list[i]; //Close price Series s = new Series(c.Symbol + " Close Price"); s.ChartType = SeriesChartType.Line; s.Color = colors[i]; s.ChartArea = "0"; s.XValueType = ChartValueType.DateTime; for (int j = 0; j < c.Count; j++) { DateTime date = DateTime.Parse(c.label[j]); float val = c.close[j]; s.Points.AddXY(date, val); } chartValue.Series.Add(s); //MovingAverageClose price Series maClose = new Series(c.Symbol + " MA Close Price"); maClose.ChartType = SeriesChartType.Line; maClose.BorderDashStyle = ChartDashStyle.Dot; maClose.Color = colors[i]; maClose.ChartArea = "0"; maClose.XValueType = ChartValueType.DateTime; for (int j = 0; j < c.Count; j++) { DateTime date = DateTime.Parse(c.label[j]); float val = c.MovingAverageClose[j]; maClose.Points.AddXY(date, val); } chartValue.Series.Add(maClose); } chartValue.Show(); chartValue.ChartAreas[0].AxisX.ScaleView.ZoomReset(); chartValue.ChartAreas[0].AxisY.ScaleView.ZoomReset(); }
private void DrawVolumeChart(Trading.Company c) { //Volume Series s = new Series(c.Symbol + " Volume"); s.ChartType = SeriesChartType.Column; s.ChartArea = "0"; s.XValueType = ChartValueType.DateTime; for (int i = 0; i < c.Count; i++) { DateTime date = DateTime.Parse(c.label[i]); float val = c.volume[i]; s.Points.AddXY(date, val); } s["PixelPointWidth"] = "1"; chartVolume.Series.Add(s); //MovingAverageVolume Series maVol = new Series(c.Symbol + " MA Volume"); maVol.ChartType = SeriesChartType.Line; maVol.BorderDashStyle = ChartDashStyle.Solid; maVol.ChartArea = "0"; maVol.XValueType = ChartValueType.DateTime; for (int i = 0; i < c.Count; i++) { DateTime date = DateTime.Parse(c.label[i]); float val = c.MovingAverageVolume[i]; maVol.Points.AddXY(date, val); } chartVolume.Series.Add(maVol); chartVolume.ChartAreas[0].AxisX.ScaleView.ZoomReset(); chartVolume.ChartAreas[0].AxisY.ScaleView.ZoomReset(); }