/// <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); }
/// <summary> /// Returns the amount of slope between two level in a market series based on bar bodies /// </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"></param> /// <returns>double</returns> public static double GetBodyBaseSlope(this Bars bars, int firstPointIndex, int secondPointIndex, Direction direction) { double firstPoint, secondPoint; if (direction == Direction.Up) { firstPoint = bars.GetBarBodyLow(firstPointIndex); secondPoint = bars.GetBarBodyLow(secondPointIndex); } else if (direction == Direction.Down) { firstPoint = bars.GetBarBodyHigh(firstPointIndex); secondPoint = bars.GetBarBodyHigh(secondPointIndex); } else { throw new InvalidOperationException("Invalid Direction Type"); } return((secondPoint - firstPoint) / (secondPointIndex - firstPointIndex)); }