Declare Lower;
input Period1 = 3;
input Period2 = 5;
input Period3 = 8;
input Period4 = 10;
input Period5 = 12;
input Period6 = 15;
input Period7 = 30;
input Period8 = 35;
input Period9 = 40;
input Period10 = 45;
input Period11 = 50;
input Period12 = 60;
input Dotsize = 3;
input Paintbars =0;
def T1 = Sum(High, Period1) / Period1;
def B1 = Sum(Low, Period1) / Period1;
def A1=(T1+B1)/2;
def T2 = Sum(High, Period2) / Period2;
def B2 = Sum(Low, Period2) / Period2;
def A2=(T2+B2)/2;
def T3 = Sum(High, Period3) / Period3;
def B3 = Sum(Low, Period3) / Period3;
def A3=(T3+B3)/2;
def T4 = Sum(High, Period4) / Period4;
def B4 = Sum(Low, Period4) / Period4;
def A4=(T4+B4)/2;
def T5 = Sum(High, Period5) / Period5;
def B5 = Sum(Low, Period5) / Period5;
def A5=(T5+B5)/2;
def T6 = Sum(High, Period6) / Period6;
def B6 = Sum(Low, Period6) / Period6;
def A6=(T6+B6)/2;
def T7 = Sum(High, Period7) / Period7;
def B7 = Sum(Low, Period7) / Period7;
def A7=(T7+B7)/2;
def T8 = Sum(High, Period8) / Period8;
def B8 = Sum(Low, Period8) / Period8;
def A8=(T8+B8)/2;
def T9 = Sum(High, Period9) / Period9;
def B9 = Sum(Low, Period9) / Period9;
def A9=(T9+B9)/2;
def T10 = Sum(High, Period10) / Period10;
def B10 = Sum(Low, Period10) / Period10;
def A10=(T10+B10)/2;
def T11 = Sum(High, Period11) / Period11;
def B11 = Sum(Low, Period11) / Period11;
def A11=(T11+B11)/2;
def T12 = Sum(High, Period12) / Period12;
def B12 = Sum(Low, Period12) / Period12;
def A12=(T12+B12)/2;
plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if A1 < Close then Color.Cyan else Color.Magenta);
plot A2_Dot = if IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.AssignValueColor(if A2 < Close then Color.Cyan else Color.Magenta);
plot A3_Dot = if IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.AssignValueColor(if A3 < Close then Color.Cyan else Color.Magenta);
plot A4_Dot = if IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.AssignValueColor(if A4 < Close then Color.Cyan else Color.Magenta);
plot A5_Dot = if IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.AssignValueColor(if A5 < Close then Color.Cyan else Color.Magenta);
plot A6_Dot = if IsNaN(Close) then Double.NaN else 6;
A6_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A6_Dot.SetLineWeight(DotSize);
A6_Dot.AssignValueColor(if A6 < Close then Color.Cyan else Color.Magenta);
plot B7_Dot = if IsNaN(Close) then Double.NaN else 7;
B7_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
B7_Dot.SetLineWeight(DotSize);
B7_Dot.AssignValueColor(if A7 < Close then Color.Blue else Color.Red);
plot B8_Dot = if IsNaN(Close) then Double.NaN else 8;
B8_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
B8_Dot.SetLineWeight(DotSize);
B8_Dot.AssignValueColor(if A8 < Close then Color.Blue else Color.Red);
plot B9_Dot = if IsNaN(Close) then Double.NaN else 9;
B9_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
B9_Dot.SetLineWeight(DotSize);
B9_Dot.AssignValueColor(if A9 < Close then Color.Blue else Color.Red);
plot B10_Dot = if IsNaN(Close) then Double.NaN else 10;
B10_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
B10_Dot.SetLineWeight(DotSize);
B10_Dot.AssignValueColor(if A10 < Close then Color.Blue else Color.Red);
plot B11_Dot = if IsNaN(Close) then Double.NaN else 11;
B11_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
B11_Dot.SetLineWeight(DotSize);
B11_Dot.AssignValueColor(if A11 < Close then Color.Blue else Color.Red);
plot B12_Dot = if IsNaN(Close) then Double.NaN else 12;
B12_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
B12_Dot.SetLineWeight(DotSize);
B12_Dot.AssignValueColor(if A12 < Close then Color.Blue else Color.Red);
AssignPriceColor(if paintbars == 1 and A1 < Close then Color.Cyan else if paintbars == 1 and A1 > Close then Color.Magenta else if paintbars == 2 and A2 < Close then Color.Cyan else if paintbars == 2 and A2 > Close then Color.Magenta else if paintbars == 3 and A3 < Close then Color.Cyan else if paintbars == 3 and A3 > Close then Color.Magenta else if paintbars == 4 and A4 < Close then Color.Cyan else if paintbars == 4 and A4 > Close then Color.Magenta else
if paintbars == 5 and A5 < Close then Color.Cyan else if paintbars == 5 and A5 > Close then Color.Magenta else if paintbars == 6 and A6 < Close then Color.Cyan else if paintbars == 6 and A6 > Close then Color.Magenta else if paintbars == 7 and A7 < Close then Color.Blue else if paintbars == 7 and A7 > Close then Color.Red else if paintbars == 8 and A8 < Close then Color.Blue else if paintbars == 8 and A8 > Close then Color.Red else
if paintbars == 9 and A9 < Close then Color.Blue else if paintbars == 9 and A9 > Close then Color.Red else if paintbars == 10 and A10 < Close then Color.Blue else if paintbars == 10 and A10 > Close then Color.Red else if paintbars == 11 and A11 < Close then Color.Blue else if paintbars == 11 and A11 > Close then Color.Red else if paintbars == 12 and A12 < Close then Color.Blue else if paintbars == 12 and A12 > Close then Color.Red else color.Current);