```
#Swing High/Low (Fractal)
#Higher Highs or Higher Lows are designated by green dots and/or green horizontal lines
#Lower Highs or Lower Lows are designated by red dots and/or red horizontal lines
#User input to select how many horizontal lines are plotted
#User input to plot lines connecting swing highs to each other and swing lows to each other
#User input to plot lines connecting swing highs to swing lows
input swing = 1;
input spacer = 0;
def swinghigh = if Round(Highest(high[1], swing), 2) < Round(high, 2) and
Round(high, 2) > Round(Highest(high[-swing], swing), 2) and
Round(Lowest(low[1], swing), 2) < Round(Lowest(low[-swing], swing), 2)
then 1
else 0;
def fast = if swinghigh == 1 then high else fast[1];
plot sh1 = if swinghigh == 1 then high + spacer * TickSize() else Double.NaN;
sh1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sh1.AssignValueColor(if fast[1] < fast
then Color.GREEN
else if fast[1] == fast
then Color.YELLOW
else Color.RED);
sh1.SetLineWeight(4);
sh1.HideBubble();
def swinglow = if Round(low, 2) < Round(Lowest(low[1], swing), 2) and
Round(low) < Round(Lowest(low[-swing], swing), 2) and
Round(Highest(high[1], swing), 2) > Round(Highest(high[-swing], swing), 2)
then 1
else 0;
def slow = if swinglow == 1 then low else slow[1];
plot sl1 = if swinglow == 1 then low - spacer * TickSize() else Double.NaN;
sl1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
sl1.AssignValueColor(if slow[1] < slow
then Color.GREEN
else if slow[1] == slow
then Color.YELLOW
else Color.RED);
sl1.SetLineWeight(4);
sl1.HideBubble();
def sh11 = if !IsNaN(sh1) then high else Double.NaN;
def sl11 = if !IsNaN(sl1) then low else Double.NaN;
def swhigh = if !IsNaN(sh1) then sh1 else swhigh[1];
def swlow = if !IsNaN(sl1) then sl1 else swlow[1];
def shcolor = if swhigh != swhigh[1] and swhigh > swhigh[1]
then 1
else if shcolor[1] == 1 and swhigh == swhigh[1]
then 1
else 0;
def slcolor = if swlow != swlow[1] and swlow > swlow[1]
then 1
else if slcolor[1] == 1 and swlow == swlow[1]
then 1
else 0;
#Swing Line from High to Low
input showswinghightolowline = yes;
plot hilowline = if showswinghightolowline == no then Double.NaN else if swinghigh then sh11 else sl11;
hilowline.EnableApproximation();
hilowline.SetDefaultColor(Color.BLACK);
hilowline.HideBubble();
#Price Bubbles @Swing
input showbubbles = yes;
AddChartBubble(showbubbles and sh1, high, high, if shcolor == 1 then Color.LIGHT_GREEN else Color.LIGHT_RED, yes);
AddChartBubble(showbubbles and sl1, low, low, if slcolor == 1 then Color.LIGHT_GREEN else Color.LIGHT_RED, no);
#Horizontal Lines
input number_swing_horizontalsstoshow = 2;
input show_horizontallines = yes;
def data = CompoundValue(1, if !IsNaN(sh1) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]) + 1;
def data1 = CompoundValue(1, if !IsNaN(sl1) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]) + 1;
plot swingHp = if show_horizontallines == no
then Double.NaN
else if datacount <= number_swing_horizontalsstoshow
then swhigh
else Double.NaN;
swingHp.SetPaintingStrategy(PaintingStrategy.DASHES);
swingHp.setlineWeight(2);
swingHp.AssignValueColor(if shcolor == 1 then Color.GREEN else Color.RED);
swingHp.HideBubble();
plot swingLp = if show_horizontallines == no
then Double.NaN
else if datacount1 <= number_swing_horizontalsstoshow
then swlow
else Double.NaN;
swingLp.SetPaintingStrategy(PaintingStrategy.DASHES);
swingLp.AssignValueColor(if slcolor == 1 then Color.GREEN else Color.RED);
swinglp.setlineWeight(2);
swingLp.HideBubble();
```