protected override void OnStateChange() { if (State == State.SetDefaults) { Name = Custom.Resource.NinjaScriptChartStyleKagi; ChartStyleType = ChartStyleType.KagiLine; Stroke = new Gui.Stroke(System.Windows.Media.Brushes.LimeGreen, 3) { IsOpacityVisible = false }; Stroke2 = new Gui.Stroke(System.Windows.Media.Brushes.Red, 1) { IsOpacityVisible = false }; } else if (State == State.Configure) { Properties.Remove(Properties.Find("BarWidthUI", true)); Properties.Remove(Properties.Find("DownBrush", true)); Properties.Remove(Properties.Find("UpBrush", true)); SetPropertyName("Stroke", Custom.Resource.NinjaScriptChartStyleKagiThickLine); SetPropertyName("Stroke2", Custom.Resource.NinjaScriptChartStyleKagiThinLine); } }
public override void OnRender(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars) { Bars bars = chartBars.Bars; float barWidth = GetBarPaintWidth(BarWidthUI); RectangleF rect = new RectangleF(); for (int idx = chartBars.FromIndex; idx <= chartBars.ToIndex; idx++) { Brush overriddenBrush = chartControl.GetBarOverrideBrush(chartBars, idx); Brush overriddenOutlineBrush = chartControl.GetCandleOutlineOverrideBrush(chartBars, idx); double closeValue = bars.GetClose(idx); float close = chartScale.GetYByValue(closeValue); double openValue = bars.GetOpen(idx); float open = chartScale.GetYByValue(openValue); float x = chartControl.GetXByBarIndex(chartBars, idx); Gui.Stroke outlineStroke = closeValue >= openValue ? Stroke : Stroke2; rect.X = x - barWidth * 0.5f + 0.5f; rect.Y = Math.Min(open, close); rect.Width = barWidth - 1; rect.Height = Math.Max(open, close) - Math.Min(open, close); Brush b = overriddenBrush ?? (closeValue >= openValue ? UpBrushDX : DownBrushDX); if (!(b is SolidColorBrush)) { TransformBrush(b, rect); } RenderTarget.FillRectangle(rect, b); b = overriddenBrush ?? outlineStroke.BrushDX; if (!(b is SolidColorBrush)) { TransformBrush(b, rect); } RenderTarget.DrawRectangle(rect, overriddenOutlineBrush ?? outlineStroke.BrushDX, outlineStroke.Width, outlineStroke.StrokeStyle); } }