Rally Candle (End Game )  26/04/2022 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MINTYFRESH97

//@version=5
indicator("Rallie Candle (2)" ,overlay=true )

//swing high/low filter
swingHigh = high == ta.highest(high,6) or high[1] == ta.highest(high,6)

//user input
var g_ema    = "EMA Filter"
emaLength    = input.int(title="EMA Length", defval=50, tooltip="Length of the EMA filter", group=g_ema)
useEmaFilter = input.bool(title="Use EMA Filter?", defval=false, tooltip="Turns on/off the EMA filter", group=g_ema)

// Get EMA filter
ema = ta.ema(close, emaLength)
emaFilterLong = not useEmaFilter or close > ema
emaFilterShort = not useEmaFilter or close < ema


//DETECT MARUBUZO

upUpDownCloses = (close[3] > close[4]) and (close[2] > close[3]) and
     (close < close[1]) and emaFilterShort and swingHigh
     
// Plot our candle patterns
barcolor(upUpDownCloses ? color.blue :na)
plotshape(upUpDownCloses, style=shape.diamond,size=size.tiny, color=color.red, text="R",location=location.abovebar)
alertcondition(upUpDownCloses, "RallieCandle", "RallieCandle detected for {{ticker}}")