Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="chart">证券控件</param>
        /// <param name="dataSource">数据源</param>
        /// <param name="fields">字段</param>
        /// <param name="securityData">证券数据</param>
        /// <returns>索引</returns>
        public static int insertData(FCChart chart, FCDataTable 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], volume);
            dataSource.set2(index, fields[6], avgPrice);
            return(index);
        }
Exemplo n.º 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);
        }