/// <summary> /// 创建指标 /// </summary> /// <param name="native">方法库</param> /// <param name="script">脚本</param> /// <param name="xml">XML</param> /// <returns>指标</returns> public static CIndicator CreateIndicator(string script, UIXml xml) { CIndicator indicator = xml.Native.CreateIndicator(); CTable table = xml.Native.CreateTable(); indicator.DataSource = table; CFunctionBase.AddFunctions(indicator); CFunctionUI.AddFunctions(indicator, xml); CFunctionWin.AddFunctions(indicator); CFunctionAjax.AddFunctions(indicator); int index = 1000000; string[] functions = FUNCTIONS.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); int functionsSize = functions.Length; for (int i = 0; i < functionsSize; i++) { indicator.AddFunction(new CFunctionEx(indicator, index + i, functions[i], xml)); } indicator.Script = script; table.AddColumn(0); table.Set(0, 0, 0); indicator.OnCalculate(0); return(indicator); }
/// <summary> /// 绑定图形 /// </summary> private void BindChart() { m_chartLevels.Clear(); CTable dataSource = m_chartLevels.DataSource; List <LevelInfo> levels = DataCenter.LevelService.m_levels; int levelsSize = levels.Count; for (int i = 0; i < levelsSize; i++) { if (levels[i].m_date.Length == 8) { int year = CStr.ConvertStrToInt(levels[i].m_date.Substring(0, 4)); int month = CStr.ConvertStrToInt(levels[i].m_date.Substring(4, 2)); int day = CStr.ConvertStrToInt(levels[i].m_date.Substring(6, 2)); DateTime dt = new DateTime(year, month, day); double pk = CStr.ConvertDateToNum(dt); dataSource.Set(pk, 0, CStr.ConvertStrToDouble(levels[i].m_level)); dataSource.Set2(i, 1, 10); dataSource.Set2(i, 2, 0); dataSource.Set2(i, 3, CStr.ConvertStrToDouble(levels[i].m_level2)); dataSource.Set2(i, 4, CStr.ConvertStrToDouble(levels[i].m_level3)); } } m_chartLevels.Update(); m_chartLevels.Invalidate(); }
/// <summary> /// 创建指标 /// </summary> /// <param name="id">编号</param> /// <param name="script">脚本</param> /// <param name="xml">XML</param> /// <returns>指标</returns> public static CIndicator CreateIndicator2(String id, ChatData chatData, UIXml xml) { CIndicator indicator = xml.Native.CreateIndicator(); indicator.Name = id; CTable table = xml.Native.CreateTable(); indicator.DataSource = table; indicator.Tag = chatData; CFunctionBase.AddFunctions(indicator); CFunctionUI.AddFunctions(indicator, xml); CFunctionWin.AddFunctions(indicator); int index = STARTINDEX; String[] functions = FUNCTIONS.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); int functionsSize = functions.Length; for (int i = 0; i < functionsSize; i++) { indicator.AddFunction(new CFunctionEx(indicator, index + i, functions[i], xml)); } indicator.Script = chatData.m_content; table.AddColumn(0); table.Set(0, 0, 0); indicator.OnCalculate(0); return(indicator); }
/// <summary> /// 绑定图形 /// </summary> private void BindChart() { m_chartLevels.Clear(); CTable dataSource = m_chartLevels.DataSource; List <DialogInfo> dialogs = DataCenter.DialogService.m_dialogs; Dictionary <String, int> dialogsMap = new Dictionary <String, int>(); int dialogsSize = dialogs.Count; for (int i = 0; i < dialogsSize; i++) { if (dialogs[i].m_date.Length == 8) { if (dialogsMap.ContainsKey(dialogs[i].m_date)) { dialogsMap[dialogs[i].m_date] = dialogsMap[dialogs[i].m_date] + 1; } else { dialogsMap[dialogs[i].m_date] = 1; } } } List <DialogData> datas = new List <DialogData>(); foreach (String key in dialogsMap.Keys) { DialogData data = new DialogData(); data.m_name = key; data.m_times = dialogsMap[key]; datas.Add(data); } datas.Sort(new DialogDataCompare2()); int datasSize = datas.Count; for (int i = 0; i < datasSize; i++) { DialogData data = datas[i]; int year = CStr.ConvertStrToInt(data.m_name.Substring(0, 4)); int month = CStr.ConvertStrToInt(data.m_name.Substring(4, 2)); int day = CStr.ConvertStrToInt(data.m_name.Substring(6, 2)); DateTime dt = new DateTime(year, month, day); double pk = CStr.ConvertDateToNum(dt); dataSource.Set(pk, 0, data.m_times); dataSource.Set2(i, 1, 0); } m_chartLevels.Update(); m_chartLevels.Invalidate(); }
/// <summary> /// 插入数据 /// </summary> /// <param name="chart">证券控件</param> /// <param name="dataSource">数据源</param> /// <param name="fields">字段</param> /// <param name="securityData">证券数据</param> /// <returns>索引</returns> public static int InsertData(ChartA chart, CTable dataSource, int[] fields, SecurityData securityData) { double close = securityData.m_close, high = securityData.m_high, low = securityData.m_low, open = securityData.m_open, avgPrice = securityData.m_avgPrice, volume = securityData.m_volume, amount = securityData.m_amount; if (volume > 0 || close > 0) { if (high == 0) { high = close; } if (low == 0) { low = close; } if (open == 0) { open = close; } if (avgPrice == 0) { avgPrice = double.NaN; } } else { close = double.NaN; high = double.NaN; low = double.NaN; open = double.NaN; volume = double.NaN; amount = double.NaN; avgPrice = double.NaN; } double date = securityData.m_date; dataSource.Set(date, fields[4], volume); int index = dataSource.GetRowIndex(date); dataSource.Set2(index, fields[0], close); dataSource.Set2(index, fields[1], high); dataSource.Set2(index, fields[2], low); dataSource.Set2(index, fields[3], open); dataSource.Set2(index, fields[5], amount); dataSource.Set2(index, fields[6], avgPrice); return(index); }
/// <summary> /// 创建指标 /// </summary> /// <param name="native">方法库</param> /// <param name="script">脚本</param> /// <param name="xml">XML</param> /// <returns>指标</returns> public static CIndicator CreateIndicator(String script, INativeBase native) { CIndicator indicator = native.CreateIndicator(); CTable table = native.CreateTable(); indicator.DataSource = table; CFunctionBase.AddFunctions(indicator); CFunctionHttp.AddFunctions(indicator); int index = STARTINDEX; string[] functions = FUNCTIONS.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); int functionsSize = functions.Length; for (int i = 0; i < functionsSize; i++) { indicator.AddFunction(new CFunctionEx(indicator, index + i, functions[i], native)); } indicator.Script = script; table.AddColumn(0); table.Set(0, 0, 0); indicator.OnCalculate(0); return(indicator); }
/// <summary> /// 宏运行中 /// </summary> /// <param name="macro">宏</param> /// <returns>状态</returns> public virtual int OnMacroRunning(Macro macro) { if (OnMacroStart(macro) == 0) { return(0); } if (macro.m_script.Length > 0) { int endIndex = m_chart.Index; ChartA ct = m_chart.Chart; CTable dataSource = ct.DataSource; CTable newDataSource = SecurityDataHelper.CreateDataSource(ct); int interval = macro.m_interval; CIndicator indicator = SecurityDataHelper.CreateIndicator(ct, newDataSource, "", ""); //indicator.AddFunction(new CFunctionEx(indicator, 1000, "ALERT", m_mainFrame-)); //indicator.AddFunction(new CFunctionEx(indicator, 1001, "SETCYCLE", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1002, "SETLAYOUT", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1003, "SETCODE", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1004, "SHOWWINDOW", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1005, "SLEEP", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1006, "SCROLLLEFT", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1007, "SCROLLRIGHT", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1008, "ZOOMIN", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1009, "ZOOMOUT", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1010, "WIN_MOUSEEVENT", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1011, "WIN_SETTEXT", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1012, "WIN_EXECUTE", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1013, "WIN_SENDKEY", m_chart)); //indicator.AddFunction(new CFunctionEx(indicator, 1014, "WIN_GETVALUE", m_chart)); indicator.Script = macro.m_script; int[] fields = new int[] { KeyFields.CLOSE_INDEX, KeyFields.HIGH_INDEX, KeyFields.LOW_INDEX, KeyFields.OPEN_INDEX, KeyFields.VOL_INDEX, KeyFields.AMOUNT_INDEX }; int fieldsSize = fields.Length; int startIndex = endIndex - (interval - 1); if (startIndex < 0) { startIndex = 0; } if (startIndex > endIndex) { startIndex = endIndex; } if (macro.m_type == 0 || macro.m_type == 2 || endIndex == -1) { double date = 0; newDataSource.Set(date, KeyFields.VOL_INDEX, 0); int index = newDataSource.GetRowIndex(date); for (int j = 0; j < fieldsSize; j++) { if (fields[j] != KeyFields.VOL_INDEX) { newDataSource.Set2(index, fields[j], 0); } } } else { for (int i = startIndex; i <= endIndex; i++) { double date = dataSource.GetXValue(i); newDataSource.Set(date, KeyFields.VOL_INDEX, dataSource.Get2(i, KeyFields.VOL_INDEX)); int index = newDataSource.GetRowIndex(date); for (int j = 0; j < fieldsSize; j++) { if (fields[j] != KeyFields.VOL_INDEX) { newDataSource.Set2(index, fields[j], dataSource.Get2(i, fields[j])); } } } } if (macro.m_type == 1 || macro.m_type == 3) { indicator.OnCalculate(0); } else { for (int i = 0; i < interval; i++) { indicator.OnCalculate(0); } } indicator.Clear(); indicator.Dispose(); newDataSource.Dispose(); } OnMacroEnd(macro); return(1); }