Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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();
        }