#MTF_avgx_dots_02
#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
#FreefallJM03 1/24 #1
#Is there a way to do this for the 10 SMA being above the 50 SMA and for the 10 SMA being below the 50 SMA?
#in a watchlist or put this into stoplights at the top of a chart for,
# 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;
input agg7 = AggregationPeriod.two_hours;
input agg8 = AggregationPeriod.four_hours;
input agg9 = AggregationPeriod.day;
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;
def agg7b;
if agg7 >= chartagg then {
agg7b = agg7;
} else {
agg7b = chartagg;
}
def agg7min = agg7/60000;
def agg8b;
if agg8 >= chartagg then {
agg8b = agg8;
} else {
agg8b = chartagg;
}
def agg8min = agg8/60000;
def agg9b;
if agg9 >= chartagg then {
agg9b = agg9;
} else {
agg9b = chartagg;
}
def agg9min = agg9/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 ma1_7 = MovingAverage(avgtype1, Fundamental(price, period = agg7b), length1);
def ma1_8 = MovingAverage(avgtype1, Fundamental(price, period = agg8b), length1);
def ma1_9 = MovingAverage(avgtype1, Fundamental(price, period = agg9b), 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);
def ma2_7 = MovingAverage(avgtype2, Fundamental(price, period = agg7b), length2);
def ma2_8 = MovingAverage(avgtype2, Fundamental(price, period = agg8b), length2);
def ma2_9 = MovingAverage(avgtype2, Fundamental(price, period = agg9b), 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);
input show_agg7_average_lines = no;
plot z1_7 = if show_agg7_average_lines then ma1_7 else na;
plot z2_7 = if show_agg7_average_lines then ma2_7 else na;
z1_7.SetDefaultColor(getcolor(5));
#z1_7.setlineweight(1);
z1_7.hidebubble();
z1_7.SetHiding(agg7 < chartagg);
z2_7.SetDefaultColor(getcolor(5));
#z2_7.setlineweight(1);
z2_7.hidebubble();
z2_7.SetHiding(agg7 < chartagg);
input show_agg8_average_lines = no;
plot z1_8 = if show_agg8_average_lines then ma1_8 else na;
plot z2_8 = if show_agg8_average_lines then ma2_8 else na;
z1_8.SetDefaultColor(getcolor(5));
#z1_8.setlineweight(1);
z1_8.hidebubble();
z1_8.SetHiding(agg8 < chartagg);
z2_8.SetDefaultColor(getcolor(5));
#z2_8.setlineweight(1);
z2_8.hidebubble();
z2_8.SetHiding(agg8 < chartagg);
input show_agg9_average_lines = no;
plot z1_9 = if show_agg9_average_lines then ma1_9 else na;
plot z2_9 = if show_agg9_average_lines then ma2_9 else na;
z1_9.SetDefaultColor(getcolor(5));
#z1_9.setlineweight(1);
z1_9.hidebubble();
z1_9.SetHiding(agg9 < chartagg);
z2_9.SetDefaultColor(getcolor(5));
#z2_9.setlineweight(1);
z2_9.hidebubble();
z2_9.SetHiding(agg9 < 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(showlabels,
(if agg7min < 60 then (agg7min + " m")
else if agg7min < 1440 then ((agg7min / 60) + " H")
else if agg7min < 10080 then (agg7min / (60 * 24) + " D")
else "--"),
(if agg7 < chartagg then color.dark_gray else if ma1_7 > ma2_7 then Color.GREEN else Color.RED));
AddLabel(showlabels,
(if agg8min < 60 then (agg8min + " m")
else if agg8min < 1440 then ((agg8min / 60) + " H")
else if agg8min < 10080 then (agg8min / (60 * 24) + " D")
else "--"),
(if agg8 < chartagg then color.dark_gray else if ma1_8 > ma2_8 then Color.GREEN else Color.RED));
AddLabel(showlabels,
(if agg9min < 60 then (agg9min + " m")
else if agg9min < 1440 then ((agg9min / 60) + " H")
else if agg9min < 10080 then (agg9min / (60 * 24) + " D")
else "--"),
(if agg9 < chartagg then color.dark_gray else if ma1_9 > ma2_9 then Color.GREEN else Color.RED));
addlabel(1, " ", color.black);
#==================================
# dots
#----------------------
# ref level for rows of dots
#price_line
#https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# Line At Price Mobius
#def back = 1000;
#def d = if !IsNaN(close) and IsNaN(close[-1]) then close else d[1];
#plot line1 = if isNaN(close[-back]) then d[-back] else Double.NaN;
#----------------------
# ----------------------------
#https://usethinkscript.com/threads/the-multi-10x-mtf-labels-indicator-for-thinkorswim.1129/page-4#post-69106
#def agg2 = GetAggregationPeriod();
#def agg2min = agg2 / 60000;
#AddLabel(0,
#(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 == AggregationPeriod.WEEK then "W"
# else if agg2 == AggregationPeriod.MONTH then "M"
# else ""),
# Color.CYAN);
#addlabel(1, "chart min " + agg2/60000, color.cyan);
#