Windi-Scalper
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheWindicatorPro

//@version=4
study('Windi-scalp', overlay=true)
ema = ema(close, 200)
ema2 = ema(close, 100)
ema3 = ema(close, 50)
fast= ema(close,1)
plot(ema, color=color.new(color.red, 0))
plot(ema2, color=color.new(color.orange, 0))
plot(ema3, color=color.new(color.green, 0))

bull = ema > ema2
bull2 = ema2 > ema3

bear = ema < ema2
bear2 = ema2 < ema3

buy = bear and bear2
sell = bull and bull2

cross50 = cross(ema3, fast)
above= fast>ema3
bellow= fast<ema3
/////////////////////////

openBarPrevious = open[1]
closeBarPrevious = close[1]
openBarCurrent = open
closeBarCurrent = close

//If current bar open is less than equal to the previous bar close AND current bar open is less than previous bar open AND current bar close is greater than previous bar open THEN True
bullishEngulfing = openBarCurrent <= closeBarPrevious and openBarCurrent < openBarPrevious and 
   closeBarCurrent > openBarPrevious
//If current bar open is greater than equal to previous bar close AND current bar open is greater than previous bar open AND current bar close is less than previous bar open THEN True
bearishEngulfing = openBarCurrent >= closeBarPrevious and openBarCurrent > openBarPrevious and 
   closeBarCurrent < openBarPrevious

//bullishEngulfing/bearishEngulfing return a value of 1 or 0; if 1 then plot on chart, if 0 then don't plot
//plotshape(bullishEngulfing, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny)
//plotshape(bearishEngulfing, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)

alertcondition(bullishEngulfing, title="Bullish Engulfing", message="[CurrencyPair] [TimeFrame], Bullish candle engulfing previous candle")
alertcondition(bearishEngulfing, title="Bearish Engulfing", message="[CurrencyPair] [TimeFrame], Bearish candle engulfing previous candle")

sincebull= barssince(bullishEngulfing)
sincebear= barssince(bearishEngulfing)
allowup = sincebull <= 2
allowdown = sincebear <= 2
up= buy and allowup and cross50 and above
down= sell and allowdown and cross50 and bellow
plotshape(up, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny)
plotshape(down, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)


/////