```
#Example EMA Cross Time Happened
#20171217 Sleepz modified 20210307
#Times seem to work on most intraday rth aggs currently except 4m, 20m and 1hr
input timezone = {default "ET", "CT", "MT", "PT"};
input rthbegin = 0930;
input rthend = 1600;
input labels = yes;
input timebubbles = yes;
input datebubbles = yes;
def CountActive = if SecondsTillTime(rthend) > 0 and SecondsFromTime(rthbegin) >= 0 then 1 else 0;
def StartBar = if SecondsFromTime(rthbegin) >= 0 and SecondsFromTime(rthbegin) < 2 then 1 else 0;
def BarStart = if StartBar then BarNumber() else BarStart[1];
def BarCount = if CountActive then BarNumber() - BarStart else Double.NaN;
def timehr = if (GetAggregationPeriod() / 60000 == 4 or GetAggregationPeriod() / 60000 == 20 or GetAggregationPeriod() / 60000 == 60)
then Double.NaN
else (if timezone == timezone."ET"
then 9
else if timezone == timezone."CT"
then 8
else if timezone == timezone."MT"
then 7
else 6) +
Round(BarCount / (60 / (GetAggregationPeriod() / 60000)) , 0);
def timemin = Round(60 * (.5 + (BarCount / 60 * GetAggregationPeriod() / 60000 - (Round(BarCount / 60 * GetAggregationPeriod() / 60000, 0)))), 0);
plot ema1 = ExpAverage(length = 8, data = close);
plot ema2 = ExpAverage(length = 13, data = close);
def cond = if Crosses(data1 = ema1, data2 = ema2) then 1 else 0;
def cross = if cond == 1 then Round(close) else cross[1];
def hihr = if CountActive and cond then timehr else hihr[1];
def himin = if CountActive and cond then timemin else himin[1];
plot cross_ = if cond == 1 then close else Double.NaN;
AddLabel(labels, "Last RTH EMA Cross" + " " +
(AsPrice(GetYYYYMMDD())) + " " +
(hihr + ":") +
(if himin < 10
then "0" + himin + " - " + asdollars(cross)
else "" + himin + " - " + asdollars(cross)) , if ema1 > ema2 then Color.GREEN else Color.RED);
AddChartBubble(timebubbles and !IsNaN(timehr) and IsNaN(cross_[1]) and cross_, ema1,
timehr + ":" + if timemin < 10
then "0" + timemin + " - " + asdollars(cross)
else "" + timemin + " - " + asdollars(cross), if ema1 > ema2 then Color.GREEN else Color.RED, if ema1 > ema2 then no else yes);
AddChartBubble(datebubbles and !IsNaN(timehr) and IsNaN(cross_[1]) and cross_, ema1,
AsPrice(GetYYYYMMDD()), Color.GRAY, if ema1 > ema2 then no else yes);
```