public static double GetPriceToBarsRatio(this ChartRectangle rectangle, Bars bars, Symbol symbol) { var verticalDelta = rectangle.GetPriceDelta(); var barsNumnber = rectangle.GetBarsNumber(bars, symbol); return(Math.Round(verticalDelta / barsNumnber, 10)); }
private void DrawOrUpdateVerticalLines(ChartRectangle rectangle, ChartTrendLine[] verticalLines) { var startBarIndex = rectangle.GetStartBarIndex(Chart.Bars, Chart.Symbol); var barsNumber = rectangle.GetBarsNumber(Chart.Bars, Chart.Symbol); var lineLevels = new double[] { barsNumber * 0.2, barsNumber * 0.4, barsNumber * 0.6, barsNumber * 0.8, }; var rectangleEndTime = rectangle.GetEndTime(); for (int i = 0; i < lineLevels.Length; i++) { var barIndex = startBarIndex + lineLevels[i]; var time = Chart.Bars.GetOpenTime(barIndex, Chart.Symbol); if (time > rectangleEndTime) { time = rectangleEndTime; } var verticalLine = verticalLines[i]; if (verticalLine == null) { var objectName = GetObjectName(string.Format("VerticalLine{0}", i + 1)); verticalLines[i] = Chart.DrawTrendLine(objectName, time, rectangle.Y1, time, rectangle.Y2, _settings.TimeLevelsColor, _settings.TimeLevelsThickness, _settings.TimeLevelsStyle); verticalLines[i].IsInteractive = true; verticalLines[i].IsLocked = true; } else { verticalLine.Time1 = time; verticalLine.Time2 = time; verticalLine.Y1 = rectangle.Y1; verticalLine.Y2 = rectangle.Y2; } } }
private void UpdateFans(ChartRectangle rectangle, ChartTrendLine[] fans) { var startTime = rectangle.GetStartTime(); var endTime = rectangle.GetEndTime(); var topPrice = rectangle.GetTopPrice(); var bottomPrice = rectangle.GetBottomPrice(); var rectanglePriceDelta = rectangle.GetPriceDelta(); var rectangleBarsNumber = rectangle.GetBarsNumber(Chart.Bars, Chart.Symbol); var startBarIndex = rectangle.GetStartBarIndex(Chart.Bars, Chart.Symbol); foreach (var fan in fans) { var fanName = fan.Name.Split('.').Last(); fan.Time1 = startTime; fan.Y1 = bottomPrice; switch (fanName) { case "1x1": fan.Time2 = endTime; fan.Y2 = topPrice; break; case "1x2": case "1x3": case "1x4": case "1x5": case "1x8": { fan.Y2 = topPrice; switch (fanName) { case "1x2": fan.Time2 = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 2), Chart.Symbol); break; case "1x3": fan.Time2 = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 3), Chart.Symbol); break; case "1x4": fan.Time2 = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 4), Chart.Symbol); break; case "1x5": fan.Time2 = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 5), Chart.Symbol); break; case "1x8": fan.Time2 = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 8), Chart.Symbol); break; } break; } case "2x1": case "3x1": case "4x1": case "5x1": case "8x1": { fan.Time2 = endTime; switch (fanName) { case "2x1": fan.Y2 = bottomPrice + (rectanglePriceDelta / 2); break; case "3x1": fan.Y2 = bottomPrice + (rectanglePriceDelta / 3); break; case "4x1": fan.Y2 = bottomPrice + (rectanglePriceDelta / 4); break; case "5x1": fan.Y2 = bottomPrice + (rectanglePriceDelta / 5); break; case "8x1": fan.Y2 = bottomPrice + (rectanglePriceDelta / 8); break; } break; } default: throw new ArgumentOutOfRangeException("level", "The fan name is outside valid range"); } } }
private void DrawLabels(ChartRectangle rectangle, long id) { DrawLabelText(Math.Round(rectangle.GetPriceDelta(), Chart.Symbol.Digits).ToNonScientificString(), rectangle.GetStartTime(), rectangle.GetTopPrice(), id, objectNameKey: "Price", fontSize: 10); DrawLabelText(rectangle.GetBarsNumber(Chart.Bars, Chart.Symbol).ToString(), rectangle.GetEndTime(), rectangle.GetBottomPrice(), id, objectNameKey: "BarsNumber", fontSize: 10); DrawLabelText(rectangle.GetPriceToBarsRatio(Chart.Bars, Chart.Symbol).ToNonScientificString(), rectangle.GetEndTime(), rectangle.GetTopPrice(), id, objectNameKey: "PriceToBarsRatio", fontSize: 10); }
private void DrawFans(ChartRectangle rectangle) { var startTime = rectangle.GetStartTime(); var endTime = rectangle.GetEndTime(); var topPrice = rectangle.GetTopPrice(); var bottomPrice = rectangle.GetBottomPrice(); var rectanglePriceDelta = rectangle.GetPriceDelta(); var rectangleBarsNumber = rectangle.GetBarsNumber(Chart.Bars, Chart.Symbol); var startBarIndex = rectangle.GetStartBarIndex(Chart.Bars, Chart.Symbol); var levels = new[] { 1, 2, 3, 4, 5, 8, -2, -3, -4, -5, -8 }; foreach (var level in levels) { string name = null; DateTime secondTime = endTime; double secondPrice = topPrice; switch (level) { case 1: name = "1x1"; secondTime = endTime; secondPrice = topPrice; break; case 2: case 3: case 4: case 5: case 8: { name = string.Format("1x{0}", level); secondPrice = topPrice; switch (level) { case 2: secondTime = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 2), Chart.Symbol); break; case 3: secondTime = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 3), Chart.Symbol); break; case 4: secondTime = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 4), Chart.Symbol); break; case 5: secondTime = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 5), Chart.Symbol); break; case 8: secondTime = Chart.Bars.GetOpenTime(startBarIndex + (rectangleBarsNumber / 8), Chart.Symbol); break; } break; } case -2: case -3: case -4: case -5: case -8: { name = string.Format("{0}x1", Math.Abs(level)); secondTime = endTime; switch (level) { case -2: secondPrice = bottomPrice + (rectanglePriceDelta / 2); break; case -3: secondPrice = bottomPrice + (rectanglePriceDelta / 3); break; case -4: secondPrice = bottomPrice + (rectanglePriceDelta / 4); break; case -5: secondPrice = bottomPrice + (rectanglePriceDelta / 5); break; case -8: secondPrice = bottomPrice + (rectanglePriceDelta / 8); break; } break; } default: throw new ArgumentOutOfRangeException("level", "The fan level is outside valid range"); } if (string.IsNullOrWhiteSpace(name)) { continue; } var objectName = GetObjectName(string.Format("Fan.{0}", name)); var trendLine = Chart.DrawTrendLine(objectName, startTime, bottomPrice, secondTime, secondPrice, _settings.FansColor, _settings.FansThickness, _settings.FansStyle); trendLine.IsInteractive = true; trendLine.IsLocked = true; _fans[name] = trendLine; } }