How to code Candle end?

I want to code a ema crossover in which either the candle end or the next candle is taken into consideration and then a alert is generated.

you can write EMA crossover based on CLOSE of the candle 

example

EMA(CLOSE,20),EMA(CLOSE,50))