/// <summary> /// 计算指标 /// </summary> /// <param name="id">指标ID</param> /// <param name="code">代码</param> /// <param name="path">路径</param> /// <param name="type">类型</param> /// <param name="cycle">周期</param> /// <param name="subscription">复权方式</param> /// <param name="date">日期</param> /// <param name="open">开盘价</param> /// <param name="high">最高价</param> /// <param name="low">最低价</param> /// <param name="close">收盘价</param> /// <param name="volume">成交量</param> /// <param name="amount">成交额</param> /// <returns>返回数据</returns> public static double[] calculateIndicatorExtern(int id, String code, ref double result) { if (m_indicators.ContainsKey(id)) { FCScript indicator = m_indicators[id]; List <FCScript> indicators = new List <FCScript>(); indicators.Add(indicator); List <SecurityData> datas = new List <SecurityData>(); if (SecurityService.m_historyDatas.ContainsKey(code)) { datas = SecurityService.m_historyDatas[code]; SecurityLatestData latestData = null; if (SecurityService.m_latestDatas.ContainsKey(code)) { latestData = SecurityService.m_latestDatas[code]; } if (latestData != null) { SecurityData newData = new SecurityData(); getSecurityData(latestData, latestData.m_lastClose, 1440, 0, ref newData); if (datas.Count == 0) { datas.Add(newData); } else { if (newData.m_date > datas[datas.Count - 1].m_date) { datas.Add(newData); } else { datas[datas.Count - 1] = newData; } } } FCDataTable 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);; int rowsCount = dataSource.RowsCount; int variablesSize = indicator.MainVariables.Count; double[] list = new double[variablesSize]; if (rowsCount > 0) { int pos = 0; foreach (String name in indicator.MainVariables.Keys) { int field = indicator.MainVariables[name]; double value = dataSource.get2(rowsCount - 1, field); list[pos] = value; pos++; } } result = indicator.m_result; dataSource.clear(); return(list); } } return(null); }
/// <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(FCChart chart, FCDataTable dataSource, List <FCScript> 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); } }