/// <summary> /// 创建指标 /// </summary> /// <param name="text">脚本</param> /// <param name="parameters">参数</param> /// <returns>指标ID</returns> public static int CreateIndicatorExtern(String text, String parameters) { try { if (m_native == null) { m_native = NativeHandler.CreateNative(); } if (m_chart == null) { m_chart = new ChartAEx(); m_chart.Native = m_native; } m_serialNumber++; CTable dataSource = m_chart.Native.CreateTable(); dataSource.AddColumn(KeyFields.CLOSE_INDEX); dataSource.AddColumn(KeyFields.HIGH_INDEX); dataSource.AddColumn(KeyFields.LOW_INDEX); dataSource.AddColumn(KeyFields.OPEN_INDEX); dataSource.AddColumn(KeyFields.VOL_INDEX); dataSource.AddColumn(KeyFields.AMOUNT_INDEX); CIndicator indicator = SecurityDataHelper.CreateIndicator(m_chart, dataSource, text, parameters); m_indicators[m_serialNumber] = indicator; indicator.OnCalculate(0); } catch (Exception ex) { Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace); } return(m_serialNumber); }
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); } }
public static void InsertLatestData(ChartAEx chart, CTable dataSource, List <CIndicator> indicators, int [] fields, double preClose, int lastIndex) { for (int i = 0; i < lastIndex; i++) { double close = dataSource.Get2(i, fields[KeyFields.CLOSE_INDEX]); if (double.IsNaN(close)) { dataSource.Set2(i, fields[KeyFields.CLOSE_INDEX], preClose); dataSource.Set2(i, fields[KeyFields.OPEN_INDEX], preClose); dataSource.Set2(i, fields[KeyFields.HIGH_INDEX], preClose); dataSource.Set2(i, fields[KeyFields.LOW_INDEX], preClose); dataSource.Set2(i, fields[KeyFields.VOL_INDEX], 0); dataSource.Set2(i, fields[KeyFields.AMOUNT_INDEX], 0); dataSource.Set2(i, fields[KeyFields.AVGPRICE_INDEX], preClose); } else { preClose = close; } } }
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); } } }