예제 #1
0
        /// <summary>
        /// 创建指标
        /// </summary>
        /// <param name="id">编号</param>
        /// <param name="script">脚本</param>
        /// <param name="xml">XML</param>
        /// <returns>指标</returns>
        public static FCScript createIndicator(String id, String script, FCUIXml xml)
        {
            FCScript indicator = new FCScript();

            indicator.Name = id;
            FCDataTable table = new FCDataTable();

            indicator.DataSource = table;
            NFunctionBase.addFunctions(indicator);
            NFunctionUI.addFunctions(indicator, xml);
            NFunctionWin.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 NFunctionEx(indicator, index + i, functions[i], xml));
            }
            indicator.Script = script;
            table.addColumn(0);
            table.set(0, 0, 0);
            indicator.onCalculate(0);
            return(indicator);
        }
예제 #2
0
        /// <summary>
        /// 创建数据源
        /// </summary>
        /// <param name="chart">股票控件</param>
        /// <returns>数据源</returns>
        public static FCDataTable createDataSource(FCChart chart)
        {
            FCDataTable dataSource = new FCDataTable();

            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);
            return(dataSource);
        }
예제 #3
0
        /// <summary>
        /// 创建指标
        /// </summary>
        /// <param name="native">方法库</param>
        /// <param name="script">脚本</param>
        /// <returns>指标</returns>
        public static FCScript CreateScript(String script, FCNative native)
        {
            FCScript    indicator = new FCScript();
            FCDataTable table     = new FCDataTable();

            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);
        }
예제 #4
0
 /// <summary>
 /// 创建指标
 /// </summary>
 /// <param name="text">脚本</param>
 /// <param name="parameters">参数</param>
 /// <returns>指标ID</returns>
 public static int createIndicatorExtern(String text, String parameters, StringBuilder fields)
 {
     try {
         if (m_native == null)
         {
             m_native = new FCNative();
         }
         if (m_chart == null)
         {
             m_chart        = new FCChart();
             m_chart.Native = m_native;
         }
         m_serialNumber++;
         FCDataTable dataSource = new FCDataTable();
         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);
         FCScript indicator = SecurityDataHelper.createIndicator(m_chart, dataSource, text, parameters);
         m_indicators[m_serialNumber] = indicator;
         indicator.onCalculate(0);
         int pos           = 0;
         int variablesSize = indicator.MainVariables.Count;
         foreach (String field in indicator.MainVariables.Keys)
         {
             fields.Append(field);
             if (pos != variablesSize - 1)
             {
                 fields.Append(",");
             }
             pos++;
         }
     } catch (Exception ex) {
         Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
     }
     return(m_serialNumber);
 }