/// <summary> /// 生成K线的下一个数据 /// </summary> /// <param name="addOrDelete">添加或删除</param> private void CreateNextData(bool addOrDelete) { ChartA chart = m_chart.Chart; CTable dataSource = chart.DataSource; LabelA lblDate = GetLabel("lblDate"); String strDate = lblDate.Text; if (strDate != null && strDate.Length > 0) { double date = 0; if (addOrDelete) { DateTime dateTime = Convert.ToDateTime(strDate); date = chart.ConvertDateToNum(dateTime); } else { int rowsCount = dataSource.RowsCount; if (rowsCount > 0) { date = dataSource.GetXValue(rowsCount - 1); } } date += m_chart.Cycle * 60; SetSpinValue(date); } }
/// <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); }
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); }
/// <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); }
/// <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); } } }