Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加方法
        /// </summary>
        /// <param name="indicator">方法库</param>
        /// <param name="native">脚本</param>
        /// <param name="xml">XML</param>
        /// <returns>指标</returns>
        public static void AddFunctions(CIndicator indicator, UIXml xml)
        {
            string[] functions     = FUNCTIONS.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            int      functionsSize = functions.Length;

            for (int i = 0; i < functionsSize; i++)
            {
                indicator.AddFunction(new CFunctionUI(indicator, STARTINDEX + i, PREFIX + functions[i], xml));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 添加方法
        /// </summary>
        /// <param name="indicator">方法库</param>
        /// <returns>指标</returns>
        public static void AddFunctions(CIndicator indicator)
        {
            string[] functions     = FUNCTIONS.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            int      functionsSize = functions.Length;

            for (int i = 0; i < functionsSize; i++)
            {
                indicator.AddFunction(new CFunctionAjax(indicator, STARTINDEX + i, PREFIX + functions[i]));
            }
            if (m_requests == null)
            {
                m_requests = new List <AjaxRequest>();
                Thread thread = new Thread(new ThreadStart(AjaxHandle));
                thread.Start();
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 /// <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(m_chart, indicator, 1000, "ALERT"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1001, "SETCYCLE"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1002, "SETLAYOUT"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1003, "SETCODE"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1004, "SHOWWINDOW"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1005, "SLEEP"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1006, "SCROLLLEFT"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1007, "SCROLLRIGHT"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1008, "ZOOMIN"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1009, "ZOOMOUT"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1010, "WIN_MOUSEEVENT"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1011, "WIN_SETTEXT"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1012, "WIN_EXECUTE"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1013, "WIN_SENDKEY"));
         indicator.AddFunction(new CFunctionEx(m_chart, indicator, 1014, "WIN_GETVALUE"));
         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);
 }