/// <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> /// <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> /// <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); }
/// <summary> /// 运行指标 /// </summary> public void Run() { if (m_chart == null) { m_chart = new ChartA(); m_chart.Native = m_native; m_dataSource = SecurityDataHelper.CreateDataSource(m_chart); } if (m_indicator != null) { m_indicator.Dispose(); } String indicator = m_template.m_indicator; if (m_template.m_filter != null && m_template.m_filter.Length > 0) { indicator += "FILTER:=" + m_template.m_filter; } else { indicator += "FILTER:=1"; } m_indicator = SecurityDataHelper.CreateIndicator(m_chart, m_dataSource, indicator, m_template.m_parameters); m_indicator.OnCalculate(0); m_infos.Clear(); List <Security> securities = new List <Security>(); DataCenter.SecurityService.GetSecuritiesByCodes(m_template.m_codes, securities); int securitiesSize = securities.Count; for (int i = 0; i < securitiesSize; i++) { Security security = securities[i]; SecurityFilterInfo info = new SecurityFilterInfo(); info.DataSource = m_dataSource; info.Security = security; m_infos[security.m_code] = info; } LatestDataInfo dataInfo = new LatestDataInfo(); dataInfo.m_codes = m_template.m_codes; dataInfo.m_formatType = 1; m_quoteService.PushLatestDatas(m_qtRequestID, dataInfo); m_securityFilterService.StartFilter(m_sfRequestID, m_template); m_runningState = 0; m_matchCount = 0; }
/// <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); }
/// <summary> /// 设置参数 /// </summary> private void SetParameters() { List <ControlA> controls = m_window.GetControls(); List <LabelA> labels = new List <LabelA>(); List <SpinA> spins = new List <SpinA>(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { ControlA control = controls[i]; LabelA label = control as LabelA; SpinA spin = control as SpinA; if (label != null) { labels.Add(label); } else if (spin != null) { spins.Add(spin); } } int labelsSize = labels.Count; String newParameters = ""; for (int i = 0; i < labelsSize; i++) { newParameters += labels[i].Text + ",0,0," + spins[i].Value.ToString(); newParameters += ";"; } labels.Clear(); spins.Clear(); m_indicator.Clear(); m_indicator.SetSourceField(KeyFields.CLOSE, KeyFields.CLOSE_INDEX); m_indicator.SetSourceField(KeyFields.HIGH, KeyFields.HIGH_INDEX); m_indicator.SetSourceField(KeyFields.LOW, KeyFields.LOW_INDEX); m_indicator.SetSourceField(KeyFields.OPEN, KeyFields.OPEN_INDEX); m_indicator.SetSourceField(KeyFields.VOL, KeyFields.VOL_INDEX); m_indicator.SetSourceField(KeyFields.AMOUNT, KeyFields.AMOUNT_INDEX); m_indicator.SetSourceField(KeyFields.CLOSE.Substring(0, 1), KeyFields.CLOSE_INDEX); m_indicator.SetSourceField(KeyFields.HIGH.Substring(0, 1), KeyFields.HIGH_INDEX); m_indicator.SetSourceField(KeyFields.LOW.Substring(0, 1), KeyFields.LOW_INDEX); m_indicator.SetSourceField(KeyFields.OPEN.Substring(0, 1), KeyFields.OPEN_INDEX); m_indicator.SetSourceField(KeyFields.VOL.Substring(0, 1), KeyFields.VOL_INDEX); m_indicator.SetSourceField(KeyFields.AMOUNT.Substring(0, 1), KeyFields.AMOUNT_INDEX); IndicatorData indicatorData = m_indicator.Tag as IndicatorData; indicatorData.m_parameters = newParameters; String constValue = ""; if (newParameters != null && newParameters.Length > 0) { String[] strs = newParameters.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; for (int i = 0; i < strsSize; i++) { String str = strs[i]; String[] strs2 = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); constValue += "const " + strs2[0] + ":" + strs2[3] + ";"; } } m_indicator.Script = constValue + indicatorData.m_script; m_indicator.OnCalculate(0); if (m_indicator.AttachVScale == AttachVScale.Left) { //m_indicator.Div.TitleBar.Text = m_indicator.Title; } m_chart.Chart.Update(); m_chart.Chart.Invalidate(); }