# average_labels_00
# several labels of average stats
def na = Double.NaN;
def bn = BarNumber();
input average1_len = 9;
input average1_type = AverageType.EXPONENTIAL;
input average1_agg_time = AggregationPeriod.DAY;
def agg1min = average1_agg_time/60000;
def avg1 = Round(MovingAverage(average1_type, close(period = average1_agg_time), average1_len), 2);
input average2_len = 21;
input average2_type = AverageType.EXPONENTIAL;
input average2_agg_time = AggregationPeriod.DAY;
def agg2min = average2_agg_time/60000;
def avg2 = Round(MovingAverage(average2_type, close(period = average2_agg_time), average2_len), 2);
input average3_len = 50;
input average3_type = AverageType.EXPONENTIAL;
input average3_agg_time = AggregationPeriod.DAY;
def agg3min = average3_agg_time/60000;
def avg3 = Round(MovingAverage(average3_type, close(period = average3_agg_time), average3_len), 2);
input average4_len = 100;
input average4_type = AverageType.EXPONENTIAL;
input average4_agg_time = AggregationPeriod.DAY;
def agg4min = average4_agg_time/60000;
def avg4 = Round(MovingAverage(average4_type, close(period = average2_agg_time), average4_len), 2);
#---------------------------
def avg1up = (avg1 > avg1[1]);
def avg2up = (avg2 > avg2[1]);
def avg3up = (avg3 > avg3[1]);
def avg4up = (avg4 > avg4[1]);
#---------------------------
input show_labels_1 = yes;
AddLabel(show_labels_1, " " , Color.BLACK);
AddLabel(show_labels_1, "Avg1 " + avg1, (if avg1up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg2 " + avg2, (if avg2up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg3 " + avg3, (if avg3up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, "Avg4 " + avg4, (if avg4up then Color.GREEN else Color.RED));
AddLabel(show_labels_1, " " , Color.BLACK);
#--------------------------
input show_labels_2 = yes;
AddLabel(show_labels_2, " " , Color.BLACK);
AddLabel(show_labels_2,
(if average1_type == AverageType.SIMPLE then "SMA"
else if average1_type == AverageType.EXPONENTIAL then "EMA"
else if average1_type == AverageType.WEIGHTED then "WT"
else if average1_type == AverageType.WILDERS then "WLD"
else if average1_type == AverageType.HULL then "HUL"
else "-")
+ average1_len + "(" +
(if agg1min < 60 then (agg1min + "m")
else if agg1min < 1440 then ((agg1min/60) + "H")
else if agg1min < 10080 then (agg1min/(60*24) + "D")
else if average1_type == aggregationPeriod.MONTH then "M"
else if average1_type == aggregationPeriod.WEEK then "W"
else "" ) + ")"
,(if avg1up then Color.GREEN else Color.RED));
AddLabel(show_labels_2,
(if average2_type == AverageType.SIMPLE then "SMA"
else if average2_type == AverageType.EXPONENTIAL then "EMA"
else if average2_type == AverageType.WEIGHTED then "WT"
else if average2_type == AverageType.WILDERS then "WLD"
else if average2_type == AverageType.HULL then "HUL"
else "-")
+ average2_len + "(" +
(if agg2min < 60 then (agg2min + "m")
else if agg2min < 1440 then ((agg2min/60) + "H")
else if agg2min < 10080 then (agg2min/(60*24) + "D")
else if average2_type == aggregationPeriod.MONTH then "M"
else if average2_type == aggregationPeriod.WEEK then "W"
else "" ) + ")"
,(if avg2up then Color.GREEN else Color.RED));
AddLabel(show_labels_2,
(if average3_type == AverageType.SIMPLE then "SMA"
else if average3_type == AverageType.EXPONENTIAL then "EMA"
else if average3_type == AverageType.WEIGHTED then "WT"
else if average3_type == AverageType.WILDERS then "WLD"
else if average3_type == AverageType.HULL then "HUL"
else "-")
+ average3_len + "(" +
(if agg3min < 60 then (agg1min + "m")
else if agg3min < 1440 then ((agg3min/60) + "H")
else if agg3min < 10080 then (agg3min/(60*24) + "D")
else if average3_type == aggregationPeriod.MONTH then "M"
else if average3_type == aggregationPeriod.WEEK then "W"
else "" ) + ")"
, (if avg3up then Color.GREEN else Color.RED));
AddLabel(show_labels_2,
(if average4_type == AverageType.SIMPLE then "SMA"
else if average4_type == AverageType.EXPONENTIAL then "EMA"
else if average4_type == AverageType.WEIGHTED then "WT"
else if average4_type == AverageType.WILDERS then "WLD"
else if average4_type == AverageType.HULL then "HUL"
else "-")
+ average4_len + "(" +
(if agg4min < 60 then (agg4min + "m")
else if agg4min < 1440 then ((agg4min/60) + "H")
else if agg4min < 10080 then (agg4min/(60*24) + "D")
else if average4_type == aggregationPeriod.MONTH then "M"
else if average4_type == aggregationPeriod.WEEK then "W"
else "" ) + ")"
, (if avg4up then Color.GREEN else Color.RED));
#----------------------------
input show_lines = yes;
plot z1 = if show_lines then avg1 else na;
z1.SetDefaultColor(GetColor(1));
#z1.setlineweight(1);
z1.HideBubble();
plot z2 = if show_lines then avg2 else na;
z2.SetDefaultColor(GetColor(2));
#z2.setlineweight(1);
z2.HideBubble();
plot z3 = if show_lines then avg3 else na;
z3.SetDefaultColor(GetColor(3));
#z3.setlineweight(1);
z3.HideBubble();
plot z4 = if show_lines then avg4 else na;
z4.SetDefaultColor(GetColor(4));
#z4.setlineweight(1);
z4.HideBubble();
#---------------------------
def stackup = (avg1 > avg2 and avg2 > avg3 and avg3 > avg4);
def stackdwn = (avg1 < avg2 and avg2 < avg3 and avg3 < avg4);
input show_stacked_averages_cloud = no;
AddCloud((if show_stacked_averages_cloud and stackup then avg1 else na), avg4, Color.LIGHT_GREEN, Color.MAGENTA);
AddCloud((if show_stacked_averages_cloud and stackdwn then avg4 else na), avg1, Color.LIGHT_RED, Color.MAGENTA);
#