/// <summary> /// 添加指标 /// </summary> /// <param name="chart">股票控件</param> /// <param name="dataSource">数据源</param> /// <param name="text">文本</param> /// <param name="parameters">参数</param> public static CIndicator CreateIndicator(ChartA chart, CTable dataSource, String text, String parameters) { CIndicator indicator = chart.Native.CreateIndicator(); indicator.DataSource = dataSource; indicator.Name = ""; //indicator.FullName = ""; if (dataSource != null) { indicator.SetSourceField(KeyFields.CLOSE, KeyFields.CLOSE_INDEX); indicator.SetSourceField(KeyFields.HIGH, KeyFields.HIGH_INDEX); indicator.SetSourceField(KeyFields.LOW, KeyFields.LOW_INDEX); indicator.SetSourceField(KeyFields.OPEN, KeyFields.OPEN_INDEX); indicator.SetSourceField(KeyFields.VOL, KeyFields.VOL_INDEX); indicator.SetSourceField(KeyFields.AMOUNT, KeyFields.AMOUNT_INDEX); indicator.SetSourceField(KeyFields.CLOSE.Substring(0, 1), KeyFields.CLOSE_INDEX); indicator.SetSourceField(KeyFields.HIGH.Substring(0, 1), KeyFields.HIGH_INDEX); indicator.SetSourceField(KeyFields.LOW.Substring(0, 1), KeyFields.LOW_INDEX); indicator.SetSourceField(KeyFields.OPEN.Substring(0, 1), KeyFields.OPEN_INDEX); indicator.SetSourceField(KeyFields.VOL.Substring(0, 1), KeyFields.VOL_INDEX); indicator.SetSourceField(KeyFields.AMOUNT.Substring(0, 1), KeyFields.AMOUNT_INDEX); } IndicatorData indicatorData = new IndicatorData(); indicatorData.m_parameters = parameters; indicatorData.m_script = text; indicator.Tag = indicatorData; String constValue = ""; if (parameters != null && parameters.Length > 0) { String[] strs = parameters.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] + ";"; } } if (text != null && text.Length > 0) { indicator.Script = constValue + text; } return(indicator); }
/// <summary> /// 获取参数 /// </summary> private void GetParameters() { if (m_indicator != null) { m_window.Text = "参数设置(" + m_indicator.Name + ")"; IndicatorData indicatorData = m_indicator.Tag as IndicatorData; String[] strs = indicatorData.m_parameters.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; //依此创建控件 int addHeight = 0; for (int i = 0; i < strsSize; i++) { String str = strs[i]; String[] strs2 = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); String name = strs2[0]; String value = strs2[3]; //创建标签 LabelA label = new LabelA(); POINT location = new POINT(50, addHeight + 40); label.Location = location; label.Text = name; m_window.AddControl(label); //创建数值控件 SpinA spin = new SpinA(); location.x = 130; location.y = addHeight + 40; spin.Location = location; spin.Maximum = 10000000; spin.Value = CStrA.ConvertStrToDouble(value); m_window.AddControl(spin); addHeight += 30; } m_window.Height += addHeight; //调整按钮的位置 ButtonA cancelButton = GetButton("btnCancel"); ButtonA submitButton = GetButton("btnSubmit"); cancelButton.Top += addHeight; submitButton.Top += addHeight; } }
/// <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(); }