# macd_mtf_labels
#https://usethinkscript.com/threads/mtf-trend-label.15204/
#MTF trend label
script macd1 {
input price = close;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
plot Value = MovingAverage(averageType, price, fastLength) - MovingAverage(averageType, price, slowLength);
plot avg = MovingAverage(averageType, Value, MACDLength);
plot Diff = Value - Avg;
};
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
#input showBreakoutSignals = no;
# 1D, 4H, 1H, 15M, 5M
#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------
input agg1 = AggregationPeriod.day;
input agg2 = AggregationPeriod.four_HOURs;
input agg3 = AggregationPeriod.HOUR;
input agg4 = AggregationPeriod.fifteen_min;
input agg5 = AggregationPeriod.five_min;
def agg1min = agg1/60000;
def agg2min = agg2/60000;
def agg3min = agg3/60000;
def agg4min = agg4/60000;
def agg5min = agg5/60000;
def price1 = close(period = agg1);
def price2 = close(period = agg2);
def price3 = close(period = agg3);
def price4 = close(period = agg4);
def price5 = close(period = agg5);
def m1v = macd1(price1, fastLength, slowLength, MACDLength, averageType).value;
def m2v = macd1(price2, fastLength, slowLength, MACDLength, averageType).value;
def m3v = macd1(price3, fastLength, slowLength, MACDLength, averageType).value;
def m4v = macd1(price4, fastLength, slowLength, MACDLength, averageType).value;
def m5v = macd1(price5, fastLength, slowLength, MACDLength, averageType).value;
def m1a = macd1(price1, fastLength, slowLength, MACDLength, averageType).avg;
def m2a = macd1(price2, fastLength, slowLength, MACDLength, averageType).avg;
def m3a = macd1(price3, fastLength, slowLength, MACDLength, averageType).avg;
def m4a = macd1(price4, fastLength, slowLength, MACDLength, averageType).avg;
def m5a = macd1(price5, fastLength, slowLength, MACDLength, averageType).avg;
def up1 = (m1v > m1a);
def up2 = (m2v > m2a);
def up3 = (m3v > m3a);
def up4 = (m4v > m4a);
def up5 = (m5v > m5a);
addlabel(1, " ", color.black);
addlabel(1, agg1min + " min MACD " + round(m1a,2) , (if up1 then color.green else color.red));
addlabel(1, agg2min + " min MACD " + round(m2a,2) , (if up2 then color.green else color.red));
addlabel(1, agg3min + " min MACD " + round(m3a,2) , (if up3 then color.green else color.red));
addlabel(1, agg4min + " min MACD " + round(m4a,2) , (if up4 then color.green else color.red));
addlabel(1, agg5min + " min MACD " + round(m5a,2) , (if up5 then color.green else color.red));
#