public TurnBar(TurnBar bar) { owner = bar.owner; IsKeyBar = bar.IsKeyBar; Name = bar.Name; candleIndexes = new List <int>(); candleIndexes.AddRange(bar.candleIndexes); }
public TurnBar(TurnBar bar) { owner = bar.owner; IsKeyBar = bar.IsKeyBar; Name = bar.Name; candleIndexes = new List<int>(); candleIndexes.AddRange(bar.candleIndexes); }
public override IChartInteractiveObject LoadObject(XmlElement objectNode, CandleChartControl owner, bool trimObjectsOutOfHistory = false) { var obj = new TurnBar(new List <int>(), true, Chart); obj.LoadFromXML(objectNode, owner); barsKey.Add(obj); return(obj); }
protected override void OnMouseDown(List <SeriesEditParameter> parameters, MouseEventArgs e, Keys modifierKeys, out IChartInteractiveObject objectToEdit) { objectToEdit = null; if (e.Button != MouseButtons.Left) { return; } // поставить или снять ключевой бар // получить время (свечку) var clientPoint = Chart.PointToScreen(new Point(e.X, e.Y)); clientPoint = Chart.StockPane.PointToClient(clientPoint); var pointD = Conversion.ScreenToWorld(new PointD(clientPoint.X, clientPoint.Y), Owner.WorldRect, Owner.CanvasRect); var index = (int)(pointD.X + 0.5); if (index >= Owner.StockSeries.Data.Count || index < 0) { return; } // найти ключевой бар на свечке var keyBar = barsKey.FirstOrDefault(b => b.candleIndexes.Contains(index)); if (keyBar != null) { // удалить ключевой бар barsKey.Remove(keyBar); CountTurnBars(); return; } // добавить новый бар var bar = new TurnBar(new List <int> { index }, true, Chart); barsKey.Add(bar); if (Owner.Owner.Owner.AdjustObjectColorsOnCreation) { bar.AjustColorScheme(Owner.Owner.Owner); } CountTurnBars(); }
private void MakeTurnBars(int[] ackDegArray) { TurnBar lastTurnBar = null; for (var i = 0; i < ackDegArray.Length; i++) { if (i >= Owner.StockSeries.Data.Count) { break; } var degree = ackDegArray[i]; var nextDegree = (ackDegArray.Length - i > 1) ? ackDegArray[i + 1] : 0; var prevDegree = (i > 0) ? ackDegArray[i - 1] : 0; if (degree < prevDegree) {// заканчиваем крайний бар if (lastTurnBar != null) { barsTurn.Add(lastTurnBar); } lastTurnBar = null; continue; } if (degree < fibonacciTurnBarFilter) { continue; } // если у соседнего бара степень подтверждения выше - берем соседний бар if (nextDegree > degree) { lastTurnBar = null; continue; } // если степень подтверждения равна предыдущему, бар еще не закончен if (prevDegree == degree && lastTurnBar != null) { lastTurnBar.candleIndexes.Add(i); continue; } // если степень подтверждения больше или равна предыдущей if (prevDegree <= degree) { lastTurnBar = new TurnBar(new List <int> { i }, false, Chart) { AckDegree = (degree - 1) }; continue; } } if (lastTurnBar != null) { barsTurn.Add(lastTurnBar); } // проставить разворотным барам время закрытия foreach (var bar in barsTurn.Where(b => !b.IsKeyBar)) { bar.CloseTime = Owner.StockSeries.Data.Candles[ bar.candleIndexes[bar.candleIndexes.Count - 1]].timeClose; } }
/// <summary> /// Отрисовать скобки вокруг разворотных баров /// </summary> private void DrawBar(TurnBar b, Graphics g, Font font, Pen pen, Brush brushFont, Brush brushWhite, Brush brushRed, RectangleD worldRect, Rectangle canvasRect) { float maxPrice = float.MinValue, minPrice = float.MaxValue; DateTime minTime = DateTime.MaxValue, maxTime = DateTime.MinValue; var candles = Owner.StockSeries.Data.Candles; foreach (var bar in b.candleIndexes) { var candle = candles[bar]; if (candle.open > maxPrice) { maxPrice = candle.open; } if (candle.close > maxPrice) { maxPrice = candle.close; } if (candle.open < minPrice) { minPrice = candle.open; } if (candle.close < minPrice) { minPrice = candle.close; } if (candle.timeOpen > maxTime) { maxTime = candle.timeOpen; } if (candle.timeOpen < minTime) { minTime = candle.timeOpen; } } double left = Chart.CandleRange.GetXCoord(minTime) - 0.5; double right = Chart.CandleRange.GetXCoord(maxTime) + 0.5; Point leftBotm = PointD.Round(Conversion.WorldToScreen(new PointD(left, (double)minPrice), worldRect, canvasRect)); Point rightTop = PointD.Round(Conversion.WorldToScreen(new PointD(right, (double)maxPrice), worldRect, canvasRect)); leftBotm.Y += 3; rightTop.Y -= 3; // bounds if (b.candleIndexes.Count > 1) { g.DrawLine(pen, leftBotm.X, leftBotm.Y, rightTop.X, leftBotm.Y); if ((rightTop.X - leftBotm.X) > 10) { g.DrawLine(pen, leftBotm.X, leftBotm.Y, leftBotm.X, leftBotm.Y - 4); g.DrawLine(pen, rightTop.X, leftBotm.Y, rightTop.X, leftBotm.Y - 4); } } // marker if (!b.IsKeyBar) { var s = ShowAckDegrees ? b.AckDegree.ToString() : "!"; var markerSz = g.MeasureString(s, font); g.FillRectangle(brushWhite, leftBotm.X - markerSz.Width, leftBotm.Y, markerSz.Width, markerSz.Height); g.DrawRectangle(pen, leftBotm.X - markerSz.Width, leftBotm.Y, markerSz.Width, markerSz.Height); g.DrawString(s, font, brushFont, leftBotm.X - markerSz.Width, leftBotm.Y); } else { const int markerX = (int)(SignalMarkerR * 0.7071); g.FillEllipse(brushRed, leftBotm.X - markerX, leftBotm.Y, markerX, markerX); g.DrawEllipse(pen, leftBotm.X - markerX, leftBotm.Y, markerX, markerX); } }
private void MakeTurnBars(int[] ackDegArray) { TurnBar lastTurnBar = null; for (var i = 0; i < ackDegArray.Length; i++) { if (i >= Owner.StockSeries.Data.Count) break; var degree = ackDegArray[i]; var nextDegree = (ackDegArray.Length - i > 1) ? ackDegArray[i + 1] : 0; var prevDegree = (i > 0) ? ackDegArray[i - 1] : 0; if (degree < prevDegree) {// заканчиваем крайний бар if (lastTurnBar != null) barsTurn.Add(lastTurnBar); lastTurnBar = null; continue; } if (degree < fibonacciTurnBarFilter) continue; // если у соседнего бара степень подтверждения выше - берем соседний бар if (nextDegree > degree) { lastTurnBar = null; continue; } // если степень подтверждения равна предыдущему, бар еще не закончен if (prevDegree == degree && lastTurnBar != null) { lastTurnBar.candleIndexes.Add(i); continue; } // если степень подтверждения больше или равна предыдущей if (prevDegree <= degree) { lastTurnBar = new TurnBar(new List<int> { i }, false, Chart) { AckDegree = (degree - 1) }; continue; } } if (lastTurnBar != null) barsTurn.Add(lastTurnBar); // проставить разворотным барам время закрытия foreach (var bar in barsTurn.Where(b => !b.IsKeyBar)) bar.CloseTime = Owner.StockSeries.Data.Candles[ bar.candleIndexes[bar.candleIndexes.Count - 1]].timeClose; }
/// <summary> /// Отрисовать скобки вокруг разворотных баров /// </summary> private void DrawBar(TurnBar b, Graphics g, Font font, Pen pen, Brush brushFont, Brush brushWhite, Brush brushRed, RectangleD worldRect, Rectangle canvasRect) { float maxPrice = float.MinValue, minPrice = float.MaxValue; DateTime minTime = DateTime.MaxValue, maxTime = DateTime.MinValue; var candles = Owner.StockSeries.Data.Candles; foreach (var bar in b.candleIndexes) { var candle = candles[bar]; if (candle.open > maxPrice) maxPrice = candle.open; if (candle.close > maxPrice) maxPrice = candle.close; if (candle.open < minPrice) minPrice = candle.open; if (candle.close < minPrice) minPrice = candle.close; if (candle.timeOpen > maxTime) maxTime = candle.timeOpen; if (candle.timeOpen < minTime) minTime = candle.timeOpen; } double left = Chart.CandleRange.GetXCoord(minTime) - 0.5; double right = Chart.CandleRange.GetXCoord(maxTime) + 0.5; Point leftBotm = PointD.Round(Conversion.WorldToScreen(new PointD(left, (double) minPrice), worldRect, canvasRect)); Point rightTop = PointD.Round(Conversion.WorldToScreen(new PointD(right, (double)maxPrice), worldRect, canvasRect)); leftBotm.Y += 3; rightTop.Y -= 3; // bounds if (b.candleIndexes.Count > 1) { g.DrawLine(pen, leftBotm.X, leftBotm.Y, rightTop.X, leftBotm.Y); if ((rightTop.X - leftBotm.X) > 10) { g.DrawLine(pen, leftBotm.X, leftBotm.Y, leftBotm.X, leftBotm.Y - 4); g.DrawLine(pen, rightTop.X, leftBotm.Y, rightTop.X, leftBotm.Y - 4); } } // marker if (!b.IsKeyBar) { var s = ShowAckDegrees ? b.AckDegree.ToString() : "!"; var markerSz = g.MeasureString(s, font); g.FillRectangle(brushWhite, leftBotm.X - markerSz.Width, leftBotm.Y, markerSz.Width, markerSz.Height); g.DrawRectangle(pen, leftBotm.X - markerSz.Width, leftBotm.Y, markerSz.Width, markerSz.Height); g.DrawString(s, font, brushFont, leftBotm.X - markerSz.Width, leftBotm.Y); } else { const int markerX = (int)(SignalMarkerR * 0.7071); g.FillEllipse(brushRed, leftBotm.X - markerX, leftBotm.Y, markerX, markerX); g.DrawEllipse(pen, leftBotm.X - markerX, leftBotm.Y, markerX, markerX); } }
protected override void OnMouseDown(List<SeriesEditParameter> parameters, MouseEventArgs e, Keys modifierKeys, out IChartInteractiveObject objectToEdit) { objectToEdit = null; if (e.Button != MouseButtons.Left) return; // поставить или снять ключевой бар // получить время (свечку) var clientPoint = Chart.PointToScreen(new Point(e.X, e.Y)); clientPoint = Chart.StockPane.PointToClient(clientPoint); var pointD = Conversion.ScreenToWorld(new PointD(clientPoint.X, clientPoint.Y), Owner.WorldRect, Owner.CanvasRect); var index = (int)(pointD.X + 0.5); if (index >= Owner.StockSeries.Data.Count || index < 0) return; // найти ключевой бар на свечке var keyBar = barsKey.FirstOrDefault(b => b.candleIndexes.Contains(index)); if (keyBar != null) { // удалить ключевой бар barsKey.Remove(keyBar); CountTurnBars(); return; } // добавить новый бар var bar = new TurnBar(new List<int> {index}, true, Chart); barsKey.Add(bar); if (Owner.Owner.Owner.AdjustObjectColorsOnCreation) bar.AjustColorScheme(Owner.Owner.Owner); CountTurnBars(); }
public override IChartInteractiveObject LoadObject(XmlElement objectNode, CandleChartControl owner, bool trimObjectsOutOfHistory = false) { var obj = new TurnBar(new List<int>(), true, Chart); obj.LoadFromXML(objectNode, owner); barsKey.Add(obj); return obj; }