public static void RefelectOnOtherLine(this ChartTrendLine line, ChartTrendLine otherLine, Bars bars, Symbol symbol) { var onePercentFirstBarIndex = bars.GetBarIndex(otherLine.Time1, symbol); var zeroLineBarsDelta = line.GetBarsNumber(bars, symbol); var zeroLinePriceDelta = line.GetPriceDelta(); var zeroLineSlope = line.GetSlope(); double secondBarIndex, secondPrice; if (line.Time1 < line.Time2) { secondBarIndex = onePercentFirstBarIndex + zeroLineBarsDelta; secondPrice = zeroLineSlope > 0 ? otherLine.Y1 + zeroLinePriceDelta : otherLine.Y1 - zeroLinePriceDelta; } else { secondBarIndex = onePercentFirstBarIndex - zeroLineBarsDelta; secondPrice = zeroLineSlope > 0 ? otherLine.Y1 - zeroLinePriceDelta : otherLine.Y1 + zeroLinePriceDelta; } otherLine.Time2 = bars.GetOpenTime(secondBarIndex, symbol); otherLine.Y2 = secondPrice; }
protected override void DrawSideFans(ChartTrendLine mainFan) { if (MouseUpNumber < 2) { return; } var endBarIndex = Chart.Bars.GetBarIndex(mainFan.Time2, Chart.Symbol); var barsDelta = _handleLine.GetBarsNumber(Chart.Bars, Chart.Symbol) / 2; var priceDelta = _handleLine.GetPriceDelta() / 2; var slope = _handleLine.GetSlope(); for (var iFan = 0; iFan < SideFanSettings.Length; iFan++) { var fanSettings = SideFanSettings[iFan]; var secondBarIndex = slope > 0 ? endBarIndex + barsDelta * fanSettings.Percent : endBarIndex - barsDelta * fanSettings.Percent; var secondTime = Chart.Bars.GetOpenTime(secondBarIndex, Chart.Symbol); var secondPrice = mainFan.Y2 + priceDelta * fanSettings.Percent; var objectName = GetObjectName(string.Format("SideFan_{0}", fanSettings.Percent)); var trendLine = Chart.DrawTrendLine(objectName, mainFan.Time1, mainFan.Y1, secondTime, secondPrice, fanSettings.Color, fanSettings.Thickness, fanSettings.Style); trendLine.IsInteractive = true; trendLine.IsLocked = true; trendLine.ExtendToInfinity = true; SideFanLines[fanSettings.Percent] = trendLine; } }
private void UpdateFans(ChartTrendLine mainFan, ChartTrendLine handleLine, Dictionary <double, ChartTrendLine> fans) { var endBarIndex = Chart.Bars.GetBarIndex(mainFan.Time2, Chart.Symbol); var barsDelta = handleLine.GetBarsNumber(Chart.Bars, Chart.Symbol) / 2; var priceDelta = handleLine.GetPriceDelta() / 2; var slope = handleLine.GetSlope(); foreach (var fan in fans) { var fanSettings = SideFanSettings.FirstOrDefault(iSettings => iSettings.Percent == fan.Key); if (fanSettings == null) { continue; } var secondBarIndex = slope > 0 ? endBarIndex + barsDelta * fanSettings.Percent : endBarIndex - barsDelta * fanSettings.Percent; var secondTime = Chart.Bars.GetOpenTime(secondBarIndex, Chart.Symbol); var secondPrice = mainFan.Y2 + priceDelta * fanSettings.Percent; var fanLine = fan.Value; fanLine.Time1 = mainFan.Time1; fanLine.Time2 = secondTime; fanLine.Y1 = mainFan.Y1; fanLine.Y2 = secondPrice; } }
private void UpdateLines(ChartTrendLine zeroLine, ChartTrendLine onePercentLine, ChartTrendLine updatedLine, long id) { if (updatedLine == zeroLine) { zeroLine.RefelectOnOtherLine(onePercentLine, Chart.Bars, Chart.Symbol); } else { onePercentLine.RefelectOnOtherLine(zeroLine, Chart.Bars, Chart.Symbol); } DrawFibonacciLevels(zeroLine, onePercentLine, zeroLine.GetSlope(), id, updateMainLineStlyes: false); }
private void DrawPercentLevels(ChartTrendLine medianLine, ChartTrendLine handleLine, long id) { var medianLineSecondBarIndex = Chart.Bars.GetBarIndex(medianLine.Time2, Chart.Symbol); var handleLineFirstBarIndex = Chart.Bars.GetBarIndex(handleLine.Time1, Chart.Symbol); var barsDelta = Math.Abs(medianLineSecondBarIndex - handleLineFirstBarIndex); var lengthInMinutes = Math.Abs((medianLine.Time2 - handleLine.Time1).TotalMinutes) * 2; var priceDelta = handleLine.GetPriceDelta() / 2; var handleLineSlope = handleLine.GetSlope(); foreach (var levelSettings in _levelsSettings) { DrawLevel(medianLine, medianLineSecondBarIndex, barsDelta, lengthInMinutes, priceDelta, handleLineSlope, levelSettings.Value.Percent, levelSettings.Value.LineColor, id); DrawLevel(medianLine, medianLineSecondBarIndex, barsDelta, lengthInMinutes, priceDelta, handleLineSlope, -levelSettings.Value.Percent, levelSettings.Value.LineColor, id); } }
private void UpdateHandleLine(ChartTrendLine handleLine, ChartTrendLine mainFan) { var mainFanSecondBarIndex = Chart.Bars.GetBarIndex(mainFan.Time2, Chart.Symbol); var handleLineHalfBarsNumber = handleLine.GetBarsNumber(Chart.Bars, Chart.Symbol) / 2; var firstBarIndex = mainFanSecondBarIndex - handleLineHalfBarsNumber; var secondBarIndex = mainFanSecondBarIndex + handleLineHalfBarsNumber; handleLine.Time1 = Chart.Bars.GetOpenTime(firstBarIndex, Chart.Symbol); handleLine.Time2 = Chart.Bars.GetOpenTime(secondBarIndex, Chart.Symbol); var handleLineHalfPriceDelta = handleLine.GetPriceDelta() / 2; var handleLineSlope = handleLine.GetSlope(); handleLine.Y1 = handleLineSlope > 0 ? mainFan.Y2 - handleLineHalfPriceDelta : mainFan.Y2 + handleLineHalfPriceDelta; handleLine.Y2 = handleLineSlope > 0 ? mainFan.Y2 + handleLineHalfPriceDelta : mainFan.Y2 - handleLineHalfPriceDelta; }
protected override void OnMouseMove(ChartMouseEventArgs obj) { if (MouseUpNumber == 1) { _zeroLine.Time2 = obj.TimeValue; _zeroLine.Y2 = obj.YValue; } else if (MouseUpNumber == 2 && _zeroLine != null) { var onePercentLineName = GetObjectName("OnePercentLine"); var onePercentFirstBarIndex = Chart.Bars.GetBarIndex(obj.TimeValue, Chart.Symbol); var zeroLineBarsDelta = _zeroLine.GetBarsNumber(Chart.Bars, Chart.Symbol); var zeroLinePriceDelta = _zeroLine.GetPriceDelta(); var zeroLineSlope = _zeroLine.GetSlope(); double secondBarIndex, secondPrice; if (_zeroLine.Time1 < _zeroLine.Time2) { secondBarIndex = onePercentFirstBarIndex + zeroLineBarsDelta; secondPrice = zeroLineSlope > 0 ? obj.YValue + zeroLinePriceDelta : obj.YValue - zeroLinePriceDelta; } else { secondBarIndex = onePercentFirstBarIndex - zeroLineBarsDelta; secondPrice = zeroLineSlope > 0 ? obj.YValue - zeroLinePriceDelta : obj.YValue + zeroLinePriceDelta; } _onePercentLine = Chart.DrawTrendLine(onePercentLineName, obj.TimeValue, obj.YValue, Chart.Bars.GetOpenTime(secondBarIndex, Chart.Symbol), secondPrice, Color, 1, LineStyle.Dots); _onePercentLine.IsInteractive = true; var levellines = DrawFibonacciLevels(_zeroLine, _onePercentLine, zeroLineSlope, Id); foreach (var levelLine in levellines) { _otherLevelLines[levelLine.Key] = levelLine.Value; } } }