MultiUsage_Library
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TitinhoAmorim

//@version=5


library("MultiUse_Library", overlay = true)

// @BULLISH ENGULFING CANDLE DETECTOR
// Checks if Bullish Engulfing Candle Found
// {

// @INPUT PARAMETERS
// bool DetectEngulf   (TRUE if wants to detect engulfing candles)
//                     (FALSE if doesn't to detect engulfing candles)

// bool EngulfLastWick (TRUE if current close must engulf last wick)
//                     (FALSE if current close mustn't engulf last wick)


// @OUTPUT PARAMETERS
// isBullishEC         (TRUE if Bullish Engulfing Candle is detected
//                     (FALSE if Bullish Engulfing Candle isn't detected)


export BullEC(bool DetectEngulf, bool EngulfLastWick) =>
    NormalBullEC    = (open[1] > close[1]) and (close[0] > open[0]) and (close[0] > open[1])
    WickBullEC      = (open[1] > close[1]) and (close[0] > open[0]) and (close[0] > high[1])
    isBullishEC     = (DetectEngulf == true) ? (EngulfLastWick == false) ? WickBullEC : NormalBullEC : na

// }


// @BEARISH ENGULFING CANDLE DETECTOR
// Checks if Bearish Engulfing Candle Found
// {

// @INPUT PARAMETERS
// bool DetectEngulf   (TRUE if wants to detect engulfing candles)
//                     (FALSE if doesn't to detect engulfing candles)

// bool EngulfLastWick (TRUE if current close must engulf last wick)
//                     (FALSE if current close mustn't engulf last wick)

// @OUTPUT PARAMETERS
// isBearishEC         (TRUE if Bearish Engulfing Candle is detected
//                     (FALSE if Bearish Engulfing Candle isn't detected)

export BearEC(bool DetectEngulf, bool EngulfLastWick) =>
    NormalBearEC    = (open[1] < close[1]) and (close[0] < open[0]) and (close[0] < open[1])
    WickBearEC      = (open[1] < close[1]) and (close[0] < open[0]) and (close[0] < low[1])
    isBearishEC     = (DetectEngulf == true) ? (EngulfLastWick == false) ? WickBearEC : NormalBearEC : na

// }