Ejemplo n.º 1
0
        /// <summary>
        /// 获取目标K线的坐标
        /// </summary>
        /// <param name="location">目标K线的坐标</param>
        /// <param name="destHighY">移动到目标K线最高点的Y坐标</param>
        private void GetDestPos(ref POINT location, ref float destHighY)
        {
            ChartA chart       = m_chart.Chart;
            CTable dataSource  = chart.DataSource;
            int    rowIndex    = dataSource.GetRowIndex(m_data.m_date);
            int    insRowIndex = rowIndex;
            int    size        = dataSource.RowsCount;

            if (rowIndex == -1)
            {
                for (int i = 0; i < size; i++)
                {
                    double pk = dataSource.GetXValue(i);
                    if (pk > m_data.m_date)
                    {
                        insRowIndex = i;
                        break;
                    }
                }
            }
            if (insRowIndex == -1 || insRowIndex > chart.LastVisibleIndex)
            {
                insRowIndex = chart.LastVisibleIndex;
            }
            double      insLow = dataSource.Get2(insRowIndex, KeyFields.LOW_INDEX);
            float       xDest  = chart.GetX(insRowIndex);
            List <CDiv> divs   = chart.GetDivs();
            float       yDest  = chart.GetY(divs[0], insLow, AttachVScale.Left);

            location.x = (int)(xDest);
            location.y = (int)(yDest);
            destHighY  = chart.GetY(divs[0], m_data.m_high, AttachVScale.Left);
        }
Ejemplo n.º 2
0
        public static double SumHistoryData(CTable dataSource, double date, int cycle, int field)
        {
            double sumValue = 0;
            double value = 0;
            int    year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0;

            CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms);
            if (cycle == CYCLE_WEEK)
            {
                int dayOfWeek = DayOfWeek(year, month, day);
                if (dayOfWeek >= 5)
                {
                    dayOfWeek = 4;
                }
                for (int i = 1; i <= dayOfWeek; i++)
                {
                    double calcDate = CStrA.M129(year, month, day - i, 0, 0, 0, 0);
                    value = dataSource.Get(calcDate, field);
                    if (!double.IsNaN(value))
                    {
                        sumValue += value;
                    }
                }
            }
            else if (cycle == CYCLE_MONTH)
            {
                for (int i = 1; i < day; i++)
                {
                    double calcDate = CStrA.M129(year, month, i, 0, 0, 0, 0);
                    value = dataSource.Get(calcDate, field);
                    if (!double.IsNaN(value))
                    {
                        sumValue += value;
                    }
                }
            }
            else if (cycle == 0)
            {
                int rowCount = dataSource.RowsCount;
                for (int i = 0; i < rowCount; i++)
                {
                    value = dataSource.Get2(i, field);
                    if (!double.IsNaN(value))
                    {
                        sumValue += value;
                    }
                }
            }
            return(sumValue);
        }
Ejemplo n.º 3
0
        public static double GetMinuteVol(CTable dataSource, double date, int field, double volume)
        {
            int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0;

            CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms);
            double startDate = 0;
            double endDate   = date;

            if (hour >= 6)
            {
                startDate = CStrA.M129(year, month, day, 6, 0, 0, 0);
            }
            else
            {
                double preDate = date - 86400;
                int    lyear = 0, lmonth = 0, lday = 0, lhour = 0, lminute = 0, lsecond = 0, lms = 0;
                CStrA.M130(preDate, ref lyear, ref lmonth, ref lday, ref lhour, ref lminute, ref lsecond, ref lms);
                startDate = CStrA.M129(lyear, lmonth, lday, 6, 0, 0, 0);
            }
            int  dataSize    = dataSource.RowsCount;
            bool containsFlg = false;

            for (int i = dataSize - 1; i >= 0; i--)
            {
                containsFlg = false;
                double ldate = dataSource.GetXValue(i);
                if (startDate <= ldate && ldate <= endDate)
                {
                    containsFlg = true;
                }
                if (!containsFlg)
                {
                    break;
                }
                else
                {
                    double vol = dataSource.Get2(i, KeyFields.VOL_INDEX);
                    volume = volume - vol;
                }
            }
            return(volume);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 计算指标
        /// </summary>
        /// <param name="id">指标ID</param>
        /// <param name="code">代码</param>
        /// <returns>返回数据</returns>
        public static Dictionary <String, double> CalculateIndicatorExtern(int id, String code)
        {
            Dictionary <String, double> list = new Dictionary <String, double>();

            if (m_indicators.ContainsKey(id) &&
                SecurityService.m_historyDatas.ContainsKey(code) &&
                SecurityService.m_latestDatas.ContainsKey(code))
            {
                CIndicator        indicator  = m_indicators[id];
                List <CIndicator> indicators = new List <CIndicator>();
                indicators.Add(indicator);
                List <SecurityData> datas            = new List <SecurityData>();
                List <SecurityData> oldSecurityDatas = SecurityService.m_historyDatas[code];
                int oldSecurityDatasSize             = oldSecurityDatas.Count;
                for (int i = 0; i < oldSecurityDatasSize; i++)
                {
                    datas.Add(oldSecurityDatas[i]);
                }
                SecurityLatestData latestData = SecurityService.m_latestDatas[code];
                SecurityData       newData    = new SecurityData();
                StockService.GetSecurityData(latestData, latestData.m_lastClose, 1440, 1, ref newData);
                datas.Add(newData);
                CTable dataSource = indicator.DataSource;
                int[]  fields     = new int[] { KeyFields.CLOSE_INDEX, KeyFields.HIGH_INDEX, KeyFields.LOW_INDEX, KeyFields.OPEN_INDEX, KeyFields.VOL_INDEX, KeyFields.AMOUNT_INDEX };
                SecurityDataHelper.BindHistoryDatas(m_chart, dataSource, indicators, fields, datas);
                datas.Clear();
                int rowsCount     = dataSource.RowsCount;
                int variablesSize = indicator.MainVariables.Count;
                if (rowsCount > 0)
                {
                    foreach (String name in indicator.MainVariables.Keys)
                    {
                        int    field = indicator.MainVariables[name];
                        double value = dataSource.Get2(rowsCount - 1, field);
                        list[name] = value;
                    }
                }
                dataSource.Clear();
            }
            return(list);
        }
Ejemplo n.º 5
0
 public static void InsertLatestData(ChartAEx chart, CTable dataSource, List <CIndicator> indicators, int [] fields, double preClose, int lastIndex)
 {
     for (int i = 0; i < lastIndex; i++)
     {
         double close = dataSource.Get2(i, fields[KeyFields.CLOSE_INDEX]);
         if (double.IsNaN(close))
         {
             dataSource.Set2(i, fields[KeyFields.CLOSE_INDEX], preClose);
             dataSource.Set2(i, fields[KeyFields.OPEN_INDEX], preClose);
             dataSource.Set2(i, fields[KeyFields.HIGH_INDEX], preClose);
             dataSource.Set2(i, fields[KeyFields.LOW_INDEX], preClose);
             dataSource.Set2(i, fields[KeyFields.VOL_INDEX], 0);
             dataSource.Set2(i, fields[KeyFields.AMOUNT_INDEX], 0);
             dataSource.Set2(i, fields[KeyFields.AVGPRICE_INDEX], preClose);
         }
         else
         {
             preClose = close;
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 把指定日期K线的高开低收数据设置到画面的数值控件上
        /// </summary>
        /// <param name="date">日期</param>
        private void SetSpinValue(double date)
        {
            ChartA chart      = m_chart.Chart;
            CTable dataSource = chart.DataSource;
            int    rowsCount  = dataSource.RowsCount;

            if (rowsCount > 0)
            {
                int index = dataSource.GetRowIndex(date);
                if (index < 1)
                {
                    index = rowsCount - 1;
                }
                SpinA  spinOpen   = GetSpin("txtOpen");
                SpinA  spinClose  = GetSpin("txtClose");
                SpinA  spinHigh   = GetSpin("txtHigh");
                SpinA  spinLow    = GetSpin("txtLow");
                SpinA  spinVolume = GetSpin("txtVolume");
                SpinA  spinAmount = GetSpin("txtAmount");
                LabelA lblDate    = GetLabel("lblDate");
                spinOpen.Value   = dataSource.Get2(index, KeyFields.OPEN_INDEX);
                spinClose.Value  = dataSource.Get2(index, KeyFields.CLOSE_INDEX);
                spinHigh.Value   = dataSource.Get2(index, KeyFields.HIGH_INDEX);
                spinLow.Value    = dataSource.Get2(index, KeyFields.LOW_INDEX);
                spinVolume.Value = dataSource.Get2(index, KeyFields.VOL_INDEX);
                spinAmount.Value = dataSource.Get2(index, KeyFields.AMOUNT_INDEX);
                DateTime dateTime = m_chart.Chart.ConvertNumToDate(date);
                int      m_cycle  = m_chart.Cycle;
                if (m_cycle <= 60)
                {
                    lblDate.Text = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
                }
                else
                {
                    lblDate.Text = dateTime.ToString("yyyy-MM-dd");
                }
                m_window.Invalidate();
            }
        }
Ejemplo n.º 7
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(indicator, 1000, "ALERT", m_mainFrame-));
         //indicator.AddFunction(new CFunctionEx(indicator, 1001, "SETCYCLE", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1002, "SETLAYOUT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1003, "SETCODE", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1004, "SHOWWINDOW", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1005, "SLEEP", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1006, "SCROLLLEFT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1007, "SCROLLRIGHT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1008, "ZOOMIN", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1009, "ZOOMOUT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1010, "WIN_MOUSEEVENT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1011, "WIN_SETTEXT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1012, "WIN_EXECUTE", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1013, "WIN_SENDKEY", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1014, "WIN_GETVALUE", m_chart));
         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);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 重绘背景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public override void OnPaintBackground(CPaint paint, RECT clipRect)
        {
            int width  = Width;
            int height = Height;

            if (width > 0 && height > 0)
            {
                ChartA chart = m_chart.Chart;
                //十字线出现时进行绘制
                if (chart.ShowCrossLine)
                {
                    CTable dataSource = chart.DataSource;
                    //获取鼠标停留索引
                    int crossStopIndex = chart.CrossStopIndex;
                    if (dataSource.RowsCount > 0)
                    {
                        if (crossStopIndex < 0)
                        {
                            crossStopIndex = chart.FirstVisibleIndex;
                        }
                        if (crossStopIndex > chart.LastVisibleIndex)
                        {
                            crossStopIndex = chart.LastVisibleIndex;
                        }
                    }
                    else
                    {
                        crossStopIndex = -1;
                    }
                    //获取K线和成交量
                    RECT rectangle  = new RECT(0, 0, width, height);
                    long win32Color = COLOR.EMPTY;
                    paint.FillRect(GetPaintingBackColor(), rectangle);
                    paint.DrawRect(GetPaintingBorderColor(), 1, 0, rectangle);
                    //画关闭按钮
                    long lineColor = CDraw.PCOLORS_LINECOLOR;
                    paint.DrawLine(lineColor, 2, 0, width - 6, 4, width - 14, 12);
                    paint.DrawLine(lineColor, 2, 0, width - 6, 12, width - 14, 4);
                    //创建字体
                    FONT font  = new FONT("SimSun", 14, false, false, false);
                    FONT lfont = new FONT("Arial", 12, false, false, false);
                    FONT nfont = new FONT("Arial", 14, true, false, false);
                    //画日期
                    CDraw.DrawText(paint, "时 间", CDraw.PCOLORS_FORECOLOR, font, rectangle.left + 25, rectangle.top + 2);
                    DateTime date = DateTime.Now;
                    if (crossStopIndex >= 0)
                    {
                        double dateNum = dataSource.GetXValue(crossStopIndex);
                        if (dateNum != 0)
                        {
                            date = CStrA.ConvertNumToDate(dateNum);
                        }
                        String dateStr = "";
                        int    cycle   = m_chart.Cycle;
                        if (cycle <= 1)
                        {
                            dateStr = date.ToString("hh:mm");
                        }
                        else if (cycle >= 5 && cycle <= 60)
                        {
                            dateStr = date.ToString("MM-dd hh:mm");
                        }
                        else
                        {
                            dateStr = date.ToString("yyyy-MM-dd");
                        }
                        SIZE dtSize = paint.TextSize(dateStr, lfont);
                        CDraw.DrawText(paint, dateStr, CDraw.PCOLORS_FORECOLOR3,
                                       lfont, rectangle.left + width / 2 - dtSize.cx / 2, rectangle.top + 20);
                        //获取值
                        double close = 0, high = 0, low = 0, open = 0, amount = 0;
                        if (crossStopIndex >= 0)
                        {
                            close  = dataSource.Get2(crossStopIndex, KeyFields.CLOSE_INDEX);
                            high   = dataSource.Get2(crossStopIndex, KeyFields.HIGH_INDEX);
                            low    = dataSource.Get2(crossStopIndex, KeyFields.LOW_INDEX);
                            open   = dataSource.Get2(crossStopIndex, KeyFields.OPEN_INDEX);
                            amount = dataSource.Get2(crossStopIndex, KeyFields.AMOUNT_INDEX);
                        }
                        if (double.IsNaN(close))
                        {
                            close = 0;
                        }
                        if (double.IsNaN(high))
                        {
                            high = 0;
                        }
                        if (double.IsNaN(low))
                        {
                            low = 0;
                        }
                        if (double.IsNaN(open))
                        {
                            open = 0;
                        }
                        if (double.IsNaN(amount))
                        {
                            amount = 0;
                        }
                        double rate      = 1;
                        double lastClose = 0;
                        if (crossStopIndex > 1)
                        {
                            lastClose = dataSource.Get2(crossStopIndex - 1, KeyFields.CLOSE_INDEX);
                            if (cycle == 0)
                            {
                                lastClose = m_chart.LatestData.m_lastClose;
                            }
                            if (!double.IsNaN(lastClose))
                            {
                                if (lastClose != 0)
                                {
                                    rate = (close - lastClose) / lastClose;
                                }
                            }
                        }
                        //开盘价
                        String openStr = double.IsNaN(open) ? "" : CStr.GetValueByDigit(open, m_digit).ToString();
                        SIZE   tSize   = paint.TextSize(openStr, nfont);
                        CDraw.DrawText(paint, openStr, CDraw.GetPriceColor(open, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 60);
                        //最高价
                        String highStr = double.IsNaN(high) ? "" : CStr.GetValueByDigit(high, m_digit).ToString();
                        tSize = paint.TextSize(highStr, nfont);
                        CDraw.DrawText(paint, highStr, CDraw.GetPriceColor(high, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 100);
                        //最低价
                        String lowStr = double.IsNaN(low) ? "" : CStr.GetValueByDigit(low, m_digit).ToString();
                        tSize = paint.TextSize(lowStr, nfont);
                        CDraw.DrawText(paint, lowStr, CDraw.GetPriceColor(low, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 140);
                        //最低价
                        String closeStr = double.IsNaN(close) ? "" : CStr.GetValueByDigit(close, m_digit).ToString();
                        tSize = paint.TextSize(closeStr, nfont);
                        CDraw.DrawText(paint, closeStr, CDraw.GetPriceColor(close, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 180);
                        //成交量
                        String unit = "";
                        if (amount > 100000000)
                        {
                            amount /= 100000000;
                            unit    = "亿";
                        }
                        else if (amount > 10000)
                        {
                            amount /= 10000;
                            unit    = "万";
                        }
                        String amountStr = CStr.GetValueByDigit(amount, 2) + unit;
                        tSize = paint.TextSize(amountStr, lfont);
                        CDraw.DrawText(paint, amountStr, CDraw.PCOLORS_FORECOLOR3, lfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 220);
                        //涨幅
                        String rangeStr = double.IsNaN(rate) ? "0.00%" : rate.ToString("0.00%");
                        tSize = paint.TextSize(rangeStr, nfont);
                        CDraw.DrawText(paint, rangeStr, CDraw.GetPriceColor(close, lastClose), lfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 260);
                    }
                    long whiteColor = CDraw.PCOLORS_FORECOLOR;
                    CDraw.DrawText(paint, "开 盘", whiteColor, font, rectangle.left + 25, rectangle.top + 40);
                    CDraw.DrawText(paint, "最 高", whiteColor, font, rectangle.left + 25, rectangle.top + 80);
                    CDraw.DrawText(paint, "最 低", whiteColor, font, rectangle.left + 25, rectangle.top + 120);
                    CDraw.DrawText(paint, "收 盘", whiteColor, font, rectangle.left + 25, rectangle.top + 160);
                    CDraw.DrawText(paint, "金 额", whiteColor, font, rectangle.left + 25, rectangle.top + 200);
                    CDraw.DrawText(paint, "涨 幅", whiteColor, font, rectangle.left + 25, rectangle.top + 240);
                }
            }
        }