declare lower;
input Dotsize =3;
input APC = 0;
def emac = ExpAverage(close, 3);
def emal = ExpAverage(low, 5);
def emah = ExpAverage(high, 8);
def Bemac = ExpAverage(close, 5);
def Bemal = ExpAverage(low, 8);
def Bemah = ExpAverage(high, 13);
def Cemac = ExpAverage(close, 8);
def Cemal = ExpAverage(low, 13);
def Cemah = ExpAverage(high, 21);
def Demac = ExpAverage(close, 13);
def Demal = ExpAverage(low, 21);
def Demah = ExpAverage(high, 34);
def Eemac = ExpAverage(close, 21);
def Eemal = ExpAverage(low, 34);
def Eemah = ExpAverage(high, 55);
def Femac = ExpAverage(close, 34);
def Femal = ExpAverage(low, 55);
def Femah = ExpAverage(high, 89);
def ch = emac - emah;
def lc = emal - emac;
def Bch = Bemac - Bemah;
def Blc = Bemal - Bemac;
def Cch = Cemac - Cemah;
def Clc = Cemal - Cemac;
def Dch = Demac - Demah;
def Dlc = Demal - Demac;
def Ech = Eemac - Eemah;
def Elc = Eemal - Eemac;
def Fch = Femac - Femah;
def Flc = Femal - Femac;
def osc = CH - LC;
def Bosc = BCH - BLC;
def Cosc = CCH - CLC;
def Dosc = DCH - DLC;
def Eosc = ECH - ELC;
def Fosc = FCH - FLC;
Def Con1 = osc >= 0;
Def Con2 = osc < 0;
Def Con3 = osc > osc [1];
Def Con4 = osc < osc[1];
Def BCon1 = Bosc >= 0;
Def BCon2 = Bosc < 0;
Def BCon3 = Bosc > Bosc [1];
Def BCon4 = Bosc < Bosc[1];
Def CCon1 = Cosc >= 0;
Def CCon2 = Cosc < 0;
Def CCon3 = Cosc > Cosc [1];
Def CCon4 = Cosc < Cosc[1];
Def DCon1 = Dosc >= 0;
Def DCon2 = Dosc < 0;
Def DCon3 = Dosc > Dosc [1];
Def DCon4 = Dosc < Dosc[1];
Def ECon1 = Eosc >= 0;
Def ECon2 = Eosc < 0;
Def ECon3 = Eosc > Eosc [1];
Def ECon4 = Eosc < Eosc[1];
Def FCon1 = Fosc >= 0;
Def FCon2 = Fosc < 0;
Def FCon3 = Fosc > Fosc [1];
Def FCon4 = Fosc < Fosc[1];
Def BullRise = If Con1 and Con3 then 1 else 0;
Def BullFall = if Con1 and Con4 then 1 else 0;
Def BearFall = if Con2 and Con4 then 1 else 0;
Def BearRise = if Con2 and Con3 then 1 else 0;
Def BBullRise = If BCon1 and BCon3 then 1 else 0;
Def BBullFall = if BCon1 and BCon4 then 1 else 0;
Def BBearFall = if BCon2 and BCon4 then 1 else 0;
Def BBearRise = if BCon2 and BCon3 then 1 else 0;
Def CBullRise = If CCon1 and CCon3 then 1 else 0;
Def CBullFall = if CCon1 and CCon4 then 1 else 0;
Def CBearFall = if CCon2 and CCon4 then 1 else 0;
Def CBearRise = if CCon2 and CCon3 then 1 else 0;
Def DBullRise = If DCon1 and DCon3 then 1 else 0;
Def DBullFall = if DCon1 and DCon4 then 1 else 0;
Def DBearFall = if DCon2 and DCon4 then 1 else 0;
Def DBearRise = if DCon2 and DCon3 then 1 else 0;
Def EBullRise = If ECon1 and ECon3 then 1 else 0;
Def EBullFall = if ECon1 and ECon4 then 1 else 0;
Def EBearFall = if ECon2 and ECon4 then 1 else 0;
Def EBearRise = if ECon2 and ECon3 then 1 else 0;
Def FBullRise = If FCon1 and FCon3 then 1 else 0;
Def FBullFall = if FCon1 and FCon4 then 1 else 0;
Def FBearFall = if FCon2 and FCon4 then 1 else 0;
Def FBearRise = if FCon2 and FCon3 then 1 else 0;
plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if BULLRISE ==1 then Color.GREEN else if BULLFALL ==1 then Color.Dark_GREEN else if BearRISE ==1 then Color.red else if Bearfall ==1 then Color.Dark_Red else Color.Gray);
plot A2_Dot = if IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.AssignValueColor(if BBULLRISE ==1 then Color.GREEN else if BBULLFALL ==1 then Color.Dark_GREEN else if BBearRISE ==1 then Color.red else if BBearfall ==1 then Color.Dark_Red else Color.Gray);
plot A3_Dot = if IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.AssignValueColor(if CBULLRISE ==1 then Color.GREEN else if CBULLFALL ==1 then Color.Dark_GREEN else if CBearRISE ==1 then Color.red else if CBearfall ==1 then Color.Dark_Red else Color.Gray);
plot A4_Dot = if IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.AssignValueColor(if DBULLRISE ==1 then Color.GREEN else if DBULLFALL ==1 then Color.Dark_GREEN else if DBearRISE ==1 then Color.red else if DBearfall ==1 then Color.Dark_Red else Color.Gray);
plot A5_Dot = if IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.AssignValueColor(if EBULLRISE ==1 then Color.GREEN else if EBULLFALL ==1 then Color.Dark_GREEN else if EBearRISE ==1 then Color.red else if EBearfall ==1 then Color.Dark_Red else Color.Gray);
plot A6_Dot = if IsNaN(Close) then Double.NaN else 6;
A6_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A6_Dot.SetLineWeight(DotSize);
A6_Dot.AssignValueColor(if FBULLRISE ==1 then Color.GREEN else if FBULLFALL ==1 then Color.Dark_GREEN else if FBearRISE ==1 then Color.red else if FBearfall ==1 then Color.Dark_Red else Color.Gray);
AssignPriceColor(if APC ==1 and BULLRISE ==1 then Color.GREEN else if APC ==1 and BULLFALL ==1 then Color.Dark_GREEN else if APC ==1 and BearRISE ==1 then Color.red else if APC ==1 and Bearfall ==1 then Color.Dark_Red else if APC ==2 and BBULLRISE ==1 then Color.GREEN else if APC ==2 and BBULLFALL ==1 then Color.Dark_GREEN else if APC ==2 and BBearRISE ==1 then Color.red else if APC ==2 and BBearfall ==1 then Color.Dark_Red else if APC ==3 and CBULLRISE ==1 then Color.GREEN else if APC ==3 and CBULLFALL ==1 then Color.Dark_GREEN else if APC ==3 and CBearRISE ==1 then Color.red else if APC ==3 and CBearfall ==1 then Color.Dark_Red else if APC ==4 and DBULLRISE ==1 then Color.GREEN else if APC ==4 and DBULLFALL ==1 then Color.Dark_GREEN else if APC ==4 and DBearRISE ==1 then Color.red else if APC ==4 and DBearfall ==1 then Color.Dark_Red else if APC ==5 and EBULLRISE ==1 then Color.GREEN else if APC ==5 and EBULLFALL ==1 then Color.Dark_GREEN else if APC ==5 and EBearRISE ==1 then Color.red else if APC ==5 and EBearfall ==1 then Color.Dark_Red else if APC ==6 and FBULLRISE ==1 then Color.GREEN else if APC ==6 and FBULLFALL ==1 then Color.Dark_GREEN else if APC ==6 and FBearRISE ==1 then Color.red else if APC ==6 and FBearfall ==1 then Color.Dark_Red else Color.Current);