```
declare Lower;
input Show5813Label = yes;
input Show81321Label = yes;
input Show132134Label = yes;
input ShowWaveTrendLabel = yes;
input Dotsize = 3;
input APC = 0;
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Sideways", Color.YELLOW);
DefineGlobalColor("Bearish", Color.RED);
def EMA34High = ExpAverage (high, 34); #was ema1_34
def EMA34Close = ExpAverage (close, 34); #ema2_34
def EMA34Low = ExpAverage (low, 34); # was ema3_34
def EMA5 = ExpAverage(Close,5);
def EMA8 = ExpAverage(close, 8); #JT Changed var name from EMA1 to EMA8
def EMA21 = ExpAverage(close, 21); #JT Changed var name from EMA2 to EMA21
def EMA13 = ExpAverage (close, 13);
def EMA34 = ExpAverage (Close, 34);
def bullish = (EMA5 > EMA8) and (EMA8 > EMA13);
def bearish = (EMA5 < EMA8) and (EMA8 < EMA13);
def bullish2 = (EMA8 > EMA13) and (EMA13 > EMA21);
def bearish2 = (EMA8 < EMA13) and (EMA13 < EMA21);
def bullish3 = (EMA13 > EMA21) and (EMA21 > EMA34);
def bearish3 = (EMA13 < EMA21) and (EMA21 < EMA34);
def WaveState = {default SW, Bullish, Bearish}; #SW = sideways
WaveState = IF (EMA5 > EMA8) AND (EMA8 > EMA13) AND (EMA13 > EMA34High)
THEN WaveState.Bullish
ELSE IF (EMA5 < EMA8) AND (EMA8 < EMA13) AND (EMA13 < EMA34Low)
THEN WaveState.Bearish
ELSE WaveState.SW;
def WaveState2 = {default SW, Bullish, Bearish}; #SW = sideways
WaveState2 = IF (EMA8 > EMA13) AND (EMA13 > EMA21) AND (EMA21 > EMA34High)
THEN WaveState2.Bullish
ELSE IF (EMA8 < EMA13) AND (EMA13 < EMA21) AND (EMA21 < EMA34Low)
THEN WaveState2.Bearish
ELSE WaveState2.SW;
def IsBullishWave = WaveState == WaveState.Bullish;
def IsBearishWave = WaveState == WaveState.Bearish;
def IsSidewaysWave = WaveState == WaveState.SW;
def IsBullishWave2 = WaveState2 == WaveState2.Bullish;
def IsBearishWave2 = WaveState2 == WaveState2.Bearish;
def IsSidewaysWave2 = WaveState2 == WaveState2.SW;
plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if bullish then Color.Green else if Bearish then Color.Red else Color.Yellow);
plot A2_Dot = if IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.AssignValueColor(if bullish2 then Color.Green else if Bearish2 then Color.Red else Color.Yellow);
plot A3_Dot = if IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.AssignValueColor(if bullish3 then Color.Green else if Bearish3 then Color.Red else Color.Yellow);
plot A4_Dot = if IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.AssignValueColor(if IsBullishWave then Color.Green else if IsBearishWave then Color.Red else if isSidewaysWave then Color.Yellow else Color.Black);
plot A5_Dot = if IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.AssignValueColor(if IsBullishWave2 then Color.Green else if IsBearishWave2 then Color.Red else if isSidewaysWave2 then Color.Yellow else Color.Black);
AddLabel(Show5813Label, "Line1:5:8:13: " + if bullish then "Bullish" else if bearish then "Bearish" else "Slop", if bullish then GlobalColor("Bullish") else if bearish then GlobalColor("Bearish") else GlobalColor("Sideways"));
AddLabel(Show81321Label, "Line2:8:13:21: " + if bullish2 then "Bullish" else if bearish2 then "Bearish" else "Slop", if bullish2 then GlobalColor("Bullish") else if bearish2 then GlobalColor("Bearish") else GlobalColor("Sideways"));
AddLabel(Show132134Label, "Line3:13:21:34 " + if bullish3 then "Bullish" else if bearish3 then "Bearish" else "Slop", if bullish3 then GlobalColor("Bullish") else if bearish3 then GlobalColor("Bearish") else GlobalColor("Sideways"));
AddLabel(ShowWaveTrendLabel, "Line4:Wave1: " + if IsBullishWave then "Bullish" else if IsBearishWave then "Bearish" else "S/W", if IsBullishWave then GlobalColor("Bullish") else if IsBearishWave then GlobalColor("Bearish") else GlobalColor("Sideways"));
AddLabel(ShowWaveTrendLabel, "Line5:Wave2: " + if IsBullishWave2 then "Bullish" else if IsBearishWave2 then "Bearish" else "S/W", if IsBullishWave2 then GlobalColor("Bullish") else if IsBearishWave2 then GlobalColor("Bearish") else GlobalColor("Sideways"));
AssignPriceColor(if APC == 1 and Bullish then Color.Green else if APC ==1 and bearish then Color.Red else if APC ==1 and !bullish and ! Bearish then Color.yellow else if APC == 2 and Bullish2 then Color.Green else if APC ==2 and bearish2 then Color.Red else if APC ==2 and !bullish2 and ! Bearish2 then Color.yellow else if APC == 3 and Bullish3 then Color.Green else if APC ==3 and bearish3 then Color.Red else if APC ==3 and !bullish3 and ! Bearish3 then Color.yellow else if APC ==4 and IsBullishWave then Color.Green else if APC == 4 and IsBearishWave then Color.Red else if APC ==4 and isSidewaysWave then Color.Yellow else if APC ==5 and IsBullishWave2 then Color.Green else if APC == 5 and IsBearishWave2 then Color.Red else if APC ==5 and isSidewaysWave2 then Color.Yellow else Color.Current);
```