# Example_Addchartbubble_Addchart_Clouds_movavgcrosser
#
#
input show_arrows = yes;
input show_cross_clouds = yes;
input show_bubbles_up_dn = yes;
input show_bubbles_time = yes;
input price = close;
input length1 = 15;
input length2 = 30;
input averageType1 = AverageType.EXPONENTIAL;
input averageType2 = AverageType.EXPONENTIAL;
plot avg1 = MovingAverage(averageType1, price, length1);
plot avg2 = MovingAverage(averageType2, price, length2);
plot signalup = if avg1 crosses above avg2 then avg1 else Double.NaN;
plot signaldn = if avg1 crosses below avg2 then avg2 else Double.NaN;
signalup.SetDefaultColor(Color.GREEN);
signaldn.SetDefaultColor(Color.RED);
signalup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
signaldn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
signalup.SetHiding(!show_arrows);
signaldn.SetHiding(!show_arrows);
#Time defined
input timezone = {default "ET", "CT", "MT", "PT"};
def starthour = (if timezone == timezone."ET"
then 9
else if timezone == timezone."CT"
then 8
else if timezone == timezone."MT"
then 7
else 6) ;
def hour = Floor(((starthour * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def minutes = (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - starthour) * 60 + 30) + 60;
#
AddChartBubble(show_bubbles_up_dn and signalup, avg1 - TickSize() * 2, "UP", Color.GREEN, no);
AddChartBubble(show_bubbles_time and signalup, avg1 - TickSize() * 2, hour + ":" + (if minutes < 10
then "0" else "") + minutes, Color.WHITE, no);
AddChartBubble(show_bubbles_up_dn and signaldn, avg2 + TickSize() * 2, "DN", Color.RED, yes);
AddChartBubble(show_bubbles_time and signaldn, avg2 + TickSize() * 2, hour + ":" + (if minutes < 10
then "0" else "") + minutes, Color.WHITE, yes);
def up = signalup;
def dn = signaldn;
#Cloud
def uph = if IsNaN(up[-1]) and up
then Double.POSITIVE_INFINITY else Double.NaN;
def upl = if IsNaN(up[-1]) and up
then Double.NEGATIVE_INFINITY else Double.NaN;
def dnh = if IsNaN(dn[-1]) and dn
then Double.POSITIVE_INFINITY else Double.NaN;
def dnl = if IsNaN(dn[-1]) and dn
then Double.NEGATIVE_INFINITY else Double.NaN;
AddChart(if !show_cross_clouds then Double.NaN else uph, upl, uph, upl, ChartType.CANDLE, growColor = Color.GREEN);
AddChart(if !show_cross_clouds then Double.NaN else dnh, dnl, dnh, dnl, ChartType.CANDLE, growColor = Color.RED);