# MACD MTF
# Modified by tomsk
# 11.9.2019
declare lower;
input Agg1 = AggregationPeriod.THREE_MIN;
input Agg2 = AggregationPeriod.FIVE_MIN;
input Agg3 = AggregationPeriod.FIFTEEN_MIN;
input Agg4 = AggregationPeriod.Thirty_MIN;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
DefineGlobalColor("UpTrend", Color.GREEN);
DefineGlobalColor("DownTrend", Color.MAGENTA);
# Aggregation 1
def Value1 = MovingAverage(averageType, close(period = Agg1), fastLength) -
MovingAverage(averageType, close(period = Agg1), slowLength);
def Avg1 = MovingAverage(averageType, Value1, MACDLength);
def Diff1 = Value1 – Avg1;
def MACDAgg1 = if Diff1 > 0 then 1 else if Diff1 < 0 then -1 else 0;
plot MACD1 = if IsNaN(close) then Double.NaN else 1;
MACD1.SetPaintingStrategy(PaintingStrategy.POINTS);
MACD1.SetLineWeight(2);
MACD1.AssignValueColor(if MACDAgg1 == 1 then GlobalColor("UpTrend") else GlobalColor("DownTrend"));
# Aggregation 2
def Value2 = MovingAverage(averageType, close(period = Agg2), fastLength) -
MovingAverage(averageType, close(period = Agg2), slowLength);
def Avg2 = MovingAverage(averageType, Value2, MACDLength);
def Diff2 = Value2 – Avg2;
def MACDAgg2 = if Diff2 > 0 then 1 else if Diff2 < 0 then -1 else 0;
plot MACD2 = if IsNaN(close) then Double.NaN else 2;
MACD2.SetPaintingStrategy(PaintingStrategy.POINTS);
MACD2.SetLineWeight(2);
MACD2.AssignValueColor(if MACDAgg2 == 1 then GlobalColor("UpTrend") else GlobalColor("DownTrend"));
# Aggregation 3
def Value3 = MovingAverage(averageType, close(period = Agg3), fastLength) -
MovingAverage(averageType,close(period = Agg3), slowLength);
def Avg3 = MovingAverage(averageType, Value3, MACDLength);
def Diff3 = Value3 – Avg3;
def MACDAgg3 = if Diff3 > 0 then 1 else if Diff3 < 0 then -1 else 0;
plot MACD3 = if IsNaN(close) then Double.NaN else 3;
MACD3.SetPaintingStrategy(PaintingStrategy.POINTS);
MACD3.SetLineWeight(2);
MACD3.AssignValueColor(if MACDAgg3 == 1 then GlobalColor("UpTrend") else GlobalColor("DownTrend"));
# Aggregation 4
def Value4 = MovingAverage(averageType, close(period = Agg4), fastLength) -
MovingAverage(averageType,close(period = Agg4), slowLength);
def Avg4 = MovingAverage(averageType, Value4, MACDLength);
def Diff4 = Value4 – Avg4;
def MACDAgg4 = if Diff4 > 0 then 1 else if Diff4 < 0 then -1 else 0;
plot MACD4 = if IsNaN(close) then Double.NaN else 4;
MACD4.SetPaintingStrategy(PaintingStrategy.POINTS);
MACD4.SetLineWeight(2);
MACD4.AssignValueColor(if MACDAgg4 == 1 then GlobalColor("UpTrend") else GlobalColor("DownTrend"));