/// <summary> /// </summary> /// <param name="chartControl"></param> /// <param name="graphics"></param> /// <param name="bars"></param> /// <param name="panelIdx"></param> /// <param name="fromIdx"></param> /// <param name="toIdx"></param> /// <param name="bounds"></param> /// <param name="max"></param> /// <param name="min"></param> public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min) { if (downPen.Color != DownColor) downPen.Color = DownColor; if (upPen.Color != UpColor) upPen.Color = UpColor; Color barColor; int barWidth = bars.BarsData.ChartStyle.BarWidthUI; Color ellipseColor = UpColor; int high; int low; Color oldColor; Pen pen; int penHalfWidth; int penWidth; int x; if (Math.Max(1, barWidth) != upPen.Width) { downPen = new Pen(DownColor, Math.Max(1, barWidth)); upPen = new Pen(UpColor, Math.Max(1, barWidth)); } for (int idx = fromIdx; idx <= toIdx; idx++) { barColor = chartControl.GetBarOverrideColor(bars, idx); x = chartControl.GetXByBarIdx(bars, idx); high = chartControl.GetYByValue(bars, bars.GetHigh(idx)); low = chartControl.GetYByValue(bars, bars.GetLow(idx)); pen = (bars.GetClose(idx) >= bars.GetOpen(idx) ? upPen : downPen); oldColor = pen.Color; penWidth = (int)pen.Width; penHalfWidth = (int)(pen.Width / 2); ellipseColor = UpColor; if (barColor != Color.Empty) { pen.Color = barColor; ellipseColor = barColor; } if (high == low) { SolidBrush tmpBrush = new SolidBrush(ellipseColor); graphics.FillEllipse(tmpBrush, x - penHalfWidth - 1, Math.Min(high, low) - penHalfWidth - 1, pen.Width + 1, pen.Width + 1); tmpBrush.Dispose(); } else graphics.DrawLine(pen, x, Math.Min(high, low) - penHalfWidth, x, Math.Max(high, low) + penHalfWidth); if (barColor != Color.Empty) pen.Color = oldColor; } }
/// <summary> /// </summary> /// <param name="chartControl"></param> /// <param name="graphics"></param> /// <param name="bars"></param> /// <param name="panelIdx"></param> /// <param name="fromIdx"></param> /// <param name="toIdx"></param> /// <param name="bounds"></param> /// <param name="max"></param> /// <param name="min"></param> public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min) { Pen tmpUpPen = Gui.Globals.Clone(this.upPen); // work on copy, not on original object, otherwise issues with chart bars flickering on OHLC Pen tmpDownPen = Gui.Globals.Clone(this.downPen); // work on copy, not on original object, otherwise issues with chart bars flickering on OHLC if (tmpDownPen.Color != DownColor) tmpDownPen.Color = DownColor; if (tmpUpPen.Color != UpColor) tmpUpPen.Color = UpColor; Color barColor; int barWidth = bars.BarsData.ChartStyle.BarWidthUI; int close; double closeValue; int high; int low; Color oldColor = Color.Empty; int open; double openValue; Pen pen = tmpUpPen; int penWidth; int penHalfWidth; int x; if (Math.Max(1, barWidth - 2) != tmpUpPen.Width) { tmpDownPen = new Pen(DownColor, Math.Max(1, barWidth - 2)); tmpUpPen = new Pen(UpColor, Math.Max(1, barWidth - 2)); } for (int idx = fromIdx; idx <= toIdx; idx++) { barColor = chartControl.GetBarOverrideColor(bars, idx); closeValue = bars.GetClose(idx); close = chartControl.GetYByValue(bars, closeValue); high = chartControl.GetYByValue(bars, bars.GetHigh(idx)); low = chartControl.GetYByValue(bars, bars.GetLow(idx)); openValue = bars.GetOpen(idx); open = chartControl.GetYByValue(bars, openValue); pen = (closeValue >= openValue ? tmpUpPen : tmpDownPen); penHalfWidth = (int) (pen.Width / 2); penWidth = (int) pen.Width; x = chartControl.GetXByBarIdx(bars, idx); if (barColor != Color.Empty) { oldColor = pen.Color; pen.Color = barColor; } pen.Width = penWidth; // important to alleviate selecting the bar series graphics.DrawLine(pen, x, Math.Min(high, low) - penHalfWidth, x, Math.Max(high, low) + penHalfWidth); graphics.DrawLine(pen, x - Math.Max(1, barWidth), open, x, open); graphics.DrawLine(pen, x, close, x + Math.Max(1, barWidth), close); if (barColor != Color.Empty) pen.Color = oldColor; } tmpDownPen.Dispose(); tmpUpPen.Dispose(); }
/// <summary> /// </summary> /// <param name="chartControl"></param> /// <param name="graphics"></param> /// <param name="bars"></param> /// <param name="panelIdx"></param> /// <param name="fromIdx"></param> /// <param name="toIdx"></param> /// <param name="bounds"></param> /// <param name="max"></param> /// <param name="min"></param> public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min) { if (downBrush.Color != DownColor) downBrush.Color = DownColor; if (upBrush.Color != UpColor) upBrush.Color = UpColor; Color barColor; int barWidthValue = bars.BarsData.ChartStyle.BarWidthUI; int barWidth; SolidBrush brush = upBrush; int close; double closeValue; int high; int low; Color oldPenColor = Pen.Color; Color pen2Color = Pen2.Color; int open; double openValue; int x; for (int idx = fromIdx; idx <= toIdx; idx++) { barColor = chartControl.GetBarOverrideColor(bars, idx); barWidth = GetBarPaintWidth(barWidthValue); closeValue = bars.GetClose(idx); close = chartControl.GetYByValue(bars, closeValue); high = chartControl.GetYByValue(bars, bars.GetHigh(idx)); low = chartControl.GetYByValue(bars, bars.GetLow(idx)); openValue = bars.GetOpen(idx); open = chartControl.GetYByValue(bars, openValue); x = chartControl.GetXByBarIdx(bars, idx); Color candleOutlineColorScript = chartControl.GetCandleOutlineOverrideColor(bars, idx); bool isCandleOutlineColorScriptSet = (chartControl.GetCandleOutlineOverrideColor(bars, idx) != Color.Empty); Pen.Color = oldPenColor; if (barColor != Color.Empty) Pen.Color = (candleOutlineColorScript != Color.Empty ? candleOutlineColorScript : barColor); else if (candleOutlineColorScript != Color.Empty) Pen.Color = candleOutlineColorScript; if (open == close) graphics.DrawLine(Pen, x - barWidth / 2, close, x + barWidth / 2, close); else { brush = closeValue >= openValue ? upBrush : downBrush; Color oldColor = brush.Color; if (barColor != Color.Empty) brush.Color = barColor; graphics.FillRectangle(brush, x - barWidth / 2 + 1, Math.Min(close, open) + 1, barWidth - 1, Math.Max(open, close) - Math.Min(close, open) - 1); if (barColor != Color.Empty) brush.Color = oldColor; graphics.DrawRectangle(Pen, x - (barWidth / 2) + (Pen.Width / 2), Math.Min(close, open), barWidth - Pen.Width, Math.Max(open, close) - Math.Min(close, open)); } Pen2.Color = isCandleOutlineColorScriptSet ? candleOutlineColorScript : pen2Color; if (high < Math.Min(open, close)) graphics.DrawLine(Pen2, x, high, x, Math.Min(open, close)); if (low > Math.Max(open, close)) graphics.DrawLine(Pen2, x, low, x, Math.Max(open, close)); } Pen.Color = oldPenColor; Pen2.Color = pen2Color; }
/// <summary> /// </summary> /// <param name="chartControl"></param> /// <param name="graphics"></param> /// <param name="bars"></param> /// <param name="panelIdx"></param> /// <param name="fromIdx"></param> /// <param name="toIdx"></param> /// <param name="bounds"></param> /// <param name="max"></param> /// <param name="min"></param> public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min) { if (downBrush.Color != DownColor) downBrush.Color = DownColor; if (upBrush.Color != UpColor) upBrush.Color = UpColor; int x; Color barColor; int high; double highVal; int low; double lowVal; int boxStartPosition = -1; bool drawLastBar = false; int chartMinX = chartControl.CanvasRight - chartControl.BarMarginRight - GetBarPaintWidth(BarWidthUI) / 2 - ((chartControl.BarsPainted - 1) * chartControl.BarSpace); Color candleOutlineColorScript; if (toIdx >= 0 && toIdx < bars.Count - 1) toIdx++; for (int idx = fromIdx; idx <= toIdx; idx++) { if (idx == 0) continue; barColor = chartControl.GetBarOverrideColor(bars, idx); highVal = bars.GetHigh(idx); high = chartControl.GetYByValue(bars, highVal); lowVal = bars.GetLow(idx); low = chartControl.GetYByValue(bars, lowVal); x = chartControl.GetXByBarIdx(bars, idx); candleOutlineColorScript = chartControl.GetCandleOutlineOverrideColor(bars, idx); if (idx == fromIdx) boxStartPosition = chartMinX; else boxStartPosition = chartControl.GetXByBarIdx(bars, idx - 1); boxStartPosition = (boxStartPosition < chartMinX ? chartMinX : boxStartPosition); if (x == boxStartPosition) continue; int width = Math.Max(2, Math.Abs(x - boxStartPosition)); if (boxStartPosition + width > bounds.Width + bounds.X) width = (bounds.X + bounds.Width) - boxStartPosition; if (bars.GetClose(idx) >= bars.GetOpen(idx)) { Color oldBrushColor = upBrush.Color; Color oldPenColor = Pen.Color; if (barColor != Color.Empty) upBrush.Color = barColor; if (candleOutlineColorScript != Color.Empty) Pen.Color = candleOutlineColorScript; else if (barColor != Color.Empty) Pen.Color = barColor; width -= (int) Pen.Width; graphics.FillRectangle(upBrush, boxStartPosition, high, width, low - high); graphics.DrawRectangle(Pen, boxStartPosition, high, width, low - high); if (barColor != Color.Empty) upBrush.Color = oldBrushColor; if (candleOutlineColorScript != Color.Empty || barColor != Color.Empty) Pen.Color = oldPenColor; } else { Color oldBrushColor = downBrush.Color; Color oldPenColor = Pen2.Color; if (barColor != Color.Empty) downBrush.Color = barColor; if (candleOutlineColorScript != Color.Empty) Pen2.Color = candleOutlineColorScript; else if (barColor != Color.Empty) Pen2.Color = barColor; width -= (int) Pen2.Width; graphics.FillRectangle(downBrush, boxStartPosition, high, width, low - high); graphics.DrawRectangle(Pen2, boxStartPosition, high, width, low - high); if (barColor != Color.Empty) downBrush.Color = oldBrushColor; if (candleOutlineColorScript != Color.Empty || barColor != Color.Empty) Pen2.Color = oldPenColor; } if (!drawLastBar) drawLastBar = true; } }