Perfect SuperTrend For ThinkOrSwim

cando13579

Active member
VIP
Here is a companion for that one or stand alone.
Perfect Supertrend Line


The Perfect SuperTrend Line is an adaptive dual-line trend model designed to identify directional bias with high clarity and minimal noise.

It uses two dynamically adjusting levels:
• A Slow Line – establishes the primary trend by tracking recent structural highs/lows.
• A Fast Line – provides early momentum detection and helps confirm or weaken the current trend state.

A trend shift occurs only when price closes on the same side of both lines, helping reduce false reversals. Cyan indicates bullish conditions, while magenta/red indicates bearish conditions.
Up/down arrows appear at the slow line level when a confirmed trend reversal is detected.
perfectsupertrend.png



How to Use:
• Trade only in the direction of the active trend color.
• Look for pullbacks toward the Fast Line after a new arrow for higher-probability entries.
• Conservative exits: opposite arrow.
• Aggressive exits: price closes against the Fast Line.

Recommended Timeframes:
• Best for 5m–15m intraday charts and 30m–1H swing trades.
• Higher timeframes (4H–Daily) provide the cleanest structural trends with fewer whipsaws.
• Lower timeframes (1–2m) work but may generate noise.

Ideal For:
• Trend-following entries
• Pullback trading
• Swing confirmation
• Filtering low-quality trades

Code:
# Perfect Supertrend Line V1
# By CANDO13579

declare upper;

input fastLength = 3;
input slowLength = 7;

def na = Double.NaN;

# Slow line calculation
def slow_line;
if (IsNaN(slow_line[1])) {
slow_line = close;
} else {
if (close > slow_line[1]) {
slow_line = Lowest(low, slowLength);
} else {
slow_line = Highest(high, slowLength);
}
}

# Fast line calculation
def fast_line;
if (IsNaN(fast_line[1])) {
fast_line = close;
} else {
if (close > fast_line[1]) {
fast_line = Lowest(low, fastLength);
} else {
fast_line = Highest(high, fastLength);
}
}

# Trend calculation
def trend;
if (IsNaN(trend[1])) {
trend = 0;
} else {
if (close < slow_line and close < fast_line) {
trend = 1;
} else if (close > slow_line and close > fast_line) {
trend = 0;
} else {
trend = trend[1];
}
}

# Arrow positions
def arrow_pos = if trend != trend[1] then slow_line else na;

# Slow line conditions
plot SlowUpLine = if trend == 0 then slow_line else na;
SlowUpLine.SetDefaultColor(Color.CYAN);
SlowUpLine.SetLineWeight(2);
SlowUpLine.SetStyle(Curve.FIRM);

plot SlowDownLine = if trend == 1 then slow_line else na;
SlowDownLine.SetDefaultColor(Color.MAGENTA);
SlowDownLine.SetLineWeight(2);
SlowDownLine.SetStyle(Curve.FIRM);

# Fast line with conditional coloring
plot FastLine = fast_line;
FastLine.AssignValueColor(if trend == 0 then Color.CYAN else Color.RED);
FastLine.SetLineWeight(1);
FastLine.SetStyle(Curve.POINTS);

# Arrow shapes
plot UpArrow = if trend == 0 and !IsNaN(arrow_pos) then arrow_pos else na;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetDefaultColor(Color.CYAN);

plot DownArrow = if trend == 1 and !IsNaN(arrow_pos) then arrow_pos else na;
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownArrow.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
547 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