public Form1() { myTimer = new System.Windows.Forms.Timer(); myTimer.Tick += new EventHandler(myTimer_Callback); InitializeComponent(); play_state = false; my_instrument_data = new instrument_data(); mytrades = new trades_all(); mytrade = new trades_s(); cd = new candle_data(); pos = 0; comboBox1.Items.Add("1秒1根"); comboBox1.Items.Add("2秒1根"); comboBox1.Items.Add("2.5秒1根"); comboBox1.SelectedIndex = 1; changeplaystate(play_state); //reset_timer(); }
private void init_candle() { if (my_instrument_data.candle_series.Count > min_candle_numbs) { chart1.Series.Clear(); Series price = new Series("price"); //Series volumn = new Series("volumn"); price.IsXValueIndexed = true; //volumn.IsXValueIndexed = true; chart1.Series.Add(price); //chart1.Series.Add(volumn); chart1.Series["price"].ChartArea = "ChartArea1"; //chart1.Series["volumn"].ChartArea = "ChartArea2"; chart1.Series["price"].ChartType = SeriesChartType.Candlestick; //chart1.Series["volumn"].ChartType = SeriesChartType.Column; // Set point width chart1.Series["price"]["PointWidth"] = "1.0"; chart1.Series["price"]["PriceUpColor"] = "Red"; chart1.Series["price"]["PriceDownColor"] = "Green"; chart1.Series["price"].XValueType = ChartValueType.DateTime; //chart1.Series["volumn"].XValueType = ChartValueType.DateTime; chart1.ChartAreas[0].AxisX.LabelStyle.Format = "yyyy/MM/dd"; //chart1.ChartAreas[1].AxisX.LabelStyle.Format = "yyyy/MM/dd"; chart1.ChartAreas[0].AxisY.IsStartedFromZero = false; //此为解决Y轴自适应 //chart1.ChartAreas[1].AxisY.IsStartedFromZero = false; //此为解决Y轴自适应 //Random r = new Random(); //int maxv = my_instrument_data.candle_series.Count - b_candle_numbs - f_candle_numbs; //int minv = f_candle_numbs; //my_instrument_data.price_pos = r.Next( minv + (int)((maxv-minv)*0.7), maxv); //for ints for (int i = 0; i < f_candle_numbs; i++) { cd = (candle_data)my_instrument_data.candle_series[my_instrument_data.price_pos]; // adding date and high chart1.Series["price"].Points.AddXY(cd.dt, cd.high); // adding low chart1.Series["price"].Points[my_instrument_data.chart_pos].YValues[1] = cd.low; //adding open chart1.Series["price"].Points[my_instrument_data.chart_pos].YValues[2] = cd.open; // adding close chart1.Series["price"].Points[my_instrument_data.chart_pos].YValues[3] = cd.close; //chart1.Series["volumn"].Points.AddXY(cd.dt, cd.v); //if (cd.open < cd.close) // chart1.Series["volumn"].Points[my_instrument_data.chart_pos].Color = Color.Red; //else // chart1.Series["volumn"].Points[my_instrument_data.chart_pos].Color = Color.Green; my_instrument_data.price_pos++; my_instrument_data.chart_pos++; } } else { tool_status.Text = "init_draw, 数据量不够,最少 " + min_candle_numbs; } //draw_one(); }
private void draw_one() { if (my_instrument_data.candle_series.Count < min_candle_numbs) { tool_status.Text = "draw_one, 数据量不够,最少 " + min_candle_numbs; return; } if (my_instrument_data.candle_series.Count == my_instrument_data.price_pos) { tool_status.Text = "draw_one, 已经到达最后一根k线"; return; } cd = (candle_data)my_instrument_data.candle_series[my_instrument_data.price_pos]; // adding date and high pos = chart1.Series["price"].Points.AddXY(cd.dt, cd.high); // adding low chart1.Series["price"].Points[my_instrument_data.chart_pos].YValues[1] = cd.low; //adding open chart1.Series["price"].Points[my_instrument_data.chart_pos].YValues[2] = cd.open; // adding close chart1.Series["price"].Points[my_instrument_data.chart_pos].YValues[3] = cd.close; chart1.Series["price"].LegendText = String.Format("价格:{0}\n成交:{1}", cd.close, cd.v); //chart1.Series["price"].Label = ""; //chart1.Series["price"].Points[my_instrument_data.chart_pos].Label = "asdf"; //chart1.Series["volumn"].Points.AddXY(cd.dt, cd.v); //if (cd.open < cd.close) // chart1.Series["volumn"].Points[my_instrument_data.chart_pos].Color = Color.Red; //else // chart1.Series["volumn"].Points[my_instrument_data.chart_pos].Color = Color.Green; Axis xaxis = chart1.ChartAreas[0].AxisX; xaxis.Minimum = xaxis.Maximum - f_candle_numbs; //xaxis = chart1.ChartAreas[1].AxisX; //xaxis.Minimum = xaxis.Maximum - f_candle_numbs; // Axis yaxis = chart1.ChartAreas[0].AxisY; double min_p, min_v; min_p = min_v = double.MaxValue; double max_p, max_v; max_p = max_v = double.MinValue; for (int i = 0; i < f_candle_numbs; i++) { var pcd = (candle_data)my_instrument_data.candle_series[my_instrument_data.price_pos - i]; min_p = Math.Min(pcd.low, min_p); min_v = Math.Min(pcd.v, min_v); max_p = Math.Max(pcd.high, max_p); max_v = Math.Max(pcd.v, max_v); } Axis yaxis = chart1.ChartAreas[0].AxisY; yaxis.Minimum = min_p - (max_p - min_p) * 0.05; yaxis.Maximum = max_p + (max_p - min_p) * 0.05; //yaxis = chart1.ChartAreas[1].AxisY; //yaxis.Minimum = min_v - (max_v - min_v);// * 0.05; //yaxis.Maximum = max_v + (max_v - min_v);// * 0.05; //chart1.Legends[0].Title = cd.close.ToString(); my_instrument_data.price_pos++; my_instrument_data.chart_pos++; }
public bool try_parse(string fn) { bool bflag = false; try { string[] lines = System.IO.File.ReadAllLines(fn); DateTime dt2 = new DateTime(2016, 1, 1, 0, 0, 0); ArrayList temp_candle = new ArrayList(); foreach (string line in lines) { string[] columns = line.Split(','); if (columns.Length >= 7) { // Do something // Console.WriteLine(columns); try { var cd = new candle_data(); if (DateTime.TryParseExact(columns[0].Substring(0, 19), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out cd.dt)) { timeframe = 10; } else if (DateTime.TryParseExact(columns[0].Substring(0, 19), "yyyy/MM/dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out cd.dt)) { timeframe = 20; } else { continue; } if (cd.dt < dt2) { continue; } cd.open = double.Parse(columns[1]); cd.high = double.Parse(columns[2]); cd.low = double.Parse(columns[3]); cd.close = double.Parse(columns[4]); cd.interest = int.Parse(columns[5]); cd.v = int.Parse(columns[6]); temp_candle.Add(cd); } catch (Exception ex) { Console.WriteLine(ex); } //Double.TryParse() } } Random r = new Random(); int temp_start = r.Next(0, Math.Max(0, temp_candle.Count - s_candle_numb)); int temp_end = Math.Min(temp_candle.Count, temp_start + s_candle_numb); if (temp_end > 0) { candle_series = temp_candle.GetRange(temp_start, temp_end - temp_start); price_pos = 0; } instrument_name = Path.GetFileNameWithoutExtension(fn); bflag = true; } catch (Exception ex) { Console.WriteLine(ex); } return(bflag); }