示例#1
0
 /// <summary>
 /// 执行秒表方法
 /// </summary>
 /// <param name="timerID">秒表ID</param>
 public void OnTimer(int timerID)
 {
     if (m_timerID == timerID)
     {
         INativeBase             native     = Native;
         ChartA                  chart      = m_chart.Chart;
         CTable                  dataSource = chart.DataSource;
         int                     divsSize   = m_divs.Count;
         bool                    painting   = false;
         int                     cx         = native.ClientX(m_window);
         int                     cy         = native.ClientY(m_window);
         List <SandBoxCandleDiv> removeDivs = new List <SandBoxCandleDiv>();
         for (int i = 0; i < divsSize; i++)
         {
             SandBoxCandleDiv div = m_divs[i];
             //判断是否需要重绘
             if (div.Moving)
             {
                 painting = true;
             }
             //执行秒表
             if (m_divs[i].OnTimer())
             {
                 SecurityData data     = div.Data;
                 int          rowIndex = dataSource.GetRowIndex(data.m_date);
                 int[]        fields   = new int[7];
                 fields[0] = KeyFields.CLOSE_INDEX;
                 fields[1] = KeyFields.HIGH_INDEX;
                 fields[2] = KeyFields.LOW_INDEX;
                 fields[3] = KeyFields.OPEN_INDEX;
                 fields[4] = KeyFields.VOL_INDEX;
                 fields[5] = KeyFields.AMOUNT_INDEX;
                 fields[6] = KeyFields.AVGPRICE_INDEX;
                 //插入数据
                 SecurityDataHelper.InsertLatestData(m_chart.Chart, dataSource, m_chart.Indicators, fields, data);
                 removeDivs.Add(div);
             }
         }
         //移除控件
         int removeDivsSize = removeDivs.Count;
         if (removeDivsSize > 0)
         {
             for (int i = 0; i < removeDivsSize; i++)
             {
                 SandBoxCandleDiv div = removeDivs[i];
                 m_native.RemoveControl(div);
                 m_divs.Remove(div);
                 div.Dispose();
             }
             removeDivs.Clear();
             m_chart.Chart.Update();
         }
         //重绘
         if (painting)
         {
             m_native.Invalidate();
         }
     }
 }
示例#2
0
        /// <summary>
        /// 运行指标
        /// </summary>
        public void Run()
        {
            if (m_chart == null)
            {
                m_chart        = new ChartA();
                m_chart.Native = m_native;
                m_dataSource   = SecurityDataHelper.CreateDataSource(m_chart);
            }
            if (m_indicator != null)
            {
                m_indicator.Dispose();
            }
            String indicator = m_template.m_indicator;

            if (m_template.m_filter != null && m_template.m_filter.Length > 0)
            {
                indicator += "FILTER:=" + m_template.m_filter;
            }
            else
            {
                indicator += "FILTER:=1";
            }
            m_indicator = SecurityDataHelper.CreateIndicator(m_chart, m_dataSource, indicator, m_template.m_parameters);
            m_indicator.OnCalculate(0);
            m_infos.Clear();
            List <Security> securities = new List <Security>();

            DataCenter.SecurityService.GetSecuritiesByCodes(m_template.m_codes, securities);
            int securitiesSize = securities.Count;

            for (int i = 0; i < securitiesSize; i++)
            {
                Security           security = securities[i];
                SecurityFilterInfo info     = new SecurityFilterInfo();
                info.DataSource          = m_dataSource;
                info.Security            = security;
                m_infos[security.m_code] = info;
            }
            LatestDataInfo dataInfo = new LatestDataInfo();

            dataInfo.m_codes      = m_template.m_codes;
            dataInfo.m_formatType = 1;
            m_quoteService.PushLatestDatas(m_qtRequestID, dataInfo);
            m_securityFilterService.StartFilter(m_sfRequestID, m_template);
            m_runningState = 0;
            m_matchCount   = 0;
        }
示例#3
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);
 }