/// <summary> /// Checks to see if Candle Stick is Bearish or Bullish /// </summary> /// <param name="candle">The candlestick that you want to check.</param> /// <returns>Returns the animal type of the candle</returns> public static AnimalType CheckAnimalType(CandleBody candle) { var bodyType = CheckBodyType(candle); var bodyColor = CheckBodyColor(candle); var topShadow = CheckTopShadow(candle); var bottomShadow = CheckBottomShadow(candle); if (bodyType == BodyType.Long && bodyColor == BodyColor.White) { return(AnimalType.Bull); } if (bodyType == BodyType.Long && bodyColor == BodyColor.Black) { return(AnimalType.Bear); } if (bottomShadow == BottomShadow.Long && topShadow == TopShadow.Short) { return(AnimalType.Bull); } if (bottomShadow == BottomShadow.Short && topShadow == TopShadow.Long) { return(AnimalType.Bear); } return(AnimalType.NoAnimal); }
/// <summary> /// Gets the Body Type of a Candle. /// </summary> /// <param name="candle">Candle that you want to check the body type of</param> /// <returns>Returns the Enum body type of the candle</returns> public static BodyColor CheckBodyColor(CandleBody candle) { if (candle.OpenPrice > candle.ClosePrice) { return(BodyColor.Black); } else { return(BodyColor.White); } }
/// <summary> /// Converts Heikin Ashi into CandleBody. /// </summary> /// <param name="haCandle">The Heikin Ashi candlestick that you want to convert into a CandleBody object</param> /// <returns>Returns CandleBody object</returns> public static CandleBody ConvertHaCandle(HeikinAshi haCandle) { var candle = new CandleBody { OpenPrice = haCandle.HA_Open, HighPrice = haCandle.HA_High, LowPrice = haCandle.HA_Low, ClosePrice = haCandle.HA_Close }; return(candle); }
/// <summary> /// Creates a Heikin Ashi Candle /// </summary> /// <param name="current">The latest Candlestick in the series</param> /// <param name="previous">The previous Candlestick in the series</param> /// <returns>Returns a Heikin Ashi Candles</returns> public HeikinAshi(CandleBody current, CandleBody previous) { var currentCandle = current; var previousCandle = previous; HA_Close = (currentCandle.OpenPrice + currentCandle.ClosePrice + currentCandle.HighPrice + currentCandle.LowPrice) / 4; HA_Open = (previousCandle.OpenPrice + previousCandle.ClosePrice) / 2; Elements = new List <double> { currentCandle.HighPrice, currentCandle.LowPrice, HA_Open, HA_Close }; HA_High = Elements.Max(); HA_Low = Elements.Min(); }
/// <summary> /// Checks the length of a Candle /// </summary> /// <param name="candle">The Candle you want to check the size for.</param> /// <returns>Returns the size of the Candle Stick</returns> public static BodyType CheckBodyType(CandleBody candle) { var averageBody = ((candle.ClosePrice + candle.OpenPrice + candle.HighPrice + candle.LowPrice) / 4) * 1.3; var body = Math.Abs(candle.OpenPrice - candle.ClosePrice); if (body > averageBody) { return(BodyType.Long); } else { return(BodyType.Short); } }
/// <summary> /// Gets the Top Shadow of a Candle Stick /// </summary> /// <param name="candle">The candlestick that you want to check shadow for.</param> /// <returns>Determines whether or not the candle stick has a long or short top shadow</returns> public static TopShadow CheckTopShadow(CandleBody candle) { double body; double topShadow; var candleColor = CheckBodyColor(candle); if (candleColor == BodyColor.Black) { body = Math.Abs(candle.OpenPrice - candle.ClosePrice); topShadow = candle.HighPrice - candle.OpenPrice; if (topShadow > body) { return(TopShadow.Long); } if (Math.Abs(candle.HighPrice - candle.OpenPrice) < 0.01) { return(TopShadow.NoShadow); } } if (candleColor == BodyColor.White) { body = candle.OpenPrice - candle.ClosePrice; topShadow = candle.HighPrice - candle.ClosePrice; if (topShadow > body) { return(TopShadow.Long); } if (Math.Abs(candle.HighPrice - candle.ClosePrice) < 0.01) { return(TopShadow.NoShadow); } } return(TopShadow.Short); }