/// <summary> /// Returns True if connecting two provided data point based on cross direction is possible otherwise False /// </summary> /// <param name="bars"></param> /// <param name="firstPointIndex">The first point index in market series</param> /// <param name="secondPointIndex">The second point index in market series</param> /// <param name="direction">The line direction, is it on up direction or low direction?</param> /// <returns>bool</returns> public static bool IsBodyConnectionPossible(this Bars bars, int firstPointIndex, int secondPointIndex, Direction direction) { if (firstPointIndex >= secondPointIndex) { throw new ArgumentException("The 'firstPointIndex' must be less than 'secondPointIndex'"); } double slope = bars.GetBodyBaseSlope(firstPointIndex, secondPointIndex, direction); double firstPoint; if (direction == Direction.Up) { firstPoint = bars.GetBarBodyLow(firstPointIndex); } else if (direction == Direction.Down) { firstPoint = bars.GetBarBodyHigh(firstPointIndex); } else { throw new InvalidOperationException("Invalid Direction Type"); } var counter = 0; for (var i = firstPointIndex + 1; i <= secondPointIndex; i++) { counter++; double iPoint; if (direction == Direction.Up) { iPoint = bars.GetBarBodyLow(i); if (iPoint < firstPoint + slope * counter) { return(false); } } else if (direction == Direction.Down) { iPoint = bars.GetBarBodyHigh(i); if (iPoint > firstPoint + slope * counter) { return(false); } } } return(true); }