public static void BindHistoryVolAndAmountDatas(ChartAEx chart, CTable dataSource, int[] fields, List <SecurityData> historyDatas) { dataSource.Clear(); int size = (int)historyDatas.Count;; dataSource.SetRowsCapacity(size + 10); dataSource.SetRowsGrowStep(100); int columnsCount = dataSource.ColumnsCount; for (int i = 0; i < size; i++) { SecurityData securityData = historyDatas[i]; double[] ary = new double[columnsCount]; ary[0] = securityData.m_volume; ary[1] = securityData.m_amount; dataSource.AddRow((double)securityData.m_date, ary, columnsCount); } }
/// <summary> /// 计算指标 /// </summary> /// <param name="id">指标ID</param> /// <param name="code">代码</param> /// <returns>返回数据</returns> public static Dictionary <String, double> CalculateIndicatorExtern(int id, String code) { Dictionary <String, double> list = new Dictionary <String, double>(); if (m_indicators.ContainsKey(id) && SecurityService.m_historyDatas.ContainsKey(code) && SecurityService.m_latestDatas.ContainsKey(code)) { CIndicator indicator = m_indicators[id]; List <CIndicator> indicators = new List <CIndicator>(); indicators.Add(indicator); List <SecurityData> datas = new List <SecurityData>(); List <SecurityData> oldSecurityDatas = SecurityService.m_historyDatas[code]; int oldSecurityDatasSize = oldSecurityDatas.Count; for (int i = 0; i < oldSecurityDatasSize; i++) { datas.Add(oldSecurityDatas[i]); } SecurityLatestData latestData = SecurityService.m_latestDatas[code]; SecurityData newData = new SecurityData(); StockService.GetSecurityData(latestData, latestData.m_lastClose, 1440, 1, ref newData); datas.Add(newData); CTable dataSource = indicator.DataSource; int[] fields = new int[] { KeyFields.CLOSE_INDEX, KeyFields.HIGH_INDEX, KeyFields.LOW_INDEX, KeyFields.OPEN_INDEX, KeyFields.VOL_INDEX, KeyFields.AMOUNT_INDEX }; SecurityDataHelper.BindHistoryDatas(m_chart, dataSource, indicators, fields, datas); datas.Clear(); int rowsCount = dataSource.RowsCount; int variablesSize = indicator.MainVariables.Count; if (rowsCount > 0) { foreach (String name in indicator.MainVariables.Keys) { int field = indicator.MainVariables[name]; double value = dataSource.Get2(rowsCount - 1, field); list[name] = value; } } dataSource.Clear(); } return(list); }
public static void BindHistoryDatas(ChartAEx chart, CTable dataSource, List <CIndicator> indicators, int[] fields, List <SecurityData> historyDatas) { dataSource.Clear(); int sizeData = (int)historyDatas.Count; if (sizeData > 0) { dataSource.SetRowsCapacity(sizeData + 10); dataSource.SetRowsGrowStep(100); int columnsCount = dataSource.ColumnsCount; for (int i = 0; i < sizeData; i++) { SecurityData securityData = historyDatas[i]; if (dataSource == chart.DataSource) { if (securityData.m_close > 0) { InsertData(chart, dataSource, fields, securityData); } } else { double[] ary = new double[columnsCount]; ary[0] = securityData.m_close; ary[1] = securityData.m_high; ary[2] = securityData.m_low; ary[3] = securityData.m_open; ary[4] = securityData.m_volume; ary[5] = securityData.m_amount; ary[6] = securityData.m_avgPrice; dataSource.AddRow((double)securityData.m_date, ary, columnsCount); } } int indicatorsSize = (int)indicators.Count; for (int i = 0; i < indicatorsSize; i++) { indicators[i].OnCalculate(0); } } }
/// <summary> /// 绑定历史数据 /// </summary> /// <param name="chart">股票控件</param> /// <param name="dataSource">数据源</param> /// <param name="indicators">指标</param> /// <param name="fields">字段</param> /// <param name="historyDatas">历史数据</param> public static void BindHistoryDatas(ChartA chart, CTable dataSource, List <CIndicator> indicators, int[] fields, List <SecurityData> historyDatas) { dataSource.Clear(); int size = historyDatas.Count; dataSource.SetRowsCapacity(size + 10); dataSource.SetRowsGrowStep(100); int columnsCount = dataSource.ColumnsCount; for (int i = 0; i < size; i++) { SecurityData securityData = historyDatas[i]; if (dataSource == chart.DataSource) { InsertData(chart, dataSource, fields, securityData); } else { double[] ary = new double[columnsCount]; ary[0] = securityData.m_close; ary[1] = securityData.m_high; ary[2] = securityData.m_low; ary[3] = securityData.m_open; ary[4] = securityData.m_volume; for (int j = 5; j < columnsCount; j++) { ary[j] = double.NaN; } dataSource.AddRow(securityData.m_date, ary, columnsCount); } } int indicatorsSize = indicators.Count; for (int i = 0; i < indicatorsSize; i++) { indicators[i].OnCalculate(0); } }