private void FillData() { DateTime startDate = _StockDrawer.MinDate; while (startDate < _StockDrawer.MaxDate) { StockPoint pt = _StockDrawer.GetAt(startDate); if (pt != null) { int curIdx = chart1.Series["Price"].Points.AddXY(startDate, pt.High); chart1.Series["Price"].Points[curIdx].YValues[1] = pt.Low; chart1.Series["Price"].Points[curIdx].YValues[2] = pt.Open; chart1.Series["Price"].Points[curIdx].YValues[3] = pt.End; } startDate = startDate.AddDays(1); while (Holidays.IsWeekend(startDate)) { startDate = startDate.AddDays(1); } } chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "5", chart1.Series["Price"], chart1.Series["PriceMA5"]); chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "10", chart1.Series["Price"], chart1.Series["PriceMA10"]); chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "20", chart1.Series["Price"], chart1.Series["PriceMA20"]); }
/* * private StockMeta BuildStockObject(JToken meta) * { * StockMeta result = new StockMeta(); * result.Infomation = meta[Constant.INFORMATION].ToString(); * result.Date = meta[Constant.DATE].ToString(); * result.Symbol = meta[Constant.SYMBOL].ToString(); * return result; * } */ /// <summary> /// Based on the original json data, we build the stockMeta object data points. This will be the datasource for the later on drawing /// </summary> /// <param name="result"></param> /// <param name="data"></param> /// <param name="SMA_10"></param> /// <param name="SMA_50"></param> /// <param name="SMA_200"></param> /// <param name="Type"></param> private void AddStockMajorDataToStockObject(ref StockMeta result, JObject data, JObject SMA_10, JObject SMA_50, JObject SMA_200, string Type) { var meta = data[Constant.METADATA]; List <StockPoint> points = new List <StockPoint>(); var dataPoints = data[Type]; IEnumerable <JProperty> dataPoints_SMA_10 = new JObject().OfType <JProperty>(); IEnumerable <JProperty> dataPoints_SMA_50 = new JObject().OfType <JProperty>(); IEnumerable <JProperty> dataPoints_SMA_200 = new JObject().OfType <JProperty>(); if (_memuSetting.ChartSettings["SMA10"]) { dataPoints_SMA_10 = SMA_10[Constant.SMAKEY].OfType <JProperty>(); } if (_memuSetting.ChartSettings["SMA50"]) { dataPoints_SMA_50 = SMA_50[Constant.SMAKEY].OfType <JProperty>(); } if (_memuSetting.ChartSettings["SMA200"]) { dataPoints_SMA_200 = SMA_200[Constant.SMAKEY].OfType <JProperty>(); } int i = 0; ///for current stage, just hard coded 100 points foreach (JProperty point in dataPoints.OfType <JProperty>()) { StockPoint tmp = new StockPoint(); tmp.Date = point.Name.ToString(); tmp.OpenPrice = GeneralTools.StringParser(point.Value[Constant.OPENPRICE].ToString()); tmp.ClosePrice = GeneralTools.StringParser(point.Value[Constant.CLOSEPRICE].ToString()); tmp.HighPrice = GeneralTools.StringParser(point.Value[Constant.HIGHPRICE].ToString()); tmp.LowPrice = GeneralTools.StringParser(point.Value[Constant.LOWPRICE].ToString()); tmp.Volume = Int32.Parse(point.Value[Constant.VOLUME].ToString()); if (_memuSetting.ChartSettings["SMA10"]) { tmp.SMA_10 = ParseValue("", dataPoints_SMA_10, Constant.SMA, i, 1); } if (_memuSetting.ChartSettings["SMA50"]) { tmp.SMA_50 = ParseValue("", dataPoints_SMA_50, Constant.SMA, i, 1); } if (_memuSetting.ChartSettings["SMA200"]) { tmp.SMA_200 = ParseValue("", dataPoints_SMA_200, Constant.SMA, i, 1); } points.Add(tmp); i++; if (i >= 100) { break; } } result.Infomation = meta[Constant.INFORMATION].ToString(); result.Date = meta[Constant.DATE].ToString(); result.Symbol = meta[Constant.SYMBOL].ToString(); result.Charts[Constant.ChartMapper[Type]] = points; }
private void FillData() { DateTime startDate = _StockDrawer.MinDate; double minYValue = Double.MaxValue; while (startDate < _StockDrawer.MaxDate) { StockPoint pt = _StockDrawer.GetAt(startDate); if (pt != null) { int curIdx = chart1.Series["Price"].Points.AddXY(startDate, pt.High); chart1.Series["Volume"].Points.AddXY(startDate, pt.Volume); chart1.Series["Price"].Points[curIdx].YValues[1] = pt.Low; chart1.Series["Price"].Points[curIdx].YValues[2] = pt.Open; chart1.Series["Price"].Points[curIdx].YValues[3] = pt.End; minYValue = (minYValue > pt.Low) ? pt.Low : minYValue; } startDate = startDate.AddDays(1); while (Holidays.IsWeekend(startDate)) { startDate = startDate.AddDays(1); } } if (minYValue != Double.MaxValue) { chart1.ChartAreas["Price"].AxisY.Minimum = (int)minYValue - 1; // 最小值设置 } chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "5", chart1.Series["Price"], chart1.Series["PriceMA5"]); chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "10", chart1.Series["Price"], chart1.Series["PriceMA10"]); chart1.DataManipulator.FinancialFormula(FinancialFormula.MovingAverage, "20", chart1.Series["Price"], chart1.Series["PriceMA20"]); }
private void AddStockMajorDataToStockSummary(ref StockSummary result) { string req = GeneralTools.NetworkRequestStringBuilder(result.Symbol, Constant.DAILY, Constant.QUERY_FUNCTION_VALUE_DAILY, string.Empty, string.Empty, _apiKey[0]); var stockData = OriginalStockData(req); var dataPoints = stockData[Constant.DAILYCHART]; List <StockPoint> points = new List <StockPoint>(); foreach (JProperty point in dataPoints.OfType <JProperty>()) { StockPoint tmp = new StockPoint(); tmp.Date = point.Name.ToString(); tmp.OpenPrice = GeneralTools.StringParser(point.Value[Constant.OPENPRICE].ToString()); tmp.ClosePrice = GeneralTools.StringParser(point.Value[Constant.CLOSEPRICE].ToString()); tmp.HighPrice = GeneralTools.StringParser(point.Value[Constant.HIGHPRICE].ToString()); tmp.LowPrice = GeneralTools.StringParser(point.Value[Constant.LOWPRICE].ToString()); tmp.Volume = Int32.Parse(point.Value[Constant.VOLUME].ToString()); points.Add(tmp); } result.CacheData.Add(Constant.DAILYCHART, points); }