protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { if (Bars == null || ChartControl == null) { return; } int barPaintWidth = Math.Max(3, 1 + 2 * ((int)ChartControl.BarWidth - 1) + 2 * shadowWidth); for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++) { if (idx - Displacement < 0 || idx - Displacement >= BarsArray[0].Count || (idx - Displacement < BarsRequiredToPlot)) { continue; } double valH = HAHigh.GetValueAt(idx); double valL = HALow.GetValueAt(idx); double valC = HAClose.GetValueAt(idx); double valO = HAOpen.GetValueAt(idx); int x = chartControl.GetXByBarIndex(chartControl.BarsArray[0], idx); int y1 = chartScale.GetYByValue(valO); int y2 = chartScale.GetYByValue(valH); int y3 = chartScale.GetYByValue(valL); int y4 = chartScale.GetYByValue(valC); SharpDX.Direct2D1.Brush shadowColordx = shadowColor.ToDxBrush(RenderTarget); // prepare for the color to use var xy2 = new Vector2(x, y2); var xy3 = new Vector2(x, y3); RenderTarget.DrawLine(xy2, xy3, shadowColordx, shadowWidth); if (y4 == y1) { RenderTarget.DrawLine(new Vector2(x - barPaintWidth / 2, y1), new Vector2(x + barPaintWidth / 2, y1), shadowColordx, shadowWidth); } else { if (y4 > y1) { SharpDX.Direct2D1.Brush barColorDowndx = barColorDown.ToDxBrush(RenderTarget); // prepare for the color to use RenderTarget.FillRectangle(new RectangleF(x - barPaintWidth / 2, y1, barPaintWidth, y4 - y1), barColorDowndx); barColorDowndx.Dispose(); } else { SharpDX.Direct2D1.Brush barColorUpdx = barColorUp.ToDxBrush(RenderTarget); // prepare for the color to use RenderTarget.FillRectangle(new RectangleF(x - barPaintWidth / 2, y4, barPaintWidth, y1 - y4), barColorUpdx); barColorUpdx.Dispose(); } RenderTarget.DrawRectangle(new RectangleF(x - barPaintWidth / 2 + (float)shadowWidth / 2, Math.Min(y4, y1), barPaintWidth - (float)shadowWidth, Math.Abs(y4 - y1)), shadowColordx, shadowWidth); } shadowColordx.Dispose(); } }
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); BodyWidth = (int)ChartControl.BarWidth + Math.Min(ShadowWidth * 2, 4); if (ChartBars != null) { // loop through all of the viewable range of the chart for (int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++) { if (ShadowColor == Brushes.Transparent) { if (Close.GetValueAt(barIndex) > Open.GetValueAt(barIndex)) { DrawLineNT("BarBrushUp", barIndex, HAHigh.GetValueAt(barIndex), barIndex, Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)), ShadowWidth, chartScale); DrawLineNT("BarBrushUp", barIndex, HALow.GetValueAt(barIndex), barIndex, Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)), ShadowWidth, chartScale); } else { DrawLineNT("BarBrushDown", barIndex, HAHigh.GetValueAt(barIndex), barIndex, Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)), ShadowWidth, chartScale); DrawLineNT("BarBrushDown", barIndex, HALow.GetValueAt(barIndex), barIndex, Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)), ShadowWidth, chartScale); } } else { DrawLineNT("ShadowBrush", barIndex, HAHigh.GetValueAt(barIndex), barIndex, Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(ShadowWidth)), ShadowWidth, chartScale); DrawLineNT("ShadowBrush", barIndex, HALow.GetValueAt(barIndex), barIndex, Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(ShadowWidth)), ShadowWidth, chartScale); } if (HAClose.GetValueAt(barIndex) > HAOpen.GetValueAt(barIndex)) { DrawLineNT("BarBrushUp", barIndex, HAOpen.GetValueAt(barIndex), barIndex, HAClose.GetValueAt(barIndex), BodyWidth, chartScale); } else { DrawLineNT("BarBrushDown", barIndex, HAOpen.GetValueAt(barIndex), barIndex, HAClose.GetValueAt(barIndex), BodyWidth, chartScale); } } // Draw price line if wanted if (ShowPriceLine) { DrawLineNT("PriceLineBrush", Math.Max(PriceLineLength, CurrentBar - 15), Close.GetValueAt(CurrentBar), CurrentBar, Close.GetValueAt(CurrentBar), PriceLineWidth, PriceLineStyle, chartScale); DrawStringNT(" -- " + Close.GetValueAt(CurrentBar).ToString() + " = Last Price", Font, "PriceTextBrush", CurrentBar, Close.GetValueAt(CurrentBar), "PriceAreaBrush", chartScale); } } }