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 internal 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 by a moderator:

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
381 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