void LoadData() { List <int> intevals = new List <int>(); intevals.Add(300); LiveDataProcessor ldpa = new LiveDataProcessor(intevals, _si); ldpa.OnLiveBarArrival += ldpa_OnLiveBarArrival; if (true) { DateTime startTime = sidate.Date.AddHours(-8); DateTime endTime = sidate.Date.AddHours(16); string sql = string.Format("select * from ideal_tick_mstr where tick_code = '{0}' and tick_time >= '{1}' and tick_time < '{2}' order by tick_time asc", _si.Code, startTime, endTime); DataTable dt = null; //DataTable dt = LocalSQL.QueryDataTable(sql); if (dt.Rows.Count == 0) { //提示 MessageBox.Show("无历史纪录"); //返回 return; } else { DataRow dr = dt.Rows[dt.Rows.Count - 1]; //传递数据 this.th = new TickHistory(); th.code = _si.Code; th.datetime = sidate; th.lists = dt; th.lastclose = System.Convert.ToDouble(dt.Rows[0]["tick_last"]); th.high = System.Convert.ToDouble(dr["tick_high"]); th.low = System.Convert.ToDouble(dr["tick_low"]); if (Math.Abs(th.lastclose - th.high) > Math.Abs(th.lastclose - th.low)) { th.low = th.lastclose - (th.high - th.lastclose); } else { th.high = th.lastclose + (th.lastclose - th.low); } th.ticks = new SortedDictionary <TimeSpan, TickData>(); foreach (DataRow row in dt.Rows) { TickData td = TickData.ConvertFromDataRow(row); td.Time = td.Time.AddHours(8); if (_si.isLive(td.Time.TimeOfDay))// SecurityMarket.isLive(td.Time.TimeOfDay)) { ldpa.ReceiveTick(td); //dataAnalisys.ReceiveTick(td); } try { th.ticks.Add(td.Time.TimeOfDay, td); } catch { } } tickHistorys.Add(th); dataget = true; //updateChartTickX(dt); } SeriesRowColumn = new Series(); SeriesRowColumn.Name = "PointSerial"; //不显示chart控件中的右上角提示的内容 SeriesRowColumn.IsVisibleInLegend = false; //preCloseSeries.IsVisibleInLegend = false; foreach (var x in th.ticks) { DataPoint dp = new DataPoint(); dp.SetValueXY(x.Key.ToString(), x.Value.Last); SeriesRowColumn.Points.Add(dp); } //绘画一个折线图 SeriesRowColumn.ChartType = SeriesChartType.Line; LiveBars bar1M = ldpa.Bar1M; LiveBars bar5M = ldpa.Bar5M; #region 分时数据 try { SeriesFenShiColumn = new Series(); //取消chart控件中右上角的标志 SeriesFenShiColumn.IsVisibleInLegend = false; //定义一个双精度浮点型最大值为0 FenShiMax = 0; //定义一个双精度浮点型最小值为1000 FenShiMin = 10000; double last = 0; int lastindex = -1; List <TimeSpan> ts = new List <TimeSpan>(bar1M.Bars.Keys); for (int i = ts.Count - 1; i >= 0; i--) { double close = bar1M.Bars[ts[i]].Close; if (close != 0) { lastindex = i; break; } } if (lastindex == -1) { return; } int line = 0; foreach (var bar in bar1M.Bars) { if (line >= lastindex) { break; } double close = bar.Value.Close; if (close == 0 && last == 0) { close = ldpa.LastClose; } else if (close == 0 && last != 0) { close = last; } else { last = close; } string time = bar.Key.ToString().Substring(0, 5); DataPoint dp = new DataPoint(); dp.SetValueXY(line, close); dp.AxisLabel = time; SeriesFenShiColumn.Points.Add(dp); if (FenShiMax < close) { FenShiMax = close; } if (FenShiMin > close) { FenShiMin = close; } line++; } //绘画出一个折线图 SeriesFenShiColumn.ChartType = SeriesChartType.Line; SeriesFenShiColumn.Color = Color.Blue; } catch { } #endregion #region 1分钟数据 try { Series1Column = new Series("Bar"); Series1Column.IsVisibleInLegend = false; OneMax = 0; OneMin = 10000; int line = 0; double last = 0; int lastindex = -1; List <TimeSpan> ts = new List <TimeSpan>(bar1M.Bars.Keys); for (int i = ts.Count - 1; i >= 0; i--) { double close = bar1M.Bars[ts[i]].Close; if (close != 0) { lastindex = i; break; } } if (lastindex == -1) { return; } Series1Column.ChartType = SeriesChartType.Candlestick; Series1Column["OpenCloseStyle"] = "Triangle"; Series1Column["ShowOpenClose"] = "Both"; Series1Column["PointWdith"] = "0.2"; //SeriesColumn.Color = Color.Red; Series1Column["PriceUpColor"] = "Red"; Series1Column["PriceDownColor"] = "Green"; foreach (var bar in bar1M.Bars) { if (line > lastindex) { break; } double close = bar.Value.Close; double high = 0; double open = 0; double low = 0; if (close == 0 && last == 0) { close = ldpa.LastClose; high = close; open = close; low = close; } else if (close == 0 && last != 0) { close = last; high = last; open = last; low = last; } else { close = bar.Value.Close; open = bar.Value.Open; high = bar.Value.High; low = bar.Value.Low; last = close; } if (high > OneMax) { OneMax = high; } if (low < OneMin) { OneMin = low; } string time = bar.Key.ToString().Substring(0, 5); Series1Column.YValuesPerPoint = 4; Series1Column.Points.AddXY(line, high); Series1Column.Points[line].YValues[1] = low; Series1Column.Points[line].YValues[2] = open; Series1Column.Points[line].YValues[3] = close; if (close > open) { Series1Column.Points[line].Color = Color.Red; } else if (close < open) { Series1Column.Points[line].Color = Color.Green;//.Blue;//.FromName("#54FFFF"); } else { Series1Column.Points[line].Color = Color.Black; } Series1Column.Points[line].AxisLabel = time; Series1Column.Points[line].ToolTip = string.Format("{0}\n高:{1}\n开:{2}\n低:{3}\n收:{4}\n量:{5}\n均5:{6}\n均10{7}\n类{8}", time, high, open, low, close, bar.Value.Volumn, "Ev5", "Ev10", Enum.GetName(typeof(BarType), bar.Value.RelativeRaiseType)); line++; } } catch (Exception e) { MessageBox.Show(System.Convert.ToString(e)); } #endregion #region 5分钟数据 try { Series5Column = new Series("Bar"); Series5Column.IsVisibleInLegend = false; FiveMax = 0; FiveMin = 10000; int line = 0; double last = 0; int lastindex = -1; List <TimeSpan> ts = new List <TimeSpan>(bar5M.Bars.Keys); for (int i = ts.Count - 1; i >= 0; i--) { double close = bar5M.Bars[ts[i]].Close; if (close != 0) { lastindex = i; break; } } if (lastindex == -1) { return; } Series5Column.ChartType = SeriesChartType.Candlestick; Series5Column["OpenCloseStyle"] = "Triangle"; Series5Column["ShowOpenClose"] = "Both"; Series5Column["PointWdith"] = "0.2"; //SeriesColumn.Color = Color.Red; Series5Column["PriceUpColor"] = "Red"; Series5Column["PriceDownColor"] = "Green"; foreach (var bar in bar5M.Bars) { if (line > lastindex) { break; } double close = bar.Value.Close; double high = 0; double open = 0; double low = 0; if (close == 0 && last == 0) { close = ldpa.LastClose; high = close; open = close; low = close; } else if (close == 0 && last != 0) { close = last; high = last; open = last; low = last; } else { close = bar.Value.Close; open = bar.Value.Open; high = bar.Value.High; low = bar.Value.Low; last = close; } if (high > FiveMax) { FiveMax = high; } if (low < FiveMin) { FiveMin = low; } string time = bar.Key.ToString().Substring(0, 5); Series5Column.YValuesPerPoint = 4; Series5Column.Points.AddXY(line, high); Series5Column.Points[line].YValues[1] = low; Series5Column.Points[line].YValues[2] = open; Series5Column.Points[line].YValues[3] = close; if (close > open) { Series5Column.Points[line].Color = Color.Red; } else if (close < open) { Series5Column.Points[line].Color = Color.Green;//.Blue;//.FromName("#54FFFF"); } else { Series5Column.Points[line].Color = Color.Black; } Series5Column.Points[line].AxisLabel = time; Series5Column.Points[line].ToolTip = string.Format("{0}\n高:{1}\n开:{2}\n低:{3}\n收:{4}\n量:{5}\n均5:{6}\n均10{7}\n类{8}", time, high, open, low, close, bar.Value.Volumn, "Ev5", "Ev10", Enum.GetName(typeof(BarType), bar.Value.RelativeRaiseType)); line++; } } catch (Exception e) { MessageBox.Show(System.Convert.ToString(e)); } #endregion UpdateChart(ldpa); } }
public LiveShowData(LiveBars bar1M, double lastClose, RiscPoints riscpoints) { this._bar1M = bar1M; this._lastClose = lastClose; this._riscPoints = riscpoints; }