#MTF_avgx_dots
#https://usethinkscript.com/threads/looking-for-traffic-lights-for-when-a-specific-moving-average-is-above-another-moving-average.20431/
#looking for traffic lights for when a specific moving average is above another moving average
# the 2Min, 5min, 10min, 15min, 30min, and 60min time periods.
def na = double.nan;
def bn = barnumber();
input agg1 = AggregationPeriod.TWO_MIN;
input agg2 = AggregationPeriod.FIVE_MIN;
input agg3 = AggregationPeriod.TEN_MIN;
input agg4 = AggregationPeriod.FIFTEEN_MIN;
input agg5 = AggregationPeriod.thirty_MIN;
input agg6 = AggregationPeriod.hour;
def chartagg = getaggregationperiod();
def chartmin = chartagg/60000;
# adjust aggs if too small
def agg1b;
if agg1 >= chartagg then {
agg1b = agg1;
} else {
agg1b = chartagg;
}
def agg1min = agg1/60000;
def agg2b;
if agg2 >= chartagg then {
agg2b = agg2;
} else {
agg2b = chartagg;
}
def agg2min = agg2/60000;
def agg3b;
if agg3 >= chartagg then {
agg3b = agg3;
} else {
agg3b = chartagg;
}
def agg3min = agg3/60000;
def agg4b;
if agg4 >= chartagg then {
agg4b = agg4;
} else {
agg4b = chartagg;
}
def agg4min = agg4/60000;
def agg5b;
if agg5 >= chartagg then {
agg5b = agg5;
} else {
agg5b = chartagg;
}
def agg5min = agg5/60000;
def agg6b;
if agg6 >= chartagg then {
agg6b = agg6;
} else {
agg6b = chartagg;
}
def agg6min = agg6/60000;
#Averages
input length1 = 10;
input length2 = 50;
#input avgtype = AverageType.EXPONENTIAL;
input avgtype1 = AverageType.simple;
input avgtype2 = AverageType.simple;
input price = Fundamentaltype.close;
def ma1_1 = MovingAverage(avgtype1, Fundamental(price, period = agg1b), length1);
def ma1_2 = MovingAverage(avgtype1, Fundamental(price, period = agg2b), length1);
def ma1_3 = MovingAverage(avgtype1, Fundamental(price, period = agg3b), length1);
def ma1_4 = MovingAverage(avgtype1, Fundamental(price, period = agg4b), length1);
def ma1_5 = MovingAverage(avgtype1, Fundamental(price, period = agg5b), length1);
def ma1_6 = MovingAverage(avgtype1, Fundamental(price, period = agg6b), length1);
def ma2_1 = MovingAverage(avgtype2, Fundamental(price, period = agg1b), length2);
def ma2_2 = MovingAverage(avgtype2, Fundamental(price, period = agg2b), length2);
def ma2_3 = MovingAverage(avgtype2, Fundamental(price, period = agg3b), length2);
def ma2_4 = MovingAverage(avgtype2, Fundamental(price, period = agg4b), length2);
def ma2_5 = MovingAverage(avgtype2, Fundamental(price, period = agg5b), length2);
def ma2_6 = MovingAverage(avgtype2, Fundamental(price, period = agg6b), length2);
input show_agg1_average_lines = no;
plot z1_1 = if show_agg1_average_lines then ma1_1 else na;
plot z2_1 = if show_agg1_average_lines then ma2_1 else na;
z1_1.SetDefaultColor(getcolor(0));
#z1_1.setlineweight(1);
z1_1.hidebubble();
z1_1.SetHiding(agg1 < chartagg);
z2_1.SetDefaultColor(getcolor(0));
#z2_1.setlineweight(1);
z2_1.hidebubble();
z2_1.SetHiding(agg1 < chartagg);
input show_agg2_average_lines = no;
plot z1_2 = if show_agg2_average_lines then ma1_2 else na;
plot z2_2 = if show_agg2_average_lines then ma2_2 else na;
z1_2.SetDefaultColor(getcolor(1));
#z1_2.setlineweight(1);
z1_2.hidebubble();
z1_2.SetHiding(agg2 < chartagg);
z2_2.SetDefaultColor(getcolor(1));
#z2_2.setlineweight(1);
z2_2.hidebubble();
z2_2.SetHiding(agg2 < chartagg);
input show_agg3_average_lines = no;
plot z1_3 = if show_agg3_average_lines then ma1_3 else na;
plot z2_3 = if show_agg3_average_lines then ma2_3 else na;
z1_3.SetDefaultColor(getcolor(2));
#z1_3.setlineweight(1);
z1_3.hidebubble();
z1_3.SetHiding(agg3 < chartagg);
z2_3.SetDefaultColor(getcolor(2));
#z2_3.setlineweight(1);
z2_3.hidebubble();
z2_3.SetHiding(agg3 < chartagg);
input show_agg4_average_lines = no;
plot z1_4 = if show_agg4_average_lines then ma1_4 else na;
plot z2_4 = if show_agg4_average_lines then ma2_4 else na;
z1_4.SetDefaultColor(getcolor(3));
#z1_4.setlineweight(1);
z1_4.hidebubble();
z1_4.SetHiding(agg4 < chartagg);
z2_4.SetDefaultColor(getcolor(3));
#z2_4.setlineweight(1);
z2_4.hidebubble();
z2_4.SetHiding(agg4 < chartagg);
input show_agg5_average_lines = no;
plot z1_5 = if show_agg5_average_lines then ma1_5 else na;
plot z2_5 = if show_agg5_average_lines then ma2_5 else na;
z1_5.SetDefaultColor(getcolor(4));
#z1_5.setlineweight(1);
z1_5.hidebubble();
z1_5.SetHiding(agg5 < chartagg);
z2_5.SetDefaultColor(getcolor(4));
#z2_5.setlineweight(1);
z2_5.hidebubble();
z2_5.SetHiding(agg5 < chartagg);
input show_agg6_average_lines = no;
plot z1_6 = if show_agg6_average_lines then ma1_6 else na;
plot z2_6 = if show_agg6_average_lines then ma2_6 else na;
z1_6.SetDefaultColor(getcolor(5));
#z1_6.setlineweight(1);
z1_6.hidebubble();
z1_6.SetHiding(agg6 < chartagg);
z2_6.SetDefaultColor(getcolor(5));
#z2_6.setlineweight(1);
z2_6.hidebubble();
z2_6.SetHiding(agg6 < chartagg);
#==================================
# labels
# average id labels
input ShowLabels = yes;
addlabel(1, " ", color.black);
addlabel(showlabels,
(if avgtype1 == AverageType.Simple then "SMA"
else if avgtype1 == AverageType.exponential then "EMA"
else if avgtype1 == AverageType.hull then "HULL"
else if avgtype1 == AverageType.weighted then "WT"
else if avgtype1 == AverageType.wilders then "WILD"
else "---") + length1
, color.cyan);
addlabel(showLabels,
(if avgtype2 == AverageType.Simple then "SMA"
else if avgtype2 == AverageType.exponential then "EMA"
else if avgtype2 == AverageType.hull then "HULL"
else if avgtype2 == AverageType.weighted then "WT"
else if avgtype2 == AverageType.wilders then "WILD"
else "---") + length2
, color.cyan);
addlabel(1, " ", color.black);
# MTF color labels , compare 2 avgs
#https://usethinkscript.com/threads/the-multi-10x-mtf-labels-indicator-for-thinkorswim.1129/page-4#post-69106
AddLabel(showlabels,
(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 agg1 < chartagg then color.dark_gray else if ma1_1 > ma2_1 then Color.GREEN else Color.RED));
AddLabel(showlabels,
(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 agg2 < chartagg then color.dark_gray else if ma1_2 > ma2_2 then Color.GREEN else Color.RED));
AddLabel(showlabels,
(if agg3min < 60 then (agg3min + " m")
else if agg3min < 1440 then ((agg3min / 60) + " H")
else if agg3min < 10080 then (agg3min / (60 * 24) + " D")
else "--"),
(if agg3 < chartagg then color.dark_gray else if ma1_3 > ma2_3 then Color.GREEN else Color.RED));
AddLabel(showlabels,
(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 agg4 < chartagg then color.dark_gray else if ma1_4 > ma2_4 then Color.GREEN else Color.RED));
AddLabel(showlabels,
(if agg5min < 60 then (agg5min + " m")
else if agg5min < 1440 then ((agg5min / 60) + " H")
else if agg5min < 10080 then (agg5min / (60 * 24) + " D")
else "--"),
(if agg5 < chartagg then color.dark_gray else if ma1_5 > ma2_5 then Color.GREEN else Color.RED));
AddLabel(showlabels,
(if agg6min < 60 then (agg6min + " m")
else if agg6min < 1440 then ((agg6min / 60) + " H")
else if agg6min < 10080 then (agg6min / (60 * 24) + " D")
else "--"),
(if agg6 < chartagg then color.dark_gray else if ma1_6 > ma2_6 then Color.GREEN else Color.RED));
addlabel(1, " ", color.black);
#