Remove Part of the Line Plots From fractal high/low script

johnwood34

Member
VIP
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.

Screenshot 2025-08-14 194134.png


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:
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 internal the internal structure. Dots can stay. I just want the internal lines gone.

View attachment 25462

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);

internal and external have no meaning. come up with new words to describe what you want.
look at the chart and describe when to start drawing a new line


that code seems overly complicated
this draws arrows on peaks and valleys
Code:
def na = double.nan;
input len = 2;
def fup = WilliamsFractal(len).UpFractal;
def fdwn = WilliamsFractal(len).downFractal;

def vert = 0.002;
plot zu = if fdwn then low*(1-vert) else na;
zu.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#x.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zu.SetDefaultColor(Color.cyan);
zu.setlineweight(3);
zu.hidebubble();

plot zd = if fup then high*(1+vert) else na;
zd.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zd.SetDefaultColor(Color.cyan);
zd.setlineweight(3);
zd.hidebubble();

-------------------------

this draws a line, starting from a peak, when the high is > prev high
similar for valleys , when low is < prev low


Code:
#fractal_lines_fix_02
def na = double.nan;
def bn = barnumber();

input len = 2;
def fup = WilliamsFractal(len).UpFractal;
def fdwn = WilliamsFractal(len).downFractal;

def vert = 0.002;

#plot zd = if fup then high*(1+vert) else na;
plot zd = fup;
#zd.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zd.SetPaintingStrategy(PaintingStrategy.boolean_wedge_up);
zd.SetDefaultColor(Color.cyan);
zd.setlineweight(1);
zd.hidebubble();

#plot zu = if fdwn then low*(1-vert) else na;
plot zu = fdwn;
#zu.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zu.SetPaintingStrategy(PaintingStrategy.boolean_wedge_down);
zu.SetDefaultColor(Color.cyan);
zu.setlineweight(1);
zu.hidebubble();


def hiline = if bn == 1 then 0
 else if isnan(fup) then hiline[1]
 else if fup and high > hiline[1] then high
 else hiline[1];

def loline = if bn == 1 then 0
 else if isnan(fdwn) then loline[1]
 else if fdwn and loline[1] == 0 then low
 else if fdwn and low < loline[1] then low
 else loline[1];

plot z1 = if hiline > 0 then hiline else na;
plot z2 = if loline > 0 then loline else na;
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


addchartbubble(0, low,
fup + "\n" +
fdwn + "\n" +
hiline + "\n" +
loline + "\n" 
, color.yellow, no);
#
 
Last edited:
internal and external have no meaning. come up with new words to describe what you want.
look at the chart and describe when to start drawing a new line
internal and external have no meaning. come up with new words to describe what you want.
look at the chart and describe when to start drawing a new line
internal and external have no meaning. come up with new words to describe what you want.
look at the chart and describe when to start drawing a new line
The lines I drew on the screenshot that state "KEEP" are the only lines I would like to see plotting. These are my major fractal swing highs/lows. The script is tracking "ALL" fractal highs/lows. So, it's anchoring the "INTERNAL" fractal high/lows to the "EXTERNAL (MAJOR)" fractal highs/lows, as seen in the screenshot I provided. The squiggly lines represent the anchoring part of the script I would like to see removed, if at all possible. If I need to clarify further, PLEASE DO touch base with me. Thank for your response...
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
281 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top