Declare Lower;
#Designed by Henry Z Kaczmarczyk 1/2022
# GLOBAL DEFINITIONS
DefineGlobalColor("TrendUp", Color.Cyan);
DefineGlobalColor("TrendDown", Color.Magenta);
input agg = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;
input DotSize = 3;
Input APC = 7;
Input Labels = no;
input n = 20;
def n1 = n + 1;
input F2length = 2;
input F5length = 5;
input F8length = 8;
input F13length = 13;
input F21length = 21;
def CP = close(Period = AGG);
def VP = Volume(Period = AGG);
def CP2 = close(Period = AGG2);
def VP2 = Volume(Period = AGG2);
def CP3 = close(Period = AGG3);
def VP3 = Volume(Period = AGG3);
#Aggregation 1
Def FI2 = ExpAverage(data = (CP - CP[1]) * VP,F2length);
def Bullish2 = If FI2 >0 then 1 else 0;
def Bearish2 = FI2 < 0;
def Bullish2XL = FI2 crosses above 0;
def Bearish2XS = FI2 crosses Below 0;
plot FI2_Dot = if IsNaN(close) then Double.NaN else 1;
FI2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
FI2_Dot.SetLineWeight(DotSize);
FI2_Dot.AssignValueColor(if Bullish2 <1then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 1, (agg/1000/60) + " min", Color.Yellow, yes);
Def FI5 = ExpAverage(data = (CP - CP[1]) * VP,F5length);
def Bullish5 =If FI5 >0 then 1 else 0;
def Bearish5 = FI5 < 0;
def Bullish5XL = FI5 crosses above 0;
def Bearish5XS = FI5 crosses Below 0;
plot FI5_Dot = if IsNaN(close) then Double.NaN else 2;
FI5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
FI5_Dot.SetLineWeight(DotSize);
FI5_Dot.AssignValueColor(if Bullish5<1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 2, (agg/1000/60) + " min", Color.Yellow, yes);
Def FI8 = ExpAverage(data = (CP - CP[1]) * VP,F8length);
def Bullish8 = If FI8 >0 then 1 else 0;
def Bearish8 = FI8 < 0;
def Bullish8XL = FI8 crosses above 0;
def Bearish8XS = FI8 crosses Below 0;
plot FI8_Dot = if IsNaN(close) then Double.NaN else 3;
FI8_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
FI8_Dot.SetLineWeight(DotSize);
FI8_Dot.AssignValueColor(if Bullish8<1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 3, (agg/1000/60) + " min", Color.Yellow, yes);
Def FI13 = ExpAverage(data = (CP - CP[1]) * VP,F13length);
def Bullish13 = If FI13 >0 then 1 else 0;
def Bearish13 = FI13 < 0;
def Bullish13XL = FI13 crosses above 0;
def Bearish13XS = FI13 crosses Below 0;
plot FI13_Dot = if IsNaN(close) then Double.NaN else 4;
FI13_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
FI13_Dot.SetLineWeight(DotSize);
FI13_Dot.AssignValueColor(if Bullish13 <1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 4, (agg/1000/60) + " min", Color.Yellow, yes);
Def FI21 = ExpAverage(data = (CP - CP[1]) * VP,F21length);
def Bullish21 =If FI21 >0 then 1 else 0;
def Bearish21 = FI21 < 0;
def Bullish21XL = FI21 crosses above 0;
def Bearish21XS = FI21 crosses Below 0;
plot FI21_Dot = if IsNaN(close) then Double.NaN else 5;
FI21_Dot.SetPaintingStrategy(PaintingStrategy.Triangles);
FI21_Dot.SetLineWeight(DotSize);
FI21_Dot.AssignValueColor(if Bullish21<1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 5, (agg/1000/60) + " min", Color.Yellow, yes);
plot MTF_ADot = 6;
MTF_ADot.SetPaintingStrategy(PaintingStrategy.SQUARES);
MTF_ADot.SetLineWeight(lineWeight = 3);
MTF_ADot.DefineColor("Buy", Color.Green);
MTF_ADot.DefineColor("Sell", Color.red);
MTF_ADot.AssignValueColor ( if (Bullish2+ Bullish5 + Bullish8 + Bullish13+ Bullish21) >= 3 then MTF_ADot.Color("Buy") else MTF_ADot.Color("Sell"));
#Aggregation 2
Def A2FI2 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F2length);
def A2Bullish2 = If A2FI2 >0 then 1 else 0;
def A2Bearish2 = A2FI2<0;
def A2Bullish2XL = A2FI2 crosses above 0;
def A2Bearish2XS = A2FI2 crosses Below 0;
plot A2FI2_Dot = if IsNaN(close) then Double.NaN else 8;
A2FI2_Dot.SetPaintingStrategy(PaintingStrategy.Points);
A2FI2_Dot.SetLineWeight(DotSize+1);
A2FI2_Dot.AssignValueColor(if A2Bullish2< 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 8, (agg2/1000/60) + " min", Color.Yellow, yes);
Def A2FI5 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F5length);
def A2Bullish5 = If A2FI5 >0 then 1 else 0;
def A2Bearish5 = A2FI5<0;
def A2Bullish5XL = A2FI5 crosses above 0;
def A2Bearish5XS = A2FI5 crosses Below 0;
plot A2FI5_Dot = if IsNaN(close) then Double.NaN else 9;
A2FI5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2FI5_Dot.SetLineWeight(DotSize+1);
A2FI5_Dot.AssignValueColor(if A2Bullish5 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]),9, (agg2/1000/60) + " min", Color.Yellow, yes);
Def A2FI8 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F8length);
def A2Bullish8 = If A2FI8 >0 then 1 else 0;
def A2Bearish8 = A2FI8<0;
def A2Bullish8XL = A2FI8 crosses above 0;
def A2Bearish8XS = A2FI8 crosses Below 0;
plot A2FI8_Dot = if IsNaN(close) then Double.NaN else 10;
A2FI8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2FI8_Dot.SetLineWeight(DotSize+1);
A2FI8_Dot.AssignValueColor(if A2Bullish8 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]),10, (agg2/1000/60) + " min", Color.Yellow, yes);
Def A2FI13 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F13length);
def A2Bullish13 = if A2FI13 >0 then 1 else 0;
def A2Bearish13 = A2FI13<0;
def A2Bullish13XL = A2FI13 crosses above 0;
def A2Bearish13XS = A2FI13 crosses Below 0;
plot A2FI13_Dot = if IsNaN(close) then Double.NaN else 11;
A2FI13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2FI13_Dot.SetLineWeight(DotSize+1);
A2FI13_Dot.AssignValueColor(if A2Bullish13 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 11, (agg2/1000/60) + " min", Color.Yellow, yes);
Def A2FI21 = ExpAverage(data = (CP2 – CP2[1]) * VP2,F21length);
def A2Bullish21 = If A2FI21 >0 then 1 else 0;
def A2Bearish21 = A2FI21<0;
def A2Bullish21XL = A2FI21 crosses above 0;
def A2Bearish21XS = A2FI21 crosses Below 0;
plot A2FI21_Dot = if IsNaN(close) then Double.NaN else 12;
A2FI21_Dot.SetPaintingStrategy(PaintingStrategy.Points);
A2FI21_Dot.SetLineWeight(DotSize+1);
A2FI21_Dot.AssignValueColor(if A2Bullish21< 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 12, (agg2/1000/60) + " min", Color.Yellow, yes);
plot MTF_BDot = 13;
MTF_BDot.SetPaintingStrategy(PaintingStrategy.SQUARES);
MTF_BDot.SetLineWeight(lineWeight = 4);
MTF_BDot.DefineColor("Buy", Color.Green);
MTF_BDot.DefineColor("Sell", Color.red);
MTF_BDot.AssignValueColor ( if (A2Bullish2+ A2Bullish5 +A2Bullish8 + A2Bullish13+ A2Bullish21) >= 3 then MTF_BDot.Color("Buy") else MTF_BDot.Color("Sell"));
#Aggregation 3
Def A3FI2 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F2length);
def A3Bullish2 = If A3FI2 >0 then 1 else 0;
def A3Bearish2 = A3FI2<0;
def A3Bullish2XL = A3FI2 crosses above 0;
def A3Bearish2XS = A3FI2 crosses Below 0;
plot A3FI2_Dot = if IsNaN(close) then Double.NaN else 15;
A3FI2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI2_Dot.SetLineWeight(DotSize+2);
A3FI2_Dot.AssignValueColor(if A3Bullish2<1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 15, (agg3/1000/60) + " min", Color.Yellow, yes);
Def A3FI5 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F5length);
def A3Bullish5 = If A3FI5 >0 then 1 else 0;
def A3Bearish5 = A3FI5<0;
def A3Bullish5XL = A3FI5 crosses above 0;
def A3Bearish5XS = A3FI5 crosses Below 0;
plot A3FI5_Dot = if IsNaN(close) then Double.NaN else 16;
A3FI5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI5_Dot.SetLineWeight(DotSize+2);
A3FI5_Dot.AssignValueColor(if A3Bullish5< 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 16, (agg3/1000/60) + " min", Color.Yellow, yes);
Def A3FI8 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F8length);
def A3Bullish8 = If A3FI8 >0 then 1 else 0;
def A3Bearish8 = A3FI8<0;
def A3Bullish8XL = A3FI8 crosses above 0;
def A3Bearish8XS = A3FI8 crosses Below 0;
plot A3FI8_Dot = if IsNaN(close) then Double.NaN else 17;
A3FI8_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI8_Dot.SetLineWeight(DotSize+2);
A3FI8_Dot.AssignValueColor(if A3Bullish8 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 17, (agg3/1000/60) + " min", Color.Yellow, yes);
Def A3FI13 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F13length);
def A3Bullish13 = If A3FI13 >0then 1 else 0;
def A3Bearish13 = A3FI13<0;
def A3Bullish13XL = A3FI13 crosses above 0;
def A3Bearish13XS = A3FI13 crosses Below 0;
plot A3FI13_Dot = if IsNaN(close) then Double.NaN else 18;
A3FI13_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI13_Dot.SetLineWeight(DotSize+2);
A3FI13_Dot.AssignValueColor(if A3Bullish13 <1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 18, (agg3/1000/60) + " min", Color.Yellow, yes);
Def A3FI21 = ExpAverage(data = (CP3 – CP3[1]) * VP3,F21length);
def A3Bullish21 = If A3FI21 >0 then 1 else 0;
def A3Bearish21 = A3FI21<0;
def A3Bullish21XL = A3FI21 crosses above 0;
def A3Bearish21XS = A3FI21 crosses Below 0;
plot A3FI21_Dot = if IsNaN(close) then Double.NaN else 19;
A3FI21_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3FI21_Dot.SetLineWeight(DotSize+2);
A3FI21_Dot.AssignValueColor(if A3Bullish21 < 1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close [n1]) and IsNaN(Close [n]), 19, (agg3/1000/60) + " min", Color.Yellow, yes);
plot MTF_CDot = 20;
MTF_CDot.SetPaintingStrategy(PaintingStrategy.SQUARES);
MTF_CDot.SetLineWeight(lineWeight = 5);
MTF_CDot.DefineColor("Buy", Color.Green);
MTF_CDot.DefineColor("Sell", Color.red);
MTF_CDot.AssignValueColor ( if (A3Bullish2+ A3Bullish5 + A3Bullish8 + A3Bullish13+ A3Bullish21) >= 3 then MTF_CDot.Color("Buy") else MTF_CDot.Color("Sell"));
############ Labels
AddLabel(Labels == Yes And Bullish2, "Agg1.1 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish2XL, "Agg 1.1 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish2XS, "Agg 1.1 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish2, "Agg 1.1 Short" , Color.Red);
AddLabel(Labels == Yes And Bullish5, "Agg 1.2 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish5XL, "Agg 1.2 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish5XS, "Agg 1.2 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish5, "Agg 1.2 Short" , Color.Red);
AddLabel(Labels == Yes And Bullish8, "Agg1.3 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish8XL, "Agg 1.3 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish8XS, "Agg 1.3 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish8, "Agg 1.3 Short" , Color.Red);
AddLabel(Labels == Yes And Bullish13, "Agg1.4 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish13XL, "Agg 1.4 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish13XS, "Agg 1.4 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish13, "Agg 1.4 Short" , Color.Red);
AddLabel(Labels == Yes And Bullish21, "Agg1.5 Long " , Color.Green);
AddLabel(Labels == Yes And Bullish21XL, "Agg 1.5 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And Bearish21XS, "Agg 1.5 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And Bearish21, "Agg 1.5 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish2, "Agg2.1 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish2XL, "Agg 2.1 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish2XS, "Agg 2.1 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish2, "Agg 2.1 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish5, "Agg2.2 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish5XL, "Agg 2.2 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish5XS, "Agg 2.2 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish5, "Agg 2.2 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish8, "Agg 2.3 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish8XL, "Agg 2.3 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish8XS, "Agg 2.3 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish8, "Agg 2.3 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish13, "Agg 2.4 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish13XL, "Agg 2.4 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish13XS, "Agg 2.4 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish13, "Agg 2.4 Short" , Color.Red);
AddLabel(Labels == Yes And A2Bullish21, "Agg 2.5 Long " , Color.Green);
AddLabel(Labels == Yes And A2Bullish21XL, "Agg 2.5 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A2Bearish21XS, "Agg 2.5 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A2Bearish21, "Agg 2.5 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish2, "Agg 3.1 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish2XL, "Agg 3.1 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish2XS, "Agg 3.1 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish2, "Agg 3.1 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish5, "Agg 3.2 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish5XL, "Agg 3.2 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish5XS, "Agg 3.2 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish5, "Agg 3.2 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish8, "Agg 3.3 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish8XL, "Agg 3.3 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish8XS, "Agg 3.3 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish8, "Agg 3.3 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish13, "Agg 3.4 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish13XL, "Agg 3.4 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish13XS, "Agg 3.4 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish13, "Agg 3.4 Short" , Color.Red);
AddLabel(Labels == Yes And A3Bullish21, "Agg 3.5 Long " , Color.Green);
AddLabel(Labels == Yes And A3Bullish21XL, "Agg 3.5 Buy" , Color.Light_Green);
AddLabel(Labels == Yes And A3Bearish21XS, "Agg 3.5 Sell" , Color.Light_Red);
AddLabel(Labels == Yes And A3Bearish21, "Agg 3.5 Short" , Color.Red);
AssignPriceColor( if APC == 1 and FI2 >0 then Color.Cyan else if apc == 1 and FI2 < 0 then Color.Magenta else if APC == 2 and FI5 >0 then Color.Cyan else if APC == 2 and FI5 <0 then Color.Magenta else if APC == 3 and FI8 >0 then Color.Cyan else if APC == 3 and FI8 <0 then Color.Magenta else if APC == 4 and FI13 >0 then Color.Cyan else if APC == 4 and FI13 <0 then Color.Magenta else if APC == 5 and FI21 >0 then Color.Cyan else if APC == 5 and FI21 <0 then Color.Magenta else if APC == 6 and (Bullish2+ Bullish5 + Bullish8 + Bullish13+ Bullish21) >= 3 then Color.Green else if APC == 6 and (Bullish2+ Bullish5 + Bullish8 + Bullish13+ Bullish21) < 3 then Color.Red else if APC == 8 and A2FI2 >0 then Color.Cyan else if APC == 8 and A2FI2 <0 then Color.Magenta else if APC == 9 and A2FI5 >0 then Color.Cyan else if APC == 9 and A2FI5 <0 then Color.Magenta else if APC == 10 and A2FI8 >0 then Color.Cyan else if APC == 10 and A2FI8 <0 then Color.Magenta else if APC == 11 and A2FI13 >0 then Color.Cyan else if APC == 11 and A2FI13 <0 then Color.Magenta else if APC == 12 and A2FI21 >0 then Color.Cyan else if APC == 12 and A2FI21 <0 then Color.Magenta else if APC == 13 and
(A2Bullish2+ A2Bullish5 +A2Bullish8 + A2Bullish13+ A2Bullish21) >= 3 then Color.Green else if APC == 13 and (A2Bullish2+ A2Bullish5 +A2Bullish8 + A2Bullish13+ A2Bullish21) < 3 then Color.Magenta else if APC == 15 and A3FI2 >0 then Color.Cyan else if APC == 15 and A3FI2 <0 then Color.Magenta else if APC == 16 and A3FI5 >0 then Color.Cyan else if APC == 16 and A3FI5 <0 then Color.Magenta else if APC == 17 and A3FI8 >0 then Color.Cyan else if APC == 17 and A3FI8 <0 then Color.Magenta else if APC == 18 and A3FI13 >0 then Color.Cyan else if APC == 18 and A3FI13 <0 then Color.Magenta else if APC == 19 and A3FI21 >0 then Color.Cyan else if APC == 19 and A3FI21 <0 then Color.Magenta else if APC == 20 and (A3Bullish2+ A3Bullish5 + A3Bullish8 + A3Bullish13+ A3Bullish21) >= 3 then Color.Green else if APC == 20 and (A3Bullish2+ A3Bullish5 + A3Bullish8 + A3Bullish13+ A3Bullish21) < 3 then Color.Red else Color.Current);