Updated Script It's a fractal high/low script. All I need addressed is, I only want to see the external high/low lines. I don't want them connecting to the internal structure. Dots can stay. I just want the internal lines gone.
Code:
# =======================
# Fractal detection
# =======================
def isupfractal;
def isdownfractal;
rec hicount = if (high == high[1], hicount[1] + 1, 0);
rec hivalid = if (
(hicount[1] == 0 and hicount == 1 and high > high[2] and high > high[3]) or
(hicount[1] and hicount and hivalid[1]) or
(hicount[2] and hivalid[2] and high == high[2] and high > high[1]),
1, 0
);
rec locount = if (low == low[1], locount[1] + 1, 0);
rec lovalid = if (
(locount[1] == 0 and locount == 1 and low < low[2] and low < low[3]) or
(locount[1] and locount and lovalid[1]) or
(locount[2] and lovalid[2] and low == low[2] and low < low[1]),
1, 0
);
isupfractal =
if (
((hicount and hivalid) or (high > high[1] and high > high[2])) and
high > high[-1] and high > high[-2]
) then high else Double.NaN;
isdownfractal =
if (
((locount and lovalid) or (low < low[1] and low < low[2])) and
low < low[-1] and low < low[-2]
) then low else Double.NaN;
def bn = BarNumber();
# =======================
# Track two most recent fractals
# =======================
# Up fractals
rec up1 = if !IsNaN(isupfractal) then isupfractal else up1[1];
rec up1Bar = if !IsNaN(isupfractal) then bn else up1Bar[1];
rec up1Broken = if !IsNaN(isupfractal) then 0 else if high > up1 then 1 else up1Broken[1];
rec up2 = if !IsNaN(isupfractal[1]) and up1Bar[1] != up1Bar then isupfractal[1] else up2[1];
rec up2Bar = if !IsNaN(isupfractal[1]) and up1Bar[1] != up1Bar then bn - 1 else up2Bar[1];
rec up2Broken = if !IsNaN(isupfractal[1]) and up1Bar[1] != up1Bar then 0 else if high > up2 then 1 else up2Broken[1];
# Down fractals
rec down1 = if !IsNaN(isdownfractal) then isdownfractal else down1[1];
rec down1Bar = if !IsNaN(isdownfractal) then bn else down1Bar[1];
rec down1Broken = if !IsNaN(isdownfractal) then 0 else if low < down1 then 1 else down1Broken[1];
rec down2 = if !IsNaN(isdownfractal[1]) and down1Bar[1] != down1Bar then isdownfractal[1] else down2[1];
rec down2Bar = if !IsNaN(isdownfractal[1]) and down1Bar[1] != down1Bar then bn - 1 else down2Bar[1];
rec down2Broken = if !IsNaN(isdownfractal[1]) and down1Bar[1] != down1Bar then 0 else if low < down2 then 1 else down2Broken[1];
# =======================
# Structure lines
# =======================
plot recentUp1 = if bn >= up1Bar and up1Broken == 0 then up1 else Double.NaN;
recentUp1.SetDefaultColor(Color.GREEN);
recentUp1.SetStyle(Curve.FIRM);
recentUp1.SetLineWeight(1);
recentUp1.HideBubble();
plot recentUp2 = if bn >= up2Bar and up2Broken == 0 then up2 else Double.NaN;
recentUp2.SetDefaultColor(Color.GREEN);
recentUp2.SetStyle(Curve.FIRM);
recentUp2.SetLineWeight(1);
recentUp2.HideBubble();
plot recentDown1 = if bn >= down1Bar and down1Broken == 0 then down1 else Double.NaN;
recentDown1.SetDefaultColor(Color.RED);
recentDown1.SetStyle(Curve.FIRM);
recentDown1.SetLineWeight(1);
recentDown1.HideBubble();
plot recentDown2 = if bn >= down2Bar and down2Broken == 0 then down2 else Double.NaN;
recentDown2.SetDefaultColor(Color.RED);
recentDown2.SetStyle(Curve.FIRM);
recentDown2.SetLineWeight(1);
recentDown2.HideBubble();
# =======================
# Dots for fractal points
# =======================
plot dotUp = if bn == up1Bar or bn == up2Bar then high + TickSize() else Double.NaN;
dotUp.SetPaintingStrategy(PaintingStrategy.POINTS);
dotUp.SetDefaultColor(Color.GREEN);
plot dotDown = if bn == down1Bar or bn == down2Bar then low - TickSize() else Double.NaN;
dotDown.SetPaintingStrategy(PaintingStrategy.POINTS);
dotDown.SetDefaultColor(Color.RED);
Last edited: