/// <summary> /// Рисует блок состоящий из нескольких свечей /// </summary> /// <param name="prepHorV"></param> /// <param name="max"></param> /// <param name="countInBlock"></param> private void PaintOneBlock(PrepareHorVol prepHorV, Chart max, int countInBlock) { var canvas = Panel.GetGraphics; var canvasOnlyVol = PanelVolume.GetGraphics; if (prepHorV.RectBlock.Width >= MIN_WIDTH_FOR_LAYBORDER) { //рисует прямоугольник выделяющий период var rectVol = new RectDraw(); rectVol.ColorFill = ColorLayVol; rectVol.ColorBorder = ColorLayBorder; rectVol.Paint(canvas, prepHorV.RectBlock.X, prepHorV.RectBlock.Y, prepHorV.RectBlock.Width, prepHorV.RectBlock.Height); var textMax = new TextDraw(); textMax.Color = Color.Black; var text = "max:" + prepHorV.MaxVol.ToString(); var size = textMax.GetSizeText(canvas, text); textMax.Paint(canvas, text, prepHorV.RectBlock.X, prepHorV.RectBlock.Y - size.Height); } prepHorV.HorVolumes.ToArray().ForEach <ChartFull>((hv) => { this.PaintLineHVol(canvas, prepHorV.RectBlock, max, new Chart(), hv); if (PaintOnlyFirstBlock) { this.PaintLineHVol(canvasOnlyVol, PanelVolume.Rect.Rectangle, max, new Chart(), hv, Color.Blue); } }); }
private void PaintLevelRectangle() { var rectSel = new RectDraw(); rectSel.ColorBorder = Color.FromArgb(100, Color.Blue); rectSel.ColorFill = Color.FromArgb(50, Color.Red); rectSel.WidthBorder = 2.0f; int x1 = 0, y1 = 0, height = 0; height = CrossPoint.Y - ActiveCandles.ActiveCandle1.coordClick.Y; height = height < 0 ? height * -1 : height; if (ActiveCandles.ActiveCandle1.coordClick.X > CrossPoint.X) { x1 = CrossPoint.X; } else { x1 = ActiveCandles.ActiveCandle1.dataCandle.TailCoord.High.X; } if (ActiveCandles.ActiveCandle1.coordClick.Y > CrossPoint.Y) { y1 = CrossPoint.Y; } else { y1 = ActiveCandles.ActiveCandle1.coordClick.Y; } var width = CrossPoint.X - ActiveCandles.ActiveCandle1.dataCandle.TailCoord.High.X; width = width < 0 ? width * -1 : width; rectSel.Paint(Canvas, x1, y1, width, height); }
private void Start() { Input.simulateMouseWithTouches = false; validAreaCollider = GetComponent <CompositeCollider2D>(); rectDraw = FindObjectOfType <RectDraw>(); fixedForegroundTilemap = GameObject.FindGameObjectWithTag("Fixed Foreground").GetComponent <Tilemap>(); toolbarBackground = GameObject.FindGameObjectWithTag("Drawing Toolbar").GetComponent <RectTransform>(); levelControlBackground = GameObject.FindGameObjectWithTag("Level Control Toolbar").GetComponent <RectTransform>(); levelController = FindObjectOfType <LevelController>(); }
/// <summary> /// Отрисовка одного уровня /// </summary> /// <param name="canvas"></param> /// <param name="rectPaint"></param> /// <param name="Value"></param> /// <param name="index"></param> private void PaintOneLevel(Graphics canvas, Chart level, CandleInfo candle, bool paintLast = false) { int Y1 = GMath.GetCoordinate(Panel.Rect.Height, this.Max, this.Min, level.Volume > 0 ? level.Volume : 0); int Y2 = GMath.GetCoordinate(Panel.Rect.Height, this.Max, this.Min, level.Volume < 0 ? level.Volume : 0); float bodyWidth = candle.Body.Width < MAX_WIDTH ? candle.Body.Width : MAX_WIDTH;//Panel.Params.WidthCandle - Panel.Params.MarginCandle; //-2 чтобы свечки не слипались int bodyHeight = Y2 - Y1; int bodyX = (int)(candle.Body.X + (candle.Body.Width / 2) - (bodyWidth / 2)); int bodyY = Y1; //bodyHeight = bodyHeight - bodyY; bodyHeight = bodyHeight == 0 ? bodyHeight + 1 : bodyHeight; var rect = new RectDraw(); if (candle.Index != 0 || paintLast) { var Color = ValuePositive; if (candle.Candle.Close < candle.Candle.Open) { Color = ValueNegative; } rect.Paint(canvas, bodyX, bodyY, bodyWidth, bodyHeight, Color, Color); } var data = new DataLevel() { PaintRect = Panel.Rect.Rectangle, Value = level.Volume, MaxValue = this.Max, MinValue = this.Min, Index = candle.Index, DataPaint = rect, Body = new RectangleF(bodyX, bodyY, bodyWidth, bodyHeight) }; if (data.NotIsNull()) { if (data.Index == 1) { this.AllDataLevels.RemoveAll(l => l.Index == data.Index); AllDataLevels.Insert(0, data); } else { AllDataLevels.Add(data); } } }
public override void FastUpdate() { Panel.Clear(); if (!IsEnable()) { return; } if (ListTrades.NotIsNull() && ListTrades.Count() > 0) { var canvas = Panel.GetGraphics; //Устанавливаем первую уоординату + смещение float XlastTrade = Panel.Rect.Width - 40; var textVol = new TextDraw(); textVol.SetFontSize(6); textVol.Color = Color.Black; foreach (var trade in ListTrades) { int width = 4; int Height = 4; SizeF sizeText; float xPlusText = 0; float yPlusText = 0; if (MinVolumeShow <= trade.Volume) { sizeText = textVol.GetSizeText(canvas, trade.Volume.ToString()); width = Height = (int)(sizeText.Width * 2); xPlusText = (width - sizeText.Width) / 2; yPlusText = (Height - sizeText.Height) / 2; } XlastTrade = XlastTrade - width; float yPrice = (float)GetYByPrice(trade.Price); var rect = new RectDraw(); var colorCandle = trade.Direction == OrderDirection.Buy ? Color.LightGreen : Color.LightCoral; var colorBorder = Color.Black; rect.Paint(canvas, XlastTrade, yPrice - Height / 2, width, Height, colorBorder, colorCandle); if (MinVolumeShow <= trade.Volume) { textVol.Paint(canvas, trade.Volume.ToString(), XlastTrade + xPlusText, (yPrice - Height / 2) + yPlusText); } } } }
/// <summary> /// Прорисовка прямоугольника выделенного периода /// </summary> private void PaintRectSelectPeriod() { if (CrossPoint.X > 0 && ActiveCandles.ActiveCandle1.NotIsNull() && ActiveCandles.ActiveCandle2.IsNull() && ActiveCandles.statusSel()) { //Режим указания уровня if (Levels.TypeLevel == LevelsFree.TYPE_LEVELS.Vector) { PaintLevelHorVector(); } else if (Levels.TypeLevel == LevelsFree.TYPE_LEVELS.Rectangle) { PaintLevelRectangle(); } else { var rectSel = new RectDraw(); rectSel.ColorBorder = Color.FromArgb(100, Color.Black); rectSel.ColorFill = Color.FromArgb(50, Color.Blue); var x = ActiveCandles.ActiveCandle1.dataCandle.TailCoord.High.X > CrossPoint.X ? CrossPoint.X : ActiveCandles.ActiveCandle1.dataCandle.TailCoord.High.X; var width = CrossPoint.X - ActiveCandles.ActiveCandle1.dataCandle.TailCoord.High.X; int y1Line = 0, y2Line = 0; if (width < 0) { width = width * -1; y2Line = ActiveCandles.ActiveCandle1.coordClick.Y; y1Line = CrossPoint.Y; } else { y1Line = ActiveCandles.ActiveCandle1.coordClick.Y; y2Line = CrossPoint.Y; } rectSel.Paint(Canvas, x, Candels.Panel.Rect.Y, width, Candels.Panel.Rect.Height); var line = new Line(); line.Width = 1; line.Paint(Canvas, new PointF(x, y1Line), new PointF(x + width, y2Line), Color.Red); } } }
/// <summary> /// Рисует уровень ввиде свободного прямоугольника /// </summary> /// <param name="g"></param> /// <param name="rect"></param> /// <param name="lev"></param> /// <param name="widthLine"></param> private void PaintRectangleLevel(Graphics g, Rectangle rect, DoubleLevel lev, float widthLine = 1) { int yTop = GMath.GetCoordinate(rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, lev.Top); int yBot = GMath.GetCoordinate(rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, lev.Bottom); if (yBot < 0 && yTop > 0) { yBot = rect.Y + rect.Height; } if (yTop < 0 && yBot > 0) { yTop = rect.Y; } var height = yBot - yTop; if (height <= 0) { return; } var rectLev = new RectDraw(); rectLev.ColorBorder = Color.FromArgb(100, Color.Black); rectLev.ColorFill = Color.FromArgb(40, Color.Blue); rectLev.WidthBorder = widthLine; rectLev.Paint(g, rect.X, yTop, rect.Width, height); var middleLine = new Line(); middleLine.Width = 1; middleLine.Style = System.Drawing.Drawing2D.DashStyle.Dot; middleLine.Paint(g, new PointF(rect.X, yTop + height / 2), new PointF(rect.X + rect.Width, yTop + height / 2), Color.FromArgb(100, Color.Black)); var topText = new TextDraw(); var dataText = topText.GetSizeText(g, lev.Top.ToString()); int HeightText = (int)dataText.Height; if (height > HeightText * 3 && rect.Width > dataText.Width) { topText.Paint(g, lev.Top.ToString(), rect.X, yTop); topText.Paint(g, lev.Bottom.ToString(), rect.X, yBot - HeightText); } }
private void BtnRectDraw_OnClick(object sender, RoutedEventArgs e) { rectDraw = new RectDraw(); rectDraw.Start(); }
/// <summary> Рисует одну свечку </summary> /// <param name="canvas"></param> /// <param name="rectPaint"></param> /// <param name="candleData"></param> /// <param name="index"></param> /// <param name="maxPrice"></param> /// <param name="minPrice"></param> private CandleInfo PaintOneCandle(Graphics canvas, ViewPanel panel, CandleData candleData, int index, bool paint = true) { int tailY1 = GMath.GetCoordinate(panel.Rect.Height, panel.Params.MaxPrice, panel.Params.MinPrice, candleData.High); int tailY2 = GMath.GetCoordinate(panel.Rect.Height, panel.Params.MaxPrice, panel.Params.MinPrice, candleData.Low); int tailX1 = (int)((panel.Rect.Width - panel.Params.WidthCandle * index) + panel.Params.WidthCandle / 2); int bodyX = (int)(panel.Rect.Width - panel.Params.WidthCandle * index); int bodyY = GMath.GetCoordinate(panel.Rect.Height, panel.Params.MaxPrice, panel.Params.MinPrice, candleData.Open > candleData.Close ? candleData.Open : candleData.Close); float bodyWidth = panel.Params.WidthCandle - MarginCandle > 0.3f ? panel.Params.WidthCandle - MarginCandle : 0.3f; //- чтобы свечки не слипались int bodyHeight = GMath.GetCoordinate(panel.Rect.Height, panel.Params.MaxPrice, panel.Params.MinPrice, candleData.Open < candleData.Close ? candleData.Open : candleData.Close); bodyHeight = bodyHeight - bodyY; bodyHeight = bodyHeight == 0 ? bodyHeight + 1 : bodyHeight; //tail var line = new Line(); line.Width = 1.5f; if (paint) { line.Paint(canvas, new Point(tailX1, tailY1), new Point(tailX1, tailY2), ColorBorderCandle); } //Body var rect = new RectDraw(); var colorCandle = candleData.Open > candleData.Close ? ColorFallCandle : ColorGrowCandle; var colorBorder = ColorBorderCandle; /*if (candleData.Open < candleData.Close && candleData.VolumeBuy - candleData.VolumeSell > 0) * { * colorBorder = colorCandle = Color.DarkGreen; * } * if (candleData.Open > candleData.Close && candleData.VolumeBuy - candleData.VolumeSell < 0) * { * colorBorder = colorCandle = Color.DarkRed; * }*/ if (paint) { rect.Paint(canvas, bodyX, bodyY, bodyWidth, bodyHeight, colorBorder, colorCandle); } if (MaxValues.MinCandle.IsNull()) { MaxValues.MinCandle = candleData; } if (MaxValues.MaxCandle.IsNull()) { MaxValues.MaxCandle = candleData; } if (MaxValues.MaxPrice < candleData.High) { MaxValues.MaxPrice = candleData.High; MaxValues.MaxCandle = candleData; } if (MaxValues.MinPrice > candleData.Low) { MaxValues.MinPrice = candleData.Low; MaxValues.MinCandle = candleData; } /*if (candleData.HorVolumes.HVolCollection.MaxVolume.NotIsNull()) * { * if (MaxValues.MaxHorVolume.Volume < candleData.HorVolumes.HVolCollection.MaxVolume.Volume) * { * MaxValues.MaxHorVolume = candleData.HorVolumes.HVolCollection.MaxVolume; * } * }*/ var dCandle = new CandleInfo() { PaintRect = panel.Rect.Rectangle, Candle = candleData, TailCoord = new TailCoord() { Low = new Point(tailX1, tailY2), High = new Point(tailX1, tailY1) }, Body = new RectangleF() { X = bodyX, Y = bodyY, Width = bodyWidth, Height = bodyHeight }, Index = index - 1, MaxHorVolume = MaxValues.MaxHorVolume, TimeFrame = CurrentTimeFrame }; VerticalLines[index - 1] = dCandle.TailCoord.High.X; if (index == 1) { AllDataPaintedCandle.RemoveAll(c => c.Index == index - 1); AllDataPaintedCandle.Insert(0, dCandle); } else { AllDataPaintedCandle.Add(dCandle); } if (OnPaintedCandle.NotIsNull()) { OnPaintedCandle(dCandle); } return(dCandle); }
/// <summary> /// Рисует линию горизонтального объема /// </summary> private int PaintLineHVol(Graphics canvas, RectangleF rect, Chart maxElem, Chart minElem, ChartFull hv, Color?colorVol = null, bool isDelta = false) { var widthLayoutVolume = rect.Width; var value = hv.VolBuy + hv.VolSell; if (isDelta) { value = hv.VolBuy - hv.VolSell; } float y = GMath.GetCoordinate(Panel.Rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, hv.Price); var height = GMath.GetCoordinate(Panel.Rect.Height, Panel.Params.MaxPrice, Panel.Params.MinPrice, hv.Price - Panel.Params.MinStepPrice) - y; if (y == 0 || y == Panel.Rect.Height) { return(-1); } int x1 = 0, x2 = 0; if (value < 0) { x1 = GMath.GetCoordinate(widthLayoutVolume, maxElem.Volume, minElem.Volume, value); x2 = GMath.GetCoordinate(widthLayoutVolume, maxElem.Volume, minElem.Volume, 0); } else { x1 = GMath.GetCoordinate(widthLayoutVolume, maxElem.Volume, minElem.Volume, 0); x2 = GMath.GetCoordinate(widthLayoutVolume, maxElem.Volume, minElem.Volume, value); } var p1 = new PointF(rect.X + widthLayoutVolume - x1, y); var p2 = new PointF(rect.X + widthLayoutVolume - x2, y); RectDraw rectVol = new RectDraw(); var color = ColorVol; if (isDelta) { if (value < 0) { color = this.ColorDeltaNegative; } else { color = this.ColorDeltaPositive; } } if (maxElem.Price == hv.Price) { color = ColorMaxVol; } if (minElem.Price == hv.Price) { color = ColorMaxVol; } if (colorVol.NotIsNull()) { color = (Color)colorVol; } rectVol.ColorBorder = color; rectVol.ColorFill = color; rectVol.Paint(canvas, p1.X, y - height / 2, p2.X - p1.X, height - 1 <= 0 ? 1 : height - 1); return(0); }
public void PaintHorVolByPeriodCandleDelta(bool alwaysUpdate = false, bool delta = false, long limitBorder = 0) { lock (_lockPaint) { if (PrepDataHorVol.IsNull()) { return; } if (activeCandle1.IsNull() || activeCandle2.IsNull()) { return; } Panel.Clear(); PanelVolume.Clear(); if (!CreateBlockHorVolume()) { return; } var canvas = Panel.GetGraphics; var canvasOnlyVol = PanelVolume.GetGraphics; var countCandleInVol = PrepDataHorVol.index1 - PrepDataHorVol.index2 + 1; var xLineBorder = activeCandle2.dataCandle.Body.X + activeCandle2.dataCandle.Body.Width; RectangleF rectPaint = new RectangleF(); rectPaint.X = activeCandle1.dataCandle.Body.X; rectPaint.Width = xLineBorder - activeCandle1.dataCandle.Body.X; rectPaint.Width = rectPaint.Width < 40 ? 40 : rectPaint.Width; rectPaint.Y = activeCandle1.dataCandle.TailCoord.Low.Y; rectPaint.Height = 0; rectPaint.Y = rectPaint.Y - 13; rectPaint.Height = rectPaint.Height + 13; //рисует прямоугольник выделяющий период var rectVol = new RectDraw(); rectVol.ColorFill = ColorLayVol; rectVol.ColorBorder = ColorLayBorder; rectVol.Paint(canvas, rectPaint.X, Panel.Rect.Y, rectPaint.Width, Panel.Rect.Height); //Получяаем максимальный гор. объем в свече или наборе свечей PrepDataHorVol.HorVolumes.ToArray().ForEach <ChartFull>((hv) => { PaintLineHVol(canvas, rectPaint, PrepDataHorVol.MaxElem, new Chart(), hv); if (delta) { Chart maxDelta, minDelta = null; if (limitBorder > 0) { maxDelta = new Chart() { Price = PrepDataHorVol.MaxDeltaElem.Price, Volume = PrepDataHorVol.MaxDeltaElem.Volume > limitBorder ? PrepDataHorVol.MaxDeltaElem.Volume : limitBorder }; minDelta = new Chart() { Price = PrepDataHorVol.MinDeltaElem.Price, Volume = PrepDataHorVol.MinDeltaElem.Volume < limitBorder * -1 ? PrepDataHorVol.MinDeltaElem.Volume : limitBorder * -1 }; } else { maxDelta = PrepDataHorVol.MaxDeltaElem; minDelta = PrepDataHorVol.MinDeltaElem; } PaintLineHVol(canvasOnlyVol, PanelVolume.Rect.Rectangle, maxDelta, minDelta, hv, null, true); var d = hv.VolBuy - hv.VolSell; if (d > 0) { PrepDataHorVol.SumDeltaBuy += d; } else { PrepDataHorVol.SumDeltaSell += d * -1; } } else { PaintLineHVol(canvasOnlyVol, PanelVolume.Rect.Rectangle, PrepDataHorVol.MaxElem, new Chart(), hv); } PrepDataHorVol.SumBuyVol += hv.VolBuy; PrepDataHorVol.SumSellVol += hv.VolSell; }); var textMax = new TextDraw(); textMax.Color = Color.Black; textMax.Paint(canvas, "V:" + (PrepDataHorVol.SumBuyVol + PrepDataHorVol.SumSellVol).ToString() + "\r\n" + "D:" + (PrepDataHorVol.SumBuyVol - PrepDataHorVol.SumSellVol).ToString() + "\r\n" + "max:" + PrepDataHorVol.MaxVol.ToString() + "\r\n" + "p:" + PrepDataHorVol.MaxElem.Price.ToString(), rectPaint.X, Panel.Rect.Y); if (delta) { textMax.Paint(canvasOnlyVol, "max: " + PrepDataHorVol.MinDeltaElem.Volume.ToString() + "/" + PrepDataHorVol.MaxDeltaElem.Volume.ToString() + "\r\n" + "sum: " + PrepDataHorVol.SumDeltaSell.ToString() + "/" + PrepDataHorVol.SumDeltaBuy.ToString() + "\r\n" , this.RectForDelta.X, this.RectForDelta.Y); } else { textMax.Paint(canvasOnlyVol, "max: " + PrepDataHorVol.MaxElem.Volume.ToString() + "\r\n" + "sum: " + (PrepDataHorVol.SumSellVol + PrepDataHorVol.SumBuyVol).ToString() + "\r\n" + "sum S/B: " + PrepDataHorVol.SumSellVol.ToString() + "/" + PrepDataHorVol.SumBuyVol.ToString() + "\r\n" , this.RectForDelta.X, this.RectForDelta.Y); } } }